浏览代码

removing indices8

dmuratshin 9 年之前
父节点
当前提交
809db0eea6

+ 1 - 5
examples/Demo/src/TestUserShader2.h

@@ -80,11 +80,7 @@ public:
         size_t indices = (count * 3) / 2;
 
         driver->setTexture(0, _base);
-
-        if (indices <= STDRenderer::indices8.size())
-            driver->draw(IVideoDriver::PT_TRIANGLES, _vdecl, &_vertices.front(), (unsigned int)count, &STDRenderer::indices8.front(), (unsigned int)indices, false);
-        else
-            driver->draw(IVideoDriver::PT_TRIANGLES, _vdecl, &_vertices.front(), (unsigned int)count, &STDRenderer::indices16.front(), (unsigned int)indices, true);
+        driver->draw(IVideoDriver::PT_TRIANGLES, _vdecl, &_vertices.front(), (unsigned int)count, &STDRenderer::indices16.front(), (unsigned int)indices);
 
         _vertices.clear();
     }

+ 3 - 21
oxygine/src/STDRenderer.cpp

@@ -29,7 +29,6 @@ namespace oxygine
     spNativeTexture STDRenderer::white;
     spNativeTexture STDRenderer::invisible;
 
-    std::vector<unsigned char> STDRenderer::indices8;
     std::vector<unsigned short> STDRenderer::indices16;
     size_t STDRenderer::maxVertices = 0;
     UberShaderProgram STDRenderer::uberShader;
@@ -97,21 +96,8 @@ namespace oxygine
 
     void STDRenderer::initialize()
     {
-        indices8.reserve(60 * 4);
-        for (int t = 0; t < 60; t += 1)
-        {
-            int i = t * 4;
-            indices8.push_back(i + 0);
-            indices8.push_back(i + 1);
-            indices8.push_back(i + 2);
-
-            indices8.push_back(i + 2);
-            indices8.push_back(i + 1);
-            indices8.push_back(i + 3);
-        }
-
-        indices16.reserve(12000 * 6);
-        for (int t = 0; t < 12000; t += 1)
+        indices16.reserve(3000 * 6);
+        for (int t = 0; t < 3000; t += 1)
         {
             int i = t * 4;
             indices16.push_back(i + 0);
@@ -143,7 +129,6 @@ namespace oxygine
 
     void STDRenderer::release()
     {
-        indices8.clear();
         indices16.clear();
         uberShader.release();
         uberShaderBody.clear();
@@ -231,10 +216,7 @@ namespace oxygine
         size_t count = _vertices.size() / _vdecl->size;
         size_t indices = (count * 3) / 2;
 
-        if (indices <= indices8.size())
-            getDriver()->draw(IVideoDriver::PT_TRIANGLES, _vdecl, &_vertices.front(), (unsigned int)count, &indices8.front(), (unsigned int)indices, false);
-        else
-            getDriver()->draw(IVideoDriver::PT_TRIANGLES, _vdecl, &_vertices.front(), (unsigned int)count, &indices16.front(), (unsigned int)indices, true);
+        getDriver()->draw(IVideoDriver::PT_TRIANGLES, _vdecl, &_vertices.front(), (unsigned int)count, &indices16.front(), (unsigned int)indices);
 
         _vertices.clear();
     }

+ 0 - 2
oxygine/src/STDRenderer.h

@@ -30,8 +30,6 @@ namespace oxygine
 
         static UberShaderProgram uberShader;
         static std::vector<unsigned char> uberShaderBody;
-
-        static std::vector<unsigned char> indices8;
         static std::vector<unsigned short> indices16;
         static size_t maxVertices;
 

+ 2 - 2
oxygine/src/core/VideoDriver.h

@@ -69,7 +69,7 @@ namespace oxygine
         virtual void clear(const Color& color) = 0;
         virtual void begin(const Rect& viewport, const Color* color) = 0;
         virtual void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize) = 0;
-        virtual void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const void* indicesData, unsigned int numIndices, bool indicesShortType) = 0;
+        virtual void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const unsigned short* indicesData, unsigned int numIndices) = 0;
 
         virtual void            getStats(Stats& s) const = 0;
         virtual void            getViewport(Rect& r) const = 0;
@@ -117,7 +117,7 @@ namespace oxygine
         const VertexDeclaration*    getVertexDeclaration(bvertex_format) const;
 
         void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize) {}
