Kaydet (Commit) a63ad6f2 authored tarafından weigao's avatar weigao Kaydeden (comit) Markus Mohrhard

add reverse image shader

Change-Id: Ibd3aff8aeb71626dada762b53cde8f50f7fbf812
üst 8018772a
...@@ -22,6 +22,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg ...@@ -22,6 +22,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg
textVertexShader.glsl \ textVertexShader.glsl \
shape3DFragmentShader.glsl \ shape3DFragmentShader.glsl \
shape3DVertexShader.glsl \ shape3DVertexShader.glsl \
renderTextureVertexShader.glsl \
renderTextureFragmentShader.glsl \
)) ))
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
uniform sampler2D RenderTex;
varying vec2 vTexCoord;
void main()
{
gl_FragColor = vec4(texture2D(RenderTex, vTexCoord).rgb, 1.0);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
attribute vec4 vPosition;
attribute vec2 texCoord;
varying vec2 vTexCoord;
void main()
{
gl_Position = vPosition;
vTexCoord = texCoord;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -235,6 +235,7 @@ private: ...@@ -235,6 +235,7 @@ private:
int iSubDivZ, float width, float height, float depth); int iSubDivZ, float width, float height, float depth);
void CreateSceneBoxView(); void CreateSceneBoxView();
void CreateBMPHeader(sal_uInt8 *bmpHeader, int xsize, int ysize); void CreateBMPHeader(sal_uInt8 *bmpHeader, int xsize, int ysize);
void RenderTexture(GLuint TexID);
private: private:
// Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
glm::mat4 m_Projection; glm::mat4 m_Projection;
...@@ -353,6 +354,17 @@ private: ...@@ -353,6 +354,17 @@ private:
GLint m_2DVertexID; GLint m_2DVertexID;
GLint m_2DColorID; GLint m_2DColorID;
GLint m_RenderProID;
GLuint m_RenderVertexBuf;
GLuint m_RenderTexCoordBuf;
GLint m_RenderTexID;
GLint m_RenderVertexID;
GLint m_RenderTexCoordID;
//TODO: moggi: kill the following parts //TODO: moggi: kill the following parts
// don't add anything below or I will remove it // don't add anything below or I will remove it
#if 0 #if 0
......
...@@ -104,7 +104,7 @@ static const GLfloat boundBoxNormal[] = { ...@@ -104,7 +104,7 @@ static const GLfloat boundBoxNormal[] = {
1.0f, 0.0f, 0.0f//12 1.0f, 0.0f, 0.0f//12
}; };
GLfloat coordinateAxis[] = { static GLfloat coordinateAxis[] = {
-1.0, 0.0, 0.0, -1.0, 0.0, 0.0,
1.0, 0.0, 0.0,//x 1.0, 0.0, 0.0,//x
0.0, 0.0, -1.0, 0.0, 0.0, -1.0,
...@@ -113,3 +113,18 @@ GLfloat coordinateAxis[] = { ...@@ -113,3 +113,18 @@ GLfloat coordinateAxis[] = {
0.0, 1.0, 0.0//y 0.0, 1.0, 0.0//y
}; };
static GLfloat coordReverseVertices[] = {
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
};
static GLfloat squareVertices[] = {
-1.0f, -1.0f, -1.0,
1.0f, -1.0f, -1.0,
1.0f, 1.0f, -1.0,
-1.0f, 1.0f, -1.0
};
...@@ -127,6 +127,12 @@ void OpenGL3DRenderer::LoadShaders() ...@@ -127,6 +127,12 @@ void OpenGL3DRenderer::LoadShaders()
m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP"); m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP");
m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition"); m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor"); m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor");
m_RenderProID = OpenGLHelper::LoadShaders("renderTextureVertexShader", "renderTextureFragmentShader");
m_RenderVertexID = glGetAttribLocation(m_RenderProID, "vPosition");
m_RenderTexCoordID = glGetAttribLocation(m_RenderProID, "texCoord");
m_RenderTexID = glGetUniformLocation(m_RenderProID, "RenderTex");
printf("m_RenderProID = %d, m_RenderVertexID = %d\n", m_RenderProID, m_RenderVertexID);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
...@@ -181,7 +187,6 @@ void OpenGL3DRenderer::CreateFrameBufferObj() ...@@ -181,7 +187,6 @@ void OpenGL3DRenderer::CreateFrameBufferObj()
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RboID[i]); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RboID[i]);
glCheckFramebufferStatus(GL_FRAMEBUFFER); glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[0]);
} }
} }
...@@ -197,7 +202,40 @@ void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::ve ...@@ -197,7 +202,40 @@ void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::ve
m_CameraInfo.cameraUp = up; m_CameraInfo.cameraUp = up;
} }
void OpenGL3DRenderer::RenderTexture(GLuint TexID)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(m_RenderProID);
glEnableVertexAttribArray(m_RenderVertexID);
glBindBuffer(GL_ARRAY_BUFFER, m_RenderVertexBuf);
glVertexAttribPointer(
m_RenderVertexID, // attribute. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
glEnableVertexAttribArray(m_RenderTexCoordID);
glBindBuffer(GL_ARRAY_BUFFER, m_RenderTexCoordBuf);
glVertexAttribPointer(
m_RenderTexCoordID, // attribute. No particular reason for 0, but must match the layout in the shader.
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
glBindTexture(GL_TEXTURE_2D, TexID);
glUniform1i(m_RenderTexID, 0);
glDrawArrays(GL_QUADS, 0, 4);
glDisableVertexAttribArray(m_RenderTexCoordID);
glDisableVertexAttribArray(m_RenderVertexID);
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
}
void OpenGL3DRenderer::init() void OpenGL3DRenderer::init()
{ {
...@@ -251,6 +289,17 @@ void OpenGL3DRenderer::init() ...@@ -251,6 +289,17 @@ void OpenGL3DRenderer::init()
glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf); glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &m_RenderTexCoordBuf);
glBindBuffer(GL_ARRAY_BUFFER, m_RenderTexCoordBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(coordReverseVertices), coordReverseVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &m_RenderVertexBuf);
glBindBuffer(GL_ARRAY_BUFFER, m_RenderVertexBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(squareVertices), squareVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CHECK_GL_ERROR(); CHECK_GL_ERROR();
Init3DUniformBlock(); Init3DUniformBlock();
...@@ -1526,11 +1575,6 @@ void OpenGL3DRenderer::ProcessUnrenderedShape() ...@@ -1526,11 +1575,6 @@ void OpenGL3DRenderer::ProcessUnrenderedShape()
#if 1 #if 1
if ((!m_FboID[0]) || (!m_FboID[1])) if ((!m_FboID[0]) || (!m_FboID[1]))
{ {
// create a texture object
CreateTextureObj(m_iWidth, m_iHeight);
//create render buffer object
CreateRenderObj(m_iWidth, m_iHeight);
//create fbo
CreateFrameBufferObj(); CreateFrameBufferObj();
} }
glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[0]); glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[0]);
...@@ -1546,6 +1590,9 @@ void OpenGL3DRenderer::ProcessUnrenderedShape() ...@@ -1546,6 +1590,9 @@ void OpenGL3DRenderer::ProcessUnrenderedShape()
RenderTextShape(); RenderTextShape();
//render the axis //render the axis
RenderCoordinateAxis(); RenderCoordinateAxis();
glBindFramebuffer(GL_FRAMEBUFFER, m_FboID[1]);
glViewport(0, 0, m_iWidth, m_iHeight);
RenderTexture(m_TextureObj[0]);
#if DEBUG_FBO #if DEBUG_FBO
char fileName[256] = {0}; char fileName[256] = {0};
sprintf(fileName, "D://shaderout_%d_%d.bmp", m_iWidth, m_iHeight); sprintf(fileName, "D://shaderout_%d_%d.bmp", m_iWidth, m_iHeight);
......
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