use shader to calculate alpha channel

Conflicts:
	chart2/source/view/main/GL3DRenderer.cxx

Change-Id: I3cf9636b36ffd47589dd3ab61278802ca73644ce
This commit is contained in:
weigao 2014-06-18 01:10:05 -07:00 committed by Markus Mohrhard
parent f4436dcb95
commit 87e23f425f
5 changed files with 34 additions and 30 deletions

View file

@ -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: */

View file

@ -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: */

View file

@ -373,8 +373,6 @@ private:
float m_fViewAngle;
float m_fHeightWeight;
bool mbPickingMode;
GLuint mnPickingFbo;

View file

@ -12,6 +12,7 @@
#include <vcl/svapp.hxx>
#include <vcl/opengl/OpenGLHelper.hxx>
#include <vcl/bmpacc.hxx>
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;

View file

@ -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<sal_uInt8> &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<sal_uInt8> &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);