summaryrefslogtreecommitdiff
path: root/vcl/opengl/program.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-07-08 18:43:32 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-07-09 10:09:17 +0900
commit2e99e4e11d33679aed674eea0d6054d16d39d6df (patch)
tree219bebe169c7322758df36770e3fdc3206c6aa5d /vcl/opengl/program.cxx
parenta1385d37e9ffc84b82e9ee11e505bba6273823dc (diff)
opengl: use MVP matrix in vertex shaders, pixel offsets
ChangChange all vertex shaders to accept model, view, projection matrix to calculate the vertex position. So now we don't need to convert the coordinates to OpenGL coordinate space [-1.0, 1.0] anymore. Additionally make it possible to offset vertex coordinates so we can apply 0.5 px offset (to hit the pixel center) at some operations. Change-Id: I8e0a61d5fd4ab6aaa1c0c94439061725918577a0
Diffstat (limited to 'vcl/opengl/program.cxx')
-rw-r--r--vcl/opengl/program.cxx30
1 files changed, 26 insertions, 4 deletions
diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx
index d40aa30695f9..157243b746bc 100644
--- a/vcl/opengl/program.cxx
+++ b/vcl/opengl/program.cxx
@@ -13,6 +13,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
+#include <glm/gtc/matrix_transform.hpp>
OpenGLProgram::OpenGLProgram() :
mnId( 0 ),
@@ -238,6 +239,19 @@ void OpenGLProgram::SetTransform(
glUniformMatrix4fv( nUniform, 1, GL_FALSE, glm::value_ptr( mMatrix ) );
}
+void OpenGLProgram::ApplyMatrix(float fWidth, float fHeight, float fPixelOffset)
+{
+ OString sProjectionMatrix("mvp");
+ GLuint nUniform = GetUniformLocation(sProjectionMatrix);
+
+ glm::mat4 mMVP = glm::ortho(0.0f, fWidth, fHeight, 0.0f, 0.0f, 1.0f);
+
+ if (fPixelOffset != 0.0f)
+ mMVP = glm::translate(mMVP, glm::vec3(fPixelOffset, fPixelOffset, 0.0f));
+
+ glUniformMatrix4fv(nUniform, 1, GL_FALSE, glm::value_ptr(mMVP));
+}
+
void OpenGLProgram::SetBlendMode( GLenum nSFactor, GLenum nDFactor )
{
glEnable( GL_BLEND );
@@ -247,12 +261,20 @@ void OpenGLProgram::SetBlendMode( GLenum nSFactor, GLenum nDFactor )
bool OpenGLProgram::DrawTexture( OpenGLTexture& rTexture )
{
- GLfloat aPosition[8] = { -1, -1, -1, 1, 1, 1, 1, -1 };
- GLfloat aTexCoord[8];
-
- if( !rTexture )
+ if (!rTexture)
return false;
+ float fWidth = rTexture.GetWidth();
+ float fHeight = rTexture.GetHeight();
+
+ float fMinX = 0.0f;
+ float fMaxX = fWidth;
+ float fMinY = 0.0f;
+ float fMaxY = fHeight;
+
+ GLfloat aPosition[8] = { fMinX, fMaxY, fMinX, fMinY, fMaxX, fMinY, fMaxX, fMaxY };
+ GLfloat aTexCoord[8];
+
rTexture.GetWholeCoord( aTexCoord );
SetVertices( aPosition );
SetTextureCoord( aTexCoord );