From 87e23f425f60b0b7459c63b824bc8bdc17796ad2 Mon Sep 17 00:00:00 2001 From: weigao Date: Wed, 18 Jun 2014 01:10:05 -0700 Subject: [PATCH] use shader to calculate alpha channel Conflicts: chart2/source/view/main/GL3DRenderer.cxx Change-Id: I3cf9636b36ffd47589dd3ab61278802ca73644ce --- chart2/opengl/screenTextFragmentShader.glsl | 3 +- chart2/opengl/textFragmentShader.glsl | 3 +- chart2/source/view/inc/GL3DRenderer.hxx | 2 - chart2/source/view/main/3DChartObjects.cxx | 11 ++++- chart2/source/view/main/GL3DRenderer.cxx | 45 +++++++++------------ 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/chart2/opengl/screenTextFragmentShader.glsl b/chart2/opengl/screenTextFragmentShader.glsl index a8481034210a..7e2bd26e1069 100644 --- a/chart2/opengl/screenTextFragmentShader.glsl +++ b/chart2/opengl/screenTextFragmentShader.glsl @@ -11,7 +11,8 @@ varying vec2 vTexCoord; uniform sampler2D TextTex; void main() { - gl_FragColor = vec4(texture2D(TextTex, vTexCoord).rgba); + vec3 color = texture2D(TextTex, vTexCoord).rgb; + gl_FragColor = vec4(color, 1.0 - color.r); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/opengl/textFragmentShader.glsl b/chart2/opengl/textFragmentShader.glsl index ef8d44d6949d..c1d44bc56f63 100644 --- a/chart2/opengl/textFragmentShader.glsl +++ b/chart2/opengl/textFragmentShader.glsl @@ -11,7 +11,8 @@ uniform sampler2D TextTex; varying vec2 vTexCoord; void main() { - gl_FragColor = vec4(texture2D(TextTex, vTexCoord).rgba); + vec3 color = texture2D(TextTex, vTexCoord).rgb; + gl_FragColor = vec4(color, 1.0 - color.r); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 6218fbcefa7b..0821cfe67960 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -373,8 +373,6 @@ private: float m_fViewAngle; - float m_fHeightWeight; - bool mbPickingMode; GLuint mnPickingFbo; diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 1b962c69168c..f1db16f5aef8 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -12,6 +12,7 @@ #include #include +#include namespace chart { @@ -90,7 +91,15 @@ const TextCacheItem& TextCache::getText(OUString const & rText) aDevice.DrawText(Point(0,0), rText); BitmapEx aText(aDevice.GetBitmapEx(Point(0,0), aDevice.GetOutputSize())); - TextCacheItem *pItem = new TextCacheItem(OpenGLHelper::ConvertBitmapExToRGBABuffer(aText), aText.GetSizePixel()); +// TextCacheItem *pItem = new TextCacheItem(OpenGLHelper::ConvertBitmapExToRGBABuffer(aText), aText.GetSizePixel()); + Bitmap aBitmap (aText.GetBitmap()); + BitmapReadAccess *pAcc = aBitmap.AcquireReadAccess(); + sal_uInt8 *buf = (sal_uInt8 *)pAcc->GetBuffer(); + long nBmpWidth = aText.GetSizePixel().Width(); + long nBmpHeight = aText.GetSizePixel().Height(); + sal_uInt8* pBitmapBuf(new sal_uInt8[3* nBmpWidth * nBmpHeight]); + memcpy(pBitmapBuf, buf, 3* nBmpWidth * nBmpHeight); + TextCacheItem *pItem = new TextCacheItem(pBitmapBuf, aText.GetSizePixel()); maTextCache.insert(rText, pItem); return *maTextCache.find(rText)->second; diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 12912302f420..d3db57c572c7 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -55,10 +55,10 @@ int static checkGLError(const char *file, int line) #define CHECK_GL_ERROR() checkGLError(__FILE__, __LINE__) GLfloat texCoords[] = { - 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 1.0f + 0.0f, 1.0f, + 0.0f, 0.0f }; glm::vec4 getColorAsVector(sal_uInt32 nColor) @@ -88,7 +88,6 @@ OpenGL3DRenderer::OpenGL3DRenderer(): , m_RenderVertexBuf(0) , m_RenderTexCoordBuf(0) , m_fViewAngle(30.0f) - , m_fHeightWeight(1.0f) , mbPickingMode(false) , mnPickingFbo(0) , mnPickingRboDepth(0) @@ -786,7 +785,7 @@ void OpenGL3DRenderer::RenderLine3D(const Polygon3DInfo& polygon) glUseProgram(maResources.m_CommonProID); PosVecf3 trans = {0.0f, 0, 0.0}; PosVecf3 angle = {0.0f, 0.0f, 0.0f}; - PosVecf3 scale = {1.0f, 1.0f, m_fHeightWeight}; + PosVecf3 scale = {1.0f, 1.0f, 1.0f}; MoveModelf(trans, angle, scale); m_Model = m_GlobalScaleMatrix * m_Model; m_3DMVP = m_3DProjection * m_3DView * m_Model; @@ -877,7 +876,7 @@ void OpenGL3DRenderer::RenderPolygon3D(const Polygon3DInfo& polygon) Normals3D *normalList = polygon.normalsList[i]; PosVecf3 trans = {0.0f, 0.0f, 0.0}; PosVecf3 angle = {0.0f, 0.0f, 0.0f}; - PosVecf3 scale = {1.0f, 1.0f, m_fHeightWeight}; + PosVecf3 scale = {1.0f, 1.0f, 1.0f}; MoveModelf(trans, angle, scale); m_Model = m_GlobalScaleMatrix * m_Model; glm::mat3 normalMatrix(m_Model); @@ -1546,8 +1545,6 @@ void OpenGL3DRenderer::RenderExtrude3DObject() (void*)0 // array buffer offset ); } - extrude3DInfo.zTransform *= m_fHeightWeight; - extrude3DInfo.zScale *= m_fHeightWeight; if(!mbPickingMode) { if (maResources.m_b330Support) @@ -1598,22 +1595,22 @@ void OpenGL3DRenderer::CreateScreenTextTexture( TextInfo aTextInfo; aTextInfo.id = getColorAsVector(nUniqueId); - aTextInfo.vertex[0] = vTopLeft.x; - aTextInfo.vertex[1] = vTopLeft.y; + aTextInfo.vertex[0] = vBottomRight.x; + aTextInfo.vertex[1] = vBottomRight.y; aTextInfo.vertex[2] = 0; aTextInfo.vertex[3] = vBottomRight.x; aTextInfo.vertex[4] = vTopLeft.y; aTextInfo.vertex[5] = 0; + aTextInfo.vertex[6] = vTopLeft.x; + aTextInfo.vertex[7] = vTopLeft.y; + aTextInfo.vertex[8] = 0; + aTextInfo.vertex[9] = vTopLeft.x; aTextInfo.vertex[10] = vBottomRight.y; aTextInfo.vertex[11] = 0; - aTextInfo.vertex[6] = vBottomRight.x; - aTextInfo.vertex[7] = vBottomRight.y; - aTextInfo.vertex[8] = 0; - CHECK_GL_ERROR(); glGenTextures(1, &aTextInfo.texture); CHECK_GL_ERROR(); @@ -1627,7 +1624,7 @@ void OpenGL3DRenderer::CreateScreenTextTexture( CHECK_GL_ERROR(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpWidth, bmpHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapBuf.get()); CHECK_GL_ERROR(); glBindTexture(GL_TEXTURE_2D, 0); CHECK_GL_ERROR(); @@ -1645,21 +1642,21 @@ void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array &b TextInfo aTextInfo; aTextInfo.id = getColorAsVector(nUniqueId); - aTextInfo.vertex[0] = vTopLeft.x; - aTextInfo.vertex[1] = vTopLeft.y; - aTextInfo.vertex[2] = vTopLeft.z * m_fHeightWeight; + aTextInfo.vertex[0] = vBottomRight.x; + aTextInfo.vertex[1] = vBottomRight.y; + aTextInfo.vertex[2] = vBottomRight.z; aTextInfo.vertex[3] = vTopRight.x; aTextInfo.vertex[4] = vTopRight.y; - aTextInfo.vertex[5] = vTopRight.z * m_fHeightWeight; + aTextInfo.vertex[5] = vTopRight.z; aTextInfo.vertex[9] = vBottomLeft.x; aTextInfo.vertex[10] = vBottomLeft.y; - aTextInfo.vertex[11] = vBottomLeft.z * m_fHeightWeight; + aTextInfo.vertex[11] = vBottomLeft.z; - aTextInfo.vertex[6] = vBottomRight.x; - aTextInfo.vertex[7] = vBottomRight.y; - aTextInfo.vertex[8] = vBottomRight.z * m_fHeightWeight; + aTextInfo.vertex[6] = vTopLeft.x; + aTextInfo.vertex[7] = vTopLeft.y; + aTextInfo.vertex[8] = vTopLeft.z; CHECK_GL_ERROR(); glGenTextures(1, &aTextInfo.texture); @@ -1674,7 +1671,7 @@ void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array &b CHECK_GL_ERROR(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); CHECK_GL_ERROR(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bmpWidth, bmpHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuf.get()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpWidth, bmpHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapBuf.get()); CHECK_GL_ERROR(); glBindTexture(GL_TEXTURE_2D, 0); CHECK_GL_ERROR(); @@ -2013,8 +2010,6 @@ void OpenGL3DRenderer::GetBatchBarsInfo() for (size_t i = 0; i < m_Extrude3DList.size(); i++) { Extrude3DInfo &extrude3DInfo = m_Extrude3DList[i]; - extrude3DInfo.zTransform *= m_fHeightWeight; - extrude3DInfo.zScale *= m_fHeightWeight; if (m_Extrude3DInfo.rounded) { GetBatchTopAndFlatInfo(extrude3DInfo);