-        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const void* indicesData, unsigned int indicesDataSize, bool indicesShortType) {}
+        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const unsigned short* indicesData, unsigned int indicesDataSize) {}
 
 
         void setUniformInt(const char* id, int v) {}

+ 2 - 2
oxygine/src/core/gl/VideoDriverGLES20.cpp

@@ -133,7 +133,7 @@ namespace oxygine
         CHECKGL();
     }
 
-    void VideoDriverGLES20::draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl_, const void* vdata, unsigned int verticesDataSize, const void* indicesData, unsigned int numIndices, bool indicesShortType)
+    void VideoDriverGLES20::draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl_, const void* vdata, unsigned int verticesDataSize, const unsigned short* indicesData, unsigned int numIndices)
     {
         const VertexDeclarationGL* decl = static_cast<const VertexDeclarationGL*>(decl_);
 
@@ -147,7 +147,7 @@ namespace oxygine
             el++;
         }
 
-        glDrawElements(getPT(pt), numIndices, indicesShortType ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, indicesData);
+        glDrawElements(getPT(pt), numIndices, GL_UNSIGNED_SHORT, indicesData);
 
         el = decl->elements;
         for (int i = 0; i < decl->numElements; ++i)

+ 1 - 1
oxygine/src/core/gl/VideoDriverGLES20.h

@@ -26,7 +26,7 @@ namespace oxygine
         ShaderProgram*  getShaderProgram() const OVERRIDE { return _p; }
 
         void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize);
-        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const void* indicesData, unsigned int indicesDataSize, bool indicesShortType);
+        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData, unsigned int verticesDataSize, const unsigned short* indicesData, unsigned int numIndices);
         void setDefaultSettings();
 
         void setViewport(const Rect& viewport);

+ 5 - 6
oxygine/src/dev_tools/TreeInspectorPreview.h

@@ -22,7 +22,7 @@ namespace oxygine
     public:
         struct cached_batch
         {
-            cached_batch(): program(0), vdecl(0), indicesShortType(false), numVertices(0), numIndices(0), blendSrc(IVideoDriver::BT_ONE), blendDest(IVideoDriver::BT_ONE)
+            cached_batch(): program(0), vdecl(0), numVertices(0), numIndices(0), blendSrc(IVideoDriver::BT_ONE), blendDest(IVideoDriver::BT_ONE)
             {
                 memset(states, 0, sizeof(states));
             }
@@ -34,12 +34,11 @@ namespace oxygine
             const VertexDeclaration* vdecl;
             PRIMITIVE_TYPE pt;
             std::vector<char> vertices;
-            std::vector<char> indices;
+            std::vector<unsigned short> indices;
             int numVertices;
             int numIndices;
             unsigned int states[STATE_NUM];
             BLEND_TYPE blendSrc, blendDest;
-            bool indicesShortType;
         };
 
         typedef std::vector<cached_batch> batches;
@@ -111,14 +110,14 @@ namespace oxygine
 
         }
 
-        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData,  unsigned int numVertices, const void* indicesData, unsigned int numIndices, bool indicesShortType)
+        void draw(PRIMITIVE_TYPE pt, const VertexDeclaration* decl, const void* verticesData,  unsigned int numVertices, const unsigned short* indicesData, unsigned int numIndices)
         {
             current().vdecl = decl;
             current().pt = pt;
             current().numVertices = numVertices;
             current().numIndices = numIndices;
             current().vertices.assign((const char*)verticesData, (const char*)verticesData + decl->size * numVertices);
-            current().indices.assign((const char*)indicesData, (const char*)indicesData + numIndices * (indicesShortType ? 2 : 1));
+            current().indices.assign(indicesData, indicesData + numIndices);
 
             const vertexPCT2* v = (const vertexPCT2*)(&current().vertices.front());
             if (_batches.size() == 1)
@@ -169,7 +168,7 @@ namespace oxygine
                 for (int i = 0; i < STATE_NUM; ++i)
                     instance->setState((STATE)i, b.states[i]);
                 if (b.numIndices)
-                    instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices, &b.indices.front(), b.numIndices, b.indicesShortType);
+                    instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices, &b.indices.front(), b.numIndices);
                 else
                     instance->draw(b.pt, b.vdecl, &modified.front(), b.numVertices);
             }