summaryrefslogtreecommitdiff
path: root/vcl/opengl/program.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-06-07 20:45:14 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2016-06-08 17:12:28 +0900
commitce72e34b359c323ef7ff96a70500810a9cd8703a (patch)
tree7436ef509b6670c4331d2e2f0c552728e13ea1f8 /vcl/opengl/program.cxx
parent4bdbfdd6426460c562746c67c29a3b5e2bef8563 (diff)
opengl: batch drawing of polylines
To get polylines to draw in a batch it was necessary to refactor the polyline code to work with GL_TRIANGLES instead of the previous used GL_TRIANGLE_STRIP. For this and to make the code easier to handle a new class was introduced: LineBuilder, which purpose is to assemble vertices for a polyline (line ends, line joints). In addition we need to know the line width, anti-aliasing (AA) per vertex basis (in addition to color, normal and extrusion) so we can draw many polylines with one draw call. This info is now stored in Vertex struct which is used when drawing lines or triangles (fills). Uploading of vertices has also been changed, previously we uploaded the vertices with the drawcall. a convention in Modern OpenGL is however to use VBO (Vertex Buffer Object) for this. With this we can upload the to the GPU vertices independently and not upload them if this is not needed (which is currently not used yet). A vector of Vertex structs is now uploaded to the GPU using a VBO which is handeled with a new VertexBufferObject class. In addition to reduce the ammount of duplicated vertices, we use a index vector (handled by IndexBufferObject class) where we only define the indices of the vertex buffer which should be drawn. Change-Id: I49dc9c6260b459f4f4ce3a5e4fa4c8ad05a7b878
Diffstat (limited to 'vcl/opengl/program.cxx')
-rw-r--r--vcl/opengl/program.cxx28
1 files changed, 19 insertions, 9 deletions
diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx
index 8aadb9d89c67..692b61afb6d7 100644
--- a/vcl/opengl/program.cxx
+++ b/vcl/opengl/program.cxx
@@ -113,11 +113,13 @@ bool OpenGLProgram::EnableVertexAttrib(GLuint& rAttrib, const OString& rName)
return true;
}
-void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData, GLint nSize )
+void OpenGLProgram::SetVertexAttrib(GLuint& rAttrib, const OString& rName, GLint nSize,
+ GLenum eType, GLboolean bNormalized, GLsizei aStride,
+ const GLvoid* pPointer)
{
if (EnableVertexAttrib(rAttrib, rName))
{
- glVertexAttribPointer( rAttrib, nSize, GL_FLOAT, GL_FALSE, 0, pData );
+ glVertexAttribPointer(rAttrib, nSize, eType, bNormalized, aStride, pPointer);
CHECK_GL_ERROR();
}
else
@@ -128,32 +130,32 @@ void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, cons
void OpenGLProgram::SetVertices( const GLvoid* pData )
{
- SetVertexAttrib( mnPositionAttrib, "position", pData );
+ SetVertexAttrib(mnPositionAttrib, "position", 2, GL_FLOAT, GL_FALSE, 0, pData);
}
void OpenGLProgram::SetTextureCoord( const GLvoid* pData )
{
- SetVertexAttrib( mnTexCoordAttrib, "tex_coord_in", pData );
+ SetVertexAttrib(mnTexCoordAttrib, "tex_coord_in", 2, GL_FLOAT, GL_FALSE, 0, pData);
}
void OpenGLProgram::SetAlphaCoord( const GLvoid* pData )
{
- SetVertexAttrib( mnAlphaCoordAttrib, "alpha_coord_in", pData );
+ SetVertexAttrib(mnAlphaCoordAttrib, "alpha_coord_in", 2, GL_FLOAT, GL_FALSE, 0, pData);
}
void OpenGLProgram::SetMaskCoord(const GLvoid* pData)
{
- SetVertexAttrib(mnMaskCoordAttrib, "mask_coord_in", pData);
+ SetVertexAttrib(mnMaskCoordAttrib, "mask_coord_in", 2, GL_FLOAT, GL_FALSE, 0, pData);
}
void OpenGLProgram::SetExtrusionVectors(const GLvoid* pData)
{
- SetVertexAttrib(mnExtrusionVectorsAttrib, "extrusion_vectors", pData, 3);
+ SetVertexAttrib(mnExtrusionVectorsAttrib, "extrusion_vectors", 3, GL_FLOAT, GL_FALSE, 0, pData);
}
-void OpenGLProgram::SetVertexColors(std::vector<glm::vec4>& rColorVector)
+void OpenGLProgram::SetVertexColors(std::vector<GLubyte>& rColorVector)
{
- SetVertexAttrib(mnVertexColorsAttrib, "vertex_color_in", glm::value_ptr(rColorVector[0]), 4);
+ SetVertexAttrib(mnVertexColorsAttrib, "vertex_color_in", 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, rColorVector.data());
}
void OpenGLProgram::SetShaderType(TextureShaderType eTextureShaderType)
@@ -189,6 +191,14 @@ void OpenGLProgram::DrawArrays(GLenum aMode, std::vector<GLfloat>& aVertices)
glDrawArrays(aMode, 0, aVertices.size() / 2);
}
+void OpenGLProgram::DrawElements(GLenum aMode, GLuint nNumberOfVertices)
+{
+ if (!mbBlending)
+ OpenGLContext::getVCLContext()->state()->blend().disable();
+
+ glDrawElements(aMode, nNumberOfVertices, GL_UNSIGNED_INT, nullptr);
+}
+
void OpenGLProgram::SetUniform1f( const OString& rName, GLfloat v1 )
{
GLuint nUniform = GetUniformLocation( rName );