From cbd055d05422ef128096187d6c18e68e55fa4232 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 15 Jan 2016 15:19:41 +0300 Subject: [PATCH] gl scene fixes --- src/dlangui/graphics/gldrawbuf.d | 18 ++++++++++++++---- src/dlangui/graphics/scene/mesh.d | 30 ++++++++++++++++++------------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 32fc7146..36bd70d5 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -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; diff --git a/src/dlangui/graphics/scene/mesh.d b/src/dlangui/graphics/scene/mesh.d index bebeabe3..f0507272 100644 --- a/src/dlangui/graphics/scene/mesh.d +++ b/src/dlangui/graphics/scene/mesh.d @@ -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; + } }