diff --git a/uppsrc/GLDraw/Code.cpp b/uppsrc/GLDraw/Code.cpp index dcbe36d44..3116bd4fc 100644 --- a/uppsrc/GLDraw/Code.cpp +++ b/uppsrc/GLDraw/Code.cpp @@ -7,36 +7,55 @@ GLCode::GLCode(const char *vertex_shader, const char *pixel_shader) Compile(vertex_shader, pixel_shader); Vector> ins; CParser p(vertex_shader); - int ii = 0; - int ti = 0; - auto readID = [&] { + auto readID = [&](int& n) { String id; - while(!p.IsEof() && !p.Char(';')) - if(p.IsId()) + n = 0; + while(!p.IsEof() && !p.IsChar(';')) + if(p.IsId()) { id = p.ReadId(); - else + if(p.Char('[') && p.IsInt()) { + n = p.ReadInt(); + p.Char(']'); + } + } + else { p.SkipTerm(); + n = 0; + } return id; }; + int ii = 0; while(!p.IsEof() && !p.Char('{')) if(p.Id("attribute") || p.Id("in")) { - String id = readID(); + int n; + String id = readID(n); if(id.GetCount()) glBindAttribLocation(program, ii++, id); } else p.SkipTerm(); + Link(); + Use(); + p.Set(pixel_shader); + int ti = 0; while(!p.IsEof() && !p.Char('{')) if(p.Id("sampler2D") || p.Id("sampler3D")) { - String id = readID(); + int n; + String id = readID(n); if(id.GetCount()) - glUniform1i(GetUniform(id), ti++); + if(n) { + for(int i = 0; i < n; i++) { + ASSERT(GetUniform(id + '[' + AsString(i) + ']') >= 0); + glUniform1i(GetUniform(id + '[' + AsString(i) + ']'), ti++); + } + } + else + glUniform1i(GetUniform(id), ti++); } else p.SkipTerm(); - Link(); } GLCode& GLCode::Uniform(int i, double a) diff --git a/uppsrc/GLDraw/GLPainter.h b/uppsrc/GLDraw/GLPainter.h index 4de4cc4c5..39bf24791 100644 --- a/uppsrc/GLDraw/GLPainter.h +++ b/uppsrc/GLDraw/GLPainter.h @@ -78,7 +78,7 @@ public: void Clear(); void Set(const Image& img, dword flags = TEXTURE_LINEAR|TEXTURE_MIPMAP); - void Bind() const; + void Bind(int ii = 0) const; int GetID() const { return data ? data->textureid : 0; } operator GLuint() const { return GetID(); } Size GetSize() const { return data ? data->sz : Size(0, 0); } @@ -92,6 +92,7 @@ public: GLTexture& operator=(const GLTexture& src); }; +void GLBind(int ii, const Image& img, dword style = TEXTURE_LINEAR|TEXTURE_MIPMAP); void GLBind(const Image& img, dword style = TEXTURE_LINEAR|TEXTURE_MIPMAP); void GLDrawTexture(const GLContext2D& dd, const Rectf& rect, int textureid, Size tsz, const Rect& src); @@ -120,8 +121,10 @@ public: GLVertexData& Add(const void *data, int type, int ntuple, int count); GLVertexData& Add(const float *data, int ntuple, int count) { return Add(data, GL_FLOAT, ntuple, count); } GLVertexData& Add(const byte *data, int ntuple, int count) { return Add(data, GL_UNSIGNED_BYTE, ntuple, count); } + GLVertexData& Add(const dword *data, int ntuple, int count) { return Add(data, GL_UNSIGNED_INT, ntuple, count); } GLVertexData& Add(const Vector& data, int ntuple) { return Add(data, ntuple, data.GetCount() / ntuple); } GLVertexData& Add(const Vector& data, int ntuple) { return Add(data, ntuple, data.GetCount() / ntuple); } + GLVertexData& Add(const Vector& data, int ntuple) { return Add(data, ntuple, data.GetCount() / ntuple); } GLVertexData& Add(const Vector& pt); GLVertexData& Index(const int *indices, int count); GLVertexData& Index(const Vector& indices) { return Index(indices, indices.GetCount()); } @@ -306,6 +309,7 @@ int GLElementCounter(); int GLTextureCounter(); int GLProgramCounter(); int GLDrawCounter(); +int GLTesselateCounter(); }; diff --git a/uppsrc/GLDraw/GLTexture.cpp b/uppsrc/GLDraw/GLTexture.cpp index b387011ae..0ac33a945 100644 --- a/uppsrc/GLDraw/GLTexture.cpp +++ b/uppsrc/GLDraw/GLTexture.cpp @@ -27,9 +27,10 @@ void GLTexture::Set(const Image& img, dword flags) extern int sTextureCounter; -void GLTexture::Bind() const +void GLTexture::Bind(int ii) const { if(data) { + glActiveTexture(GL_TEXTURE0 + ii); glBindTexture(GL_TEXTURE_2D, data->textureid); sTextureCounter++; } @@ -51,13 +52,19 @@ GLTexture& GLTexture::operator=(const GLTexture& src) return *this; } -void GLBind(const Image& img, dword style) +void GLBind(int ii, const Image& img, dword style) { extern int sTextureCounter; + glActiveTexture(GL_TEXTURE0 + ii); glBindTexture(GL_TEXTURE_2D, GetTextureForImage(style, img)); sTextureCounter++; } +void GLBind(const Image& img, dword style) +{ + GLBind(0, img, style); +} + const GLVertexData& GLRectMesh() { static GLVertexData mesh; diff --git a/uppsrc/GLDraw/PerfCounters.cpp b/uppsrc/GLDraw/PerfCounters.cpp index 12e2e1623..da05f4669 100644 --- a/uppsrc/GLDraw/PerfCounters.cpp +++ b/uppsrc/GLDraw/PerfCounters.cpp @@ -6,10 +6,11 @@ int sDrawCounter; int sElementCounter; int sTextureCounter; int sProgramCounter; +int sTesselateCounter; void GLClearCounters() { - sElementCounter = sTextureCounter = sProgramCounter = sDrawCounter = 0; + sElementCounter = sTextureCounter = sProgramCounter = sDrawCounter = sTesselateCounter = 0; } int GLElementCounter() @@ -32,4 +33,9 @@ int GLDrawCounter() return sDrawCounter; } +int GLTesselateCounter() +{ + return sTesselateCounter; +} + }; \ No newline at end of file diff --git a/uppsrc/GLDraw/TDrawGL.cpp b/uppsrc/GLDraw/TDrawGL.cpp index f3764fa5f..fe04d2823 100644 --- a/uppsrc/GLDraw/TDrawGL.cpp +++ b/uppsrc/GLDraw/TDrawGL.cpp @@ -251,6 +251,8 @@ void DrawGL::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const i DoDrawPolylines(poly, width, color); } +extern int sTesselateCounter; + void DrawGL::DoDrawPolygons(const Vector>& path, Color color) { const int TESS_LIMIT = 200; @@ -268,6 +270,7 @@ void DrawGL::DoDrawPolygons(const Vector>& path, Color color) } Vector vertex; Vector> triangle; + sTesselateCounter++; RTIMING("Tesselate"); Tesselate(path, vertex, triangle, false); int ii0; diff --git a/uppsrc/GLDraw/Triangles.cpp b/uppsrc/GLDraw/Triangles.cpp index 9c2d5af55..aebc9bbcd 100644 --- a/uppsrc/GLDraw/Triangles.cpp +++ b/uppsrc/GLDraw/Triangles.cpp @@ -10,7 +10,7 @@ void GLTriangles::Draw(const GLContext2D& dd) static GLCode program(R"( #version 130 attribute vec3 p; - attribute vec3 c; + attribute uvec3 c; uniform vec2 offset; uniform vec2 scale; varying vec4 v_color; diff --git a/uppsrc/GLDraw/VertexData.cpp b/uppsrc/GLDraw/VertexData.cpp index e00bb0a49..b1d1c14d3 100644 --- a/uppsrc/GLDraw/VertexData.cpp +++ b/uppsrc/GLDraw/VertexData.cpp @@ -57,7 +57,10 @@ GLVertexData& GLVertexData::Add(const void *values, int type, int ntuple, int co GL_UNSIGNED_INT, sizeof(uint32), sizeof(double)); glBufferData(GL_ARRAY_BUFFER, sz * ntuple * count, values, GL_STATIC_DRAW); - glVertexAttribPointer(ii, ntuple, type, GL_FALSE, ntuple * sz, (void*)0); + if(type == GL_FLOAT) + glVertexAttribPointer(ii, ntuple, type, GL_FALSE, ntuple * sz, (void*)0); + else + glVertexAttribIPointer(ii, ntuple, type, ntuple * sz, (void*)0); glEnableVertexAttribArray(ii); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0);