chart2/source/view/main/OpenGLRender.cxx | 203 ++++++++++++++++++++++++------- chart2/source/view/main/OpenGLRender.hxx | 11 + 2 files changed, 170 insertions(+), 44 deletions(-)
New commits: commit 143f47dced2b01e4c379b14a03243b5fa514bad6 Author: Peilin <[email protected]> Date: Mon Jan 6 16:32:09 2014 +0800 fix the crash and add SetBackGroundColor of rectrangle Change-Id: I521de3e68af928a1c9879a20e72ea5290259bd2c diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 866d3d2..73aedac 100644 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -409,7 +409,7 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor (1.0f, 1.0f, 1.0f, 1.0f); + glClearColor (m_ClearColor.r, m_ClearColor.g, m_ClearColor.b, m_ClearColor.a); glClear(GL_COLOR_BUFFER_BIT); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -917,6 +917,12 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget): m_TextTexCoordID(1) { memset(&m_Line2DPointList, 0, sizeof(Line2DPointList)); + memset(&m_Bubble2DPointList, 0, sizeof(m_Bubble2DPointList)); + memset(&m_Bubble2DCircle, 0, sizeof(m_Bubble2DCircle)); + memset(&m_TextInfo, 0, sizeof(TextInfo)); + memset(&m_Area2DPointList, 0, sizeof(m_Area2DPointList)); + memset(&m_RectangleList, 0, sizeof(RectanglePointList)); + m_iFboIdx = 0; m_FboID[0] = 0; m_FboID[1] = 0; @@ -924,6 +930,14 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget): m_TextureObj[1] = 0; m_RboID[0] = 0; m_RboID[1] = 0; + m_iArbMultisampleSupported = 0; + m_iArbMultisampleFormat = 0; + m_ClearColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); + + for (size_t i = 0; i < sizeof(m_BackgroundColor) / sizeof(float); i++) + { + m_BackgroundColor[i] = 1.0; + } mxRenderTarget->setPosition(awt::Point(0,0)); } @@ -1358,31 +1372,45 @@ int OpenGLRender::RenderRectangleShape() RectanglePointList &pointList = m_RectangleShapePointList.front(); PosVecf3 trans = {pointList.x, pointList.y, pointList.z}; PosVecf3 angle = {0.0f, 0.0f, 0.0f}; - PosVecf3 scale = {pointList.xScale, pointList.yScale, 1.0f}; + PosVecf3 scale = {pointList.xScale / 2, pointList.yScale / 2, 1.0f}; MoveModelf(trans, angle, scale); m_MVP = m_Projection * m_View * m_Model; + //render to fbo //fill vertex buffer glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(square2DVertices), square2DVertices, GL_STATIC_DRAW); - glUseProgram(m_CommonProID); + glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(m_BackgroundColor), m_BackgroundColor, GL_STATIC_DRAW); + glUseProgram(m_BackgroundProID); - glUniform4fv(m_2DColorID, 1, &m_2DColor[0]); - glUniformMatrix4fv(m_MatrixID, 1, GL_FALSE, &m_MVP[0][0]); + glUniformMatrix4fv(m_BackgroundMatrixID, 1, GL_FALSE, &m_MVP[0][0]); // 1rst attribute buffer : vertices - glEnableVertexAttribArray(m_2DVertexID); + glEnableVertexAttribArray(m_BackgroundVertexID); glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); glVertexAttribPointer( - m_2DVertexID, // attribute. No particular reason for 0, but must match the layout in the shader. + m_BackgroundVertexID, // 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 ); + // 2nd attribute buffer : color + glEnableVertexAttribArray(m_BackgroundColorID); + glBindBuffer(GL_ARRAY_BUFFER, m_ColorBuffer); + glVertexAttribPointer( + m_BackgroundColorID, // attribute. No particular reason for 0, but must match the layout in the shader. + 4, // size + GL_FLOAT, // type + GL_FALSE, // normalized? + 0, // stride + (void*)0 // array buffer offset + ); glDrawArrays(GL_QUADS, 0, 4); - glDisableVertexAttribArray(m_2DVertexID); + glDisableVertexAttribArray(m_BackgroundVertexID); + glDisableVertexAttribArray(m_BackgroundColorID); glUseProgram(0); glBindBuffer(GL_ARRAY_BUFFER, 0); m_RectangleShapePointList.pop_front(); @@ -1390,6 +1418,7 @@ int OpenGLRender::RenderRectangleShape() return 0; } + int OpenGLRender::CreateTextTexture(::rtl::OUString textValue, sal_uInt32 color, const Font& rFont, awt::Point aPos, awt::Size aSize, long rotation) { VirtualDevice aDevice; @@ -1649,4 +1678,38 @@ int OpenGLRender::RenderArea2DShape() return 0; } +void OpenGLRender::SetBackGroundColor(long color1, long color2) +{ + sal_uInt8 r = (color1 & 0x00FF0000) >> 16; + sal_uInt8 g = (color1 & 0x0000FF00) >> 8; + sal_uInt8 b = (color1 & 0x000000FF); + + m_BackgroundColor[0] = (float)r / 255.0f; + m_BackgroundColor[1] = (float)g / 255.0f; + m_BackgroundColor[2] = (float)b / 255.0f; + m_BackgroundColor[3] = 1.0; + + m_BackgroundColor[4] = (float)r / 255.0f; + m_BackgroundColor[5] = (float)g / 255.0f; + m_BackgroundColor[6] = (float)b / 255.0f; + m_BackgroundColor[7] = 1.0; + + r = (color2 & 0x00FF0000) >> 16; + g = (color2 & 0x0000FF00) >> 8; + b = (color2 & 0x000000FF); + + m_BackgroundColor[8] = (float)r / 255.0f; + m_BackgroundColor[9] = (float)g / 255.0f; + m_BackgroundColor[10] = (float)b / 255.0f; + m_BackgroundColor[11] = 1.0; + + m_BackgroundColor[12] = (float)r / 255.0f; + m_BackgroundColor[13] = (float)g / 255.0f; + m_BackgroundColor[14] = (float)b / 255.0f; + m_BackgroundColor[15] = 1.0; + cout << "color1 = " << color1 << ", color2 = " << color2 << endl; + +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx index 4314670..a65730b 100644 --- a/chart2/source/view/main/OpenGLRender.hxx +++ b/chart2/source/view/main/OpenGLRender.hxx @@ -195,6 +195,7 @@ private: int WGLisExtensionSupported(const char *extension); int CreateMultiSampleFrameBufObj(); int Create2DCircle(int detail); + void SetBackGroundColor(long color1, long color2); private: // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units @@ -328,6 +329,9 @@ private: GLint m_BackgroundVertexID; GLint m_BackgroundColorID; + float m_BackgroundColor[16]; + glm::vec4 m_ClearColor; + }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 1abbc58ccfda56a0c465681b347f2b3ca54bbcbb Author: Peilin <[email protected]> Date: Mon Jan 6 15:22:30 2014 +0800 change glm perspective to ortho Change-Id: I507477cd6087d3fe6be998a75d5a66016d323447 diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index d099938..866d3d2 100644 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -815,7 +815,8 @@ int OpenGLRender::SetViewPoint(PosVeci3 camPos, PosVeci3 orgPos, int headUpFlag) glm::vec3(orgPos.x, orgPos.y ,orgPos.z), // and looks at the origin glm::vec3(0, (headUpFlag >= 0 ? 1 : -1) , 0) // Head is up (set to 0,-1,0 to look upside-down) ); - m_Projection = glm::perspective(45.0f, (float)m_iWidth / (float)m_iHeight, 0.1f, 100.0f); + //m_Projection = glm::perspective(45.0f, (float)m_iWidth / (float)m_iHeight, 0.1f, 100.0f); + m_Projection = glm::ortho((-(float)m_iWidth) / 2, ((float)m_iWidth) / 2, -((float)m_iHeight) / 2, ((float)m_iHeight) / 2, -2.0f, 100.0f); // In world coordinates return 0; } commit fd5f5881636330dd5ab5b87ae7b0cdd7388ce1a0 Author: Peilin <[email protected]> Date: Mon Jan 6 15:06:36 2014 +0800 modify shader and make SetLine2DShapePoint more precision Change-Id: Ia692a678d68d3b492661cd6946c1a63b5a2c8413 diff --git a/chart2/source/view/main/OpenGLRender.cxx b/chart2/source/view/main/OpenGLRender.cxx index 439358c..d099938 100644 --- a/chart2/source/view/main/OpenGLRender.cxx +++ b/chart2/source/view/main/OpenGLRender.cxx @@ -58,33 +58,34 @@ using namespace std; #define WGL_SAMPLES_ARB 0x2042 #endif -const char *ColorFragmemtShader = OPENGL_SHADER ( +const char *CommonFragmemtShader = OPENGL_SHADER ( -varying vec3 fragmentColor; +varying vec4 fragmentColor; void main() { - gl_FragColor = vec4(fragmentColor, 1); + gl_FragColor = fragmentColor; } ); -const char *TransformVertexShader = OPENGL_SHADER ( +const char *CommonVertexShader = OPENGL_SHADER ( -attribute vec3 vertexPosition_modelspace; -attribute vec3 vertexColor; -varying vec3 fragmentColor; +attribute vec3 vPosition; uniform mat4 MVP; +uniform vec4 vColor; +varying vec4 fragmentColor; void main() { - gl_Position = MVP * vec4(vertexPosition_modelspace,1); - fragmentColor = vertexColor; + gl_Position = MVP * vec4(vPosition, 1); + fragmentColor = vColor; } ); -const char *Line2DFragmemtShader = OPENGL_SHADER ( + +const char *BackgroundFragmemtShader = OPENGL_SHADER ( varying vec4 fragmentColor; @@ -95,20 +96,22 @@ void main() ); -const char *Line2DVertexShader = OPENGL_SHADER ( +const char *BackgroundVertexShader = OPENGL_SHADER ( -attribute vec4 vPosition; -uniform vec4 vLineColor; +attribute vec3 vPosition; +uniform mat4 MVP; +attribute vec4 vColor; varying vec4 fragmentColor; void main() { - gl_Position = vPosition; - fragmentColor = vLineColor; + gl_Position = MVP * vec4(vPosition, 1); + fragmentColor = vColor; } ); + const char *RenderFragmentShader = OPENGL_SHADER ( uniform sampler2D RenderTex; @@ -116,7 +119,7 @@ varying vec2 vTexCoord; void main() { - gl_FragColor = vec4(texture2D(RenderTex, vTexCoord).rgb, 1); + gl_FragColor = vec4(texture2D(RenderTex, vTexCoord).rgb, 1.0); } ); @@ -135,6 +138,31 @@ void main() ); +const char *TextFragmentShader = OPENGL_SHADER ( +uniform sampler2D TextTex; +varying vec2 vTexCoord; +void main() +{ + gl_FragColor = vec4(texture2D(TextTex, vTexCoord).rgba); +} + +); + +const char *TextVertexShader = OPENGL_SHADER ( + +attribute vec3 vPosition; +uniform mat4 MVP; +attribute vec2 texCoord; +varying vec2 vTexCoord; +void main() +{ + gl_Position = MVP * vec4(vPosition, 1); + vTexCoord = texCoord; +} + +); + + static GLfloat squareVertices[] = { -1.0f, -1.0f, -1.0, @@ -392,21 +420,32 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow) glm::vec3(0,0,0), // and looks at the origin glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) ); - m_ProgramID = LoadShaders(TransformVertexShader, ColorFragmemtShader); + m_MVP = m_Projection * m_View * m_Model; glGenBuffers(1, &m_VertexBuffer); glGenBuffers(1, &m_ColorBuffer); - m_MatrixID = glGetUniformLocation(m_ProgramID, "MVP"); - m_VertexID = glGetAttribLocation(m_ProgramID, "vertexPosition_modelspace"); - m_ColorID = glGetAttribLocation(m_ProgramID, "vertexColor"); m_RenderProID = LoadShaders(RenderVertexShader, RenderFragmentShader); m_RenderVertexID = glGetAttribLocation(m_RenderProID, "vPosition"); m_RenderTexCoordID = glGetAttribLocation(m_RenderProID, "texCoord"); m_RenderTexID = glGetUniformLocation(m_RenderProID, "RenderTex"); - m_Line2DProID = LoadShaders(Line2DVertexShader, Line2DFragmemtShader); - m_Line2DVertexID = glGetAttribLocation(m_Line2DProID, "vPosition"); - m_Line2DColorID = glGetUniformLocation(m_Line2DProID, "vLineColor"); + m_CommonProID = LoadShaders(CommonVertexShader, CommonFragmemtShader); + m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP"); + m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition"); + m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor"); + + m_BackgroundProID = LoadShaders(BackgroundVertexShader, BackgroundFragmemtShader); + m_BackgroundMatrixID = glGetUniformLocation(m_BackgroundProID, "MVP"); + m_BackgroundVertexID = glGetAttribLocation(m_BackgroundProID, "vPosition"); + m_BackgroundColorID = glGetAttribLocation(m_BackgroundProID, "vColor"); + + m_TextProID = LoadShaders(TextVertexShader, TextFragmentShader); + m_TextMatrixID = glGetUniformLocation(m_TextProID, "MVP"); + m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition"); + m_TextTexCoordID = glGetAttribLocation(m_TextProID, "texCoord"); + m_TextTexID = glGetUniformLocation(m_TextProID, "TextTex"); + + CHECK_GL_ERROR(); glGenBuffers(1, &m_RenderVertexBuf); glBindBuffer(GL_ARRAY_BUFFER, m_RenderVertexBuf); @@ -417,6 +456,12 @@ int OpenGLRender::InitOpenGL(GLWindow aWindow) glBindBuffer(GL_ARRAY_BUFFER, m_RenderTexCoordBuf); glBufferData(GL_ARRAY_BUFFER, sizeof(coordVertices), coordVertices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); + + glGenBuffers(1, &m_TextTexCoordBuf); + glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf); + glBufferData(GL_ARRAY_BUFFER, sizeof(coordVertices), coordVertices, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + #if defined( WNT ) SwapBuffers(glWin.hDC); glFlush(); @@ -482,22 +527,30 @@ BitmapEx OpenGLRender::GetAsBitmap() int OpenGLRender::SetLine2DShapePoint(float x, float y, int listLength) { - if (!m_Line2DPoitList.pointBuf) + if (!m_Line2DPointList.pointBuf) { //a new point buffer should be alloc, we should push the old buffer first - m_Line2DPoitList.bufLen = listLength * sizeof(float) * 2; - m_Line2DPoitList.pointBuf = (float *)malloc(m_Line2DPoitList.bufLen); + m_Line2DPointList.bufLen = listLength * sizeof(float) * 3; + m_Line2DPointList.pointBuf = (float *)malloc(m_Line2DPointList.bufLen); + m_iPointNum = 0; } + float actualX = (x / OPENGL_SCALE_VALUE) - ((float)m_iWidth / 2); + float actualY = (y / OPENGL_SCALE_VALUE) - ((float)m_iHeight / 2); + m_Line2DPointList.pointBuf[m_iPointNum++] = actualX; + m_Line2DPointList.pointBuf[m_iPointNum++] = actualY; + m_Line2DPointList.pointBuf[m_iPointNum++] = m_fZStep; + m_fPicLeft = actualX < m_fPicLeft ? actualX : m_fPicLeft; - float zeroX = (float)m_iWidth * 10; - float zeroY = (float)m_iHeight * 10; - m_Line2DPoitList.pointBuf[m_iPointNum++] = 3.5 * ((x - zeroX) / zeroX + 0.3); - m_Line2DPoitList.pointBuf[m_iPointNum++] = 3.5 * ((y - zeroY) / zeroY + 0.25); + m_fPicRight = actualX > m_fPicRight ? actualX : m_fPicRight; - if (m_iPointNum == (listLength << 1)) + m_fPicBottom = actualY < m_fPicBottom ? actualY : m_fPicBottom; + + m_fPicTop = actualY > m_fPicTop ? actualY : m_fPicTop; + + if (m_iPointNum == (listLength * 3)) { - m_Line2DShapePointList.push_back(m_Line2DPoitList); - m_Line2DPoitList.pointBuf = NULL; + m_Line2DShapePointList.push_back(m_Line2DPointList); + m_Line2DPointList.pointBuf = NULL; m_iPointNum = 0; } return 0; @@ -862,7 +915,7 @@ OpenGLRender::OpenGLRender(uno::Reference< drawing::XShape > xTarget): m_TextVertexID(0), m_TextTexCoordID(1) { - memset(&m_Line2DPoitList, 0, sizeof(Line2DPointList)); + memset(&m_Line2DPointList, 0, sizeof(Line2DPointList)); m_iFboIdx = 0; m_FboID[0] = 0; m_FboID[1] = 0; diff --git a/chart2/source/view/main/OpenGLRender.hxx b/chart2/source/view/main/OpenGLRender.hxx index b5a8f0e..4314670 100644 --- a/chart2/source/view/main/OpenGLRender.hxx +++ b/chart2/source/view/main/OpenGLRender.hxx @@ -264,7 +264,7 @@ private: int m_iPointNum; - Line2DPointList m_Line2DPoitList; + Line2DPointList m_Line2DPointList; int m_iFboIdx; @@ -323,6 +323,11 @@ private: Area2DPointList m_Area2DPointList; std::list <Area2DPointList> m_Area2DShapePointList; + GLint m_BackgroundProID; + GLint m_BackgroundMatrixID; + GLint m_BackgroundVertexID; + GLint m_BackgroundColorID; + }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
