Kaydet (Commit) 7d1c123a authored tarafından Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot Kaydeden (comit) Tomaž Vajngerl

slideshow: Upload the projection and modelview matrices as uniforms

Change-Id: I9d6c3ad0d2cc2f691afb2c8622471286f8a5e1c7
üst 566eca14
......@@ -28,6 +28,8 @@
#version 120
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_sceneTransformMatrix;
uniform mat4 u_primitiveTransformMatrix;
uniform mat4 u_operationsTransformMatrix;
......@@ -37,9 +39,9 @@ varying vec3 v_normal;
void main( void )
{
mat4 modelViewMatrix = gl_ModelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
gl_Position = gl_ProjectionMatrix * modelViewMatrix * gl_Vertex;
gl_Position = u_projectionMatrix * modelViewMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
v_normal = normalize(normalMatrix * gl_Normal);
}
......
......@@ -28,6 +28,8 @@
#version 130
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_sceneTransformMatrix;
uniform mat4 u_primitiveTransformMatrix;
uniform mat4 u_operationsTransformMatrix;
......@@ -38,9 +40,9 @@ varying float v_isShadow;
void main( void )
{
mat4 modelViewMatrix = gl_ModelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
gl_Position = gl_ProjectionMatrix * modelViewMatrix * gl_Vertex;
gl_Position = u_projectionMatrix * modelViewMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
v_normal = normalize(normalMatrix * gl_Normal);
v_isShadow = float(gl_VertexID >= 6);
......
......@@ -74,6 +74,43 @@ void OGLTransitionImpl::setScene(TransitionScene const& rScene)
maScene = rScene;
}
void OGLTransitionImpl::uploadModelViewProjectionMatrices()
{
double EyePos(10.0);
double RealF(1.0);
double RealN(-1.0);
double RealL(-1.0);
double RealR(1.0);
double RealB(-1.0);
double RealT(1.0);
double ClipN(EyePos+5.0*RealN);
double ClipF(EyePos+15.0*RealF);
double ClipL(RealL*8.0);
double ClipR(RealR*8.0);
double ClipB(RealB*8.0);
double ClipT(RealT*8.0);
glm::mat4 projection = glm::frustum<float>(ClipL, ClipR, ClipB, ClipT, ClipN, ClipF);
//This scaling is to take the plane with BottomLeftCorner(-1,-1,0) and TopRightCorner(1,1,0) and map it to the screen after the perspective division.
glm::vec3 scale(1.0 / (((RealR * 2.0 * ClipN) / (EyePos * (ClipR - ClipL))) - ((ClipR + ClipL) / (ClipR - ClipL))),
1.0 / (((RealT * 2.0 * ClipN) / (EyePos * (ClipT - ClipB))) - ((ClipT + ClipB) / (ClipT - ClipB))),
1.0);
projection = glm::scale(projection, scale);
glm::mat4 modelview = glm::translate(glm::mat4(), glm::vec3(0, 0, -EyePos));
GLint location = glGetUniformLocation( m_nProgramObject, "u_projectionMatrix" );
if( location != -1 ) {
glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection));
CHECK_GL_ERROR();
}
location = glGetUniformLocation( m_nProgramObject, "u_modelViewMatrix" );
if( location != -1 ) {
glUniformMatrix4fv(location, 1, false, glm::value_ptr(modelview));
CHECK_GL_ERROR();
}
}
void OGLTransitionImpl::prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex )
{
const SceneObjects_t& rSceneObjects(maScene.getSceneObjects());
......@@ -100,6 +137,8 @@ void OGLTransitionImpl::prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteri
CHECK_GL_ERROR();
}
uploadModelViewProjectionMatrices();
m_nPrimitiveTransformLocation = glGetUniformLocation( m_nProgramObject, "u_primitiveTransformMatrix" );
m_nSceneTransformLocation = glGetUniformLocation( m_nProgramObject, "u_sceneTransformMatrix" );
m_nOperationsTransformLocation = glGetUniformLocation( m_nProgramObject, "u_operationsTransformMatrix" );
......
......@@ -212,6 +212,10 @@ private:
TransitionScene maScene;
const TransitionSettings maSettings;
/** Calculates the projection and model/view matrices, and upload them.
*/
void uploadModelViewProjectionMatrices();
/** Uniform location for primitive transform
*/
GLint m_nPrimitiveTransformLocation = -1;
......
......@@ -207,7 +207,6 @@ protected:
bool useMipmap,
uno::Sequence<sal_Int8>& data,
const OGLFormat* pFormat );
static void prepareEnvironment();
const OGLFormat* chooseFormats();
private:
......@@ -532,7 +531,6 @@ void OGLTransitionerImpl::impl_prepareSlides()
void OGLTransitionerImpl::impl_prepareTransition()
{
prepareEnvironment();
if( mpTransition && mpTransition->getSettings().mnRequiredGLVersion <= mnGLVersion )
mpTransition->prepare( maLeavingSlideGL, maEnteringSlideGL );
}
......@@ -1014,41 +1012,6 @@ void OGLTransitionerImpl::impl_createTexture(
CHECK_GL_ERROR();
}
void OGLTransitionerImpl::prepareEnvironment()
{
double EyePos(10.0);
double RealF(1.0);
double RealN(-1.0);
double RealL(-1.0);
double RealR(1.0);
double RealB(-1.0);
double RealT(1.0);
double ClipN(EyePos+5.0*RealN);
double ClipF(EyePos+15.0*RealF);
double ClipL(RealL*8.0);
double ClipR(RealR*8.0);
double ClipB(RealB*8.0);
double ClipT(RealT*8.0);
CHECK_GL_ERROR();
glMatrixMode(GL_PROJECTION);
glm::mat4 projection = glm::frustum<float>(ClipL, ClipR, ClipB, ClipT, ClipN, ClipF);
//This scaling is to take the plane with BottomLeftCorner(-1,-1,0) and TopRightCorner(1,1,0) and map it to the screen after the perspective division.
glm::vec3 scale(1.0 / (((RealR * 2.0 * ClipN) / (EyePos * (ClipR - ClipL))) - ((ClipR + ClipL) / (ClipR - ClipL))),
1.0 / (((RealT * 2.0 * ClipN) / (EyePos * (ClipT - ClipB))) - ((ClipT + ClipB) / (ClipT - ClipB))),
1.0);
projection = glm::scale(projection, scale);
CHECK_GL_ERROR();
glLoadMatrixf(glm::value_ptr(projection));
CHECK_GL_ERROR();
glMatrixMode(GL_MODELVIEW);
glm::mat4 modelview = glm::translate(glm::mat4(), glm::vec3(0, 0, -EyePos));
CHECK_GL_ERROR();
glLoadMatrixf(glm::value_ptr(modelview));
CHECK_GL_ERROR();
}
const OGLFormat* OGLTransitionerImpl::chooseFormats()
{
const OGLFormat* pDetectedFormat=nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment