From a7aee918139fa62b5d43a852919b2ad63df86689 Mon Sep 17 00:00:00 2001 From: gazer Date: Sat, 12 Dec 2015 14:11:24 +0300 Subject: [PATCH] vbo fill method --- src/dlangui/graphics/glsupport.d | 102 ++++++++----------------------- 1 file changed, 25 insertions(+), 77 deletions(-) diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d index f1e4e70b..a0be22fd 100644 --- a/src/dlangui/graphics/glsupport.d +++ b/src/dlangui/graphics/glsupport.d @@ -317,20 +317,7 @@ class SolidFillProgram : GLProgram { VAO vao = new VAO(); VBO vbo = new VBO(); - glBufferData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof, - null, - GL_STREAM_DRAW); - glBufferSubData( - GL_ARRAY_BUFFER, - 0, - vertices.length * vertices[0].sizeof, - vertices.ptr); - glBufferSubData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof, - colors.length * colors[0].sizeof, colors.ptr); + vbo.fill([vertices, colors]); glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0); glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof)); @@ -361,21 +348,7 @@ class LineProgram : SolidFillProgram { VAO vao = new VAO(); VBO vbo = new VBO(); - glBufferData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof, - null, - GL_STREAM_DRAW); - glBufferSubData( - GL_ARRAY_BUFFER, - 0, - vertices.length * vertices[0].sizeof, - vertices.ptr); - glBufferSubData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof, - colors.length * colors[0].sizeof, - colors.ptr); + vbo.fill([vertices, colors]); glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0); glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof)); @@ -446,28 +419,7 @@ class TextureProgram : SolidFillProgram { VAO vao = new VAO(); VBO vbo = new VBO(); - glBufferData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof + - colors.length * colors[0].sizeof + - texcoords.length * texcoords[0].sizeof, - null, - GL_STREAM_DRAW); - glBufferSubData( - GL_ARRAY_BUFFER, - 0, - vertices.length * vertices[0].sizeof, - vertices.ptr); - glBufferSubData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof, - colors.length * colors[0].sizeof, - colors.ptr); - glBufferSubData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof, - texcoords.length * texcoords[0].sizeof, - texcoords.ptr); + vbo.fill([vertices, colors, texcoords]); glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0); glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof)); @@ -563,28 +515,7 @@ class FontProgram : SolidFillProgram { VAO vao = new VAO(); VBO vbo = new VBO(); - glBufferData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof + - colors.length * colors[0].sizeof + - texcoords.length * texcoords[0].sizeof, - null, - GL_STREAM_DRAW); - glBufferSubData( - GL_ARRAY_BUFFER, - 0, - vertices.length * vertices[0].sizeof, - vertices.ptr); - glBufferSubData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof, - colors.length * colors[0].sizeof, - colors.ptr); - glBufferSubData( - GL_ARRAY_BUFFER, - vertices.length * vertices[0].sizeof + colors.length * colors[0].sizeof, - texcoords.length * texcoords[0].sizeof, - texcoords.ptr); + vbo.fill([vertices, colors, texcoords]); glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cast(void*) 0); glVertexAttribPointer(colAttrLocation, 4, GL_FLOAT, GL_FALSE, 0, cast(void*) (vertices.length * vertices[0].sizeof)); @@ -691,10 +622,6 @@ class GLSupport { return true; } - bool isTexture(uint textureId) { - return glIsTexture(textureId) == GL_TRUE; - } - void setRotation(int x, int y, int rotationAngle) { /* this->rotationAngle = rotationAngle; @@ -1184,6 +1111,27 @@ class GLObject(GLObjectTypes type, GLuint target = 0) { mixin("glBind" ~ to!string(type) ~ "(0);"); checkError("unbind " ~ to!string(type)); } + + static if(type == GLObjectTypes.Buffer) + { + void fill(float[][] buffs) { + int length; + foreach(b; buffs) + length += b.length; + glBufferData(target, + length * float.sizeof, + null, + GL_STREAM_DRAW); + int offset; + foreach(b; buffs) { + glBufferSubData(target, + offset, + b.length * float.sizeof, + b.ptr); + offset += b.length * float.sizeof; + } + } + } static if(type == GLObjectTypes.Texture) {