gl scene fixes

This commit is contained in:
Vadim Lopatin 2016-01-15 15:19:41 +03:00
parent 6bcd2c0487
commit cbd055d054
2 changed files with 32 additions and 16 deletions

View File

@ -256,6 +256,16 @@ private int nearestPOT(int n) {
return MIN_TEX_SIZE;
}
private int correctTextureSize(int n) {
if (n < 16)
return 16;
version(POT_TEXTURE_SIZES) {
return nearestPOT(n);
} else {
return n;
}
}
/// object deletion listener callback function type
void onObjectDestroyedCallback(uint pobject) {
glImageCache.onCachedObjectDeleted(pobject);
@ -307,8 +317,8 @@ private abstract class GLCache
public:
this(GLCache cache, int dx, int dy) {
_cache = cache;
_tdx = nearestPOT(dx);
_tdy = nearestPOT(dy);
_tdx = correctTextureSize(dx);
_tdy = correctTextureSize(dy);
_itemCount = 0;
}
@ -816,8 +826,8 @@ static class GLTexture {
if (buf) {
_dx = buf.width;
_dy = buf.height;
_tdx = nearestPOT(_dx);
_tdy = nearestPOT(_dy);
_tdx = correctTextureSize(_dx);
_tdy = correctTextureSize(_dy);
_texture = new Tex2D();
if (!_texture.ID) {
_texture = null;

View File

@ -50,24 +50,18 @@ class Submesh {
arrayElement(_txcoords, index, 2, 0)[0..2] = v.vec[0..2];
}
/// add vertex data, returns index of added vertex
void setVertex(int index, vec3 coord, vec3 normal, vec4 color, vec2 txcoord) {
/// sets vertex data for specified vertex index, returns index of added vertex; pass index -1 to append vertex to end of list
int setVertex(int index, vec3 coord, vec3 normal, vec4 color, vec2 txcoord) {
if (index < 0)
index = _vertexCount;
setVertexCoord(index, coord);
setVertexNormal(index, normal);
setVertexColor(index, color);
setVertexTxCoord(index, txcoord);
return index;
}
/// add vertex data, returns index of added vertex
int addVertex(vec3 coord, vec3 normal, vec4 color, vec2 txcoord) {
_coords ~= coord.vec;
_normals ~= normal.vec;
_colors ~= color.vec;
_txcoords ~= txcoord.vec;
_vertexCount++;
return _vertexCount - 1;
}
/// adds indexes for triangle
int addTriangleIndexes(int p1, int p2, int p3) {
_indexes ~= p1;
_indexes ~= p2;
@ -76,4 +70,16 @@ class Submesh {
return _triangleCount - 1;
}
/// adds indexes for 2 triangles forming rectangle
int addRectangleIndexes(int p1, int p2, int p3, int p4) {
_indexes ~= p1;
_indexes ~= p2;
_indexes ~= p3;
_indexes ~= p3;
_indexes ~= p4;
_indexes ~= p1;
_triangleCount++;
_triangleCount++;
return _triangleCount - 1;
}
}