[Libreoffice-commits] core.git: Branch 'feature/chart-3d-chart2' - 8 commits - chart2/opengl chart2/Package_opengl.mk chart2/source
weigao
weigao at multicorewareinc.com
Mon Jun 16 23:25:38 PDT 2014
chart2/Package_opengl.mk | 2
chart2/opengl/shape3DFragmentShaderV300.glsl | 87 +++++++++
chart2/opengl/shape3DVertexShaderV300.glsl | 29 +++
chart2/source/view/charttypes/GL3DBarChart.cxx | 83 ++++++---
chart2/source/view/inc/GL3DBarChart.hxx | 6
chart2/source/view/inc/GL3DRenderer.hxx | 20 ++
chart2/source/view/main/GL3DRenderer.cxx | 228 ++++++++++++++++++++-----
7 files changed, 387 insertions(+), 68 deletions(-)
New commits:
commit 796a9e97522ee1201a3f291f3c1c31d02541c789
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Jun 14 08:59:07 2014 -0700
add codes for calling the 3.0 shaders
Change-Id: I0e95879c04047ccb836543d801bda6a01ae469ef
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 1799396..9098cd1 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -172,6 +172,7 @@ void OpenGL3DRenderer::CheckGLSLVersion()
if (iVersion > 3)
{
maResources.m_b330Support = true;
+ maResources.m_b330Support = false;
return;
}
p++;
@@ -810,11 +811,6 @@ void OpenGL3DRenderer::RenderPolygon3D(Polygon3DInfo &polygon)
{
return ;
}
- //update ubo
- Update3DUniformBlock();
- glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
- glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &polygon.material);
- CHECK_GL_ERROR();
glBindBuffer(GL_UNIFORM_BUFFER, 0);
if(mbPickingMode)
{
@@ -825,6 +821,31 @@ void OpenGL3DRenderer::RenderPolygon3D(Polygon3DInfo &polygon)
glUseProgram(maResources.m_3DProID);
glUniformMatrix4fv(maResources.m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
glUniformMatrix4fv(maResources.m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
+ if (maResources.m_b330Support)
+ {
+ //update ubo
+ Update3DUniformBlock();
+ glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
+ glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &polygon.material);
+ CHECK_GL_ERROR();
+ }
+ else
+ {
+ //update light information
+ glUniform4fv(maResources.m_3DLightColorID, m_iLightNum, (GLfloat*)m_LightColor);
+ glUniform4fv(maResources.m_3DLightPosID, m_iLightNum, (GLfloat*)m_PositionWorldspace);
+ glUniform1fv(maResources.m_3DLightPowerID, m_iLightNum, m_fLightPower);
+ glUniform1i(maResources.m_3DLightNumID, m_iLightNum);
+ glUniform4fv(maResources.m_3DLightAmbientID, 1, &m_Ambient[0]);
+ //update meterial information
+ glUniform4fv(maResources.m_3DMaterialAmbientID, 1, &polygon.material.ambient[0]);
+ glUniform4fv(maResources.m_3DMaterialDiffuseID, 1, &polygon.material.diffuse[0]);
+ glUniform4fv(maResources.m_3DMaterialSpecularID, 1, &polygon.material.specular[0]);
+ glUniform4fv(maResources.m_3DMaterialColorID, 1, &polygon.material.materialColor[0]);
+ glUniform1i(maResources.m_3DMaterialTwoSidesID, polygon.material.twoSidesLighting);
+ glUniform1f(maResources.m_3DMaterialShininessID, polygon.material.shininess);
+ CHECK_GL_ERROR();
+ }
}
for (size_t i = 0; i < verticesNum; i++)
{
@@ -942,26 +963,45 @@ void OpenGL3DRenderer::RenderPolygon3DObject()
void OpenGL3DRenderer::Set3DSenceInfo(sal_uInt32 nColor, bool twoSidesLighting)
{
m_Polygon3DInfo.material.twoSidesLighting = twoSidesLighting;
-
- m_LightsInfo.ambient = getColorAsVector(nColor);
-
- m_LightsInfo.lightNum = 0;
+ if (maResources.m_b330Support)
+ {
+ m_LightsInfo.ambient = getColorAsVector(nColor);
+ m_LightsInfo.lightNum = 0;
+ }
+ else
+ {
+ m_iLightNum = 0;
+ m_Ambient = getColorAsVector(nColor);;
+ }
SetLightInfo(true, 0xFFFFFF, glm::vec4(1.0, 1.0, 1.0, 0.0));
}
void OpenGL3DRenderer::SetLightInfo(bool lightOn, sal_uInt32 nColor, const glm::vec4& direction)
{
- if (m_LightsInfo.lightNum >= MAX_LIGHT_NUM)
- {
- return;
- }
-
if (lightOn)
{
- m_LightsInfo.light[m_LightsInfo.lightNum].lightColor = getColorAsVector(nColor);
- m_LightsInfo.light[m_LightsInfo.lightNum].positionWorldspace = direction;
- m_LightsInfo.light[m_LightsInfo.lightNum].lightPower = 1.0;
- m_LightsInfo.lightNum++;
+ if (maResources.m_b330Support)
+ {
+ if (m_LightsInfo.lightNum >= MAX_LIGHT_NUM)
+ {
+ return;
+ }
+ m_LightsInfo.light[m_LightsInfo.lightNum].lightColor = getColorAsVector(nColor);
+ m_LightsInfo.light[m_LightsInfo.lightNum].positionWorldspace = direction;
+ m_LightsInfo.light[m_LightsInfo.lightNum].lightPower = 1.0;
+ m_LightsInfo.lightNum++;
+ }
+ else
+ {
+ if (m_iLightNum >= MAX_LIGHT_NUM)
+ {
+ return;
+ }
+ m_LightColor[m_iLightNum] = getColorAsVector(nColor);
+ m_PositionWorldspace[m_iLightNum] = direction;
+ m_fLightPower[m_iLightNum] = 1.0;
+ m_iLightNum++;
+ }
}
}
@@ -1363,7 +1403,6 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
glUniform4fv(maResources.m_2DColorID, 1, &extrude3D.id[0]);
}
glDrawElements(GL_TRIANGLES, extrude3D.size[TOP_SURFACE], GL_UNSIGNED_SHORT, reinterpret_cast<GLvoid*>(extrude3D.startIndex[TOP_SURFACE]));
- RenderExtrudeFlatSurface(extrude3D, FLAT_BOTTOM_SURFACE);
}
void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo& extrude3D)
@@ -1427,12 +1466,26 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
}
else
{
- Update3DUniformBlock();
glUseProgram(maResources.m_3DProID);
glUniformMatrix4fv(maResources.m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
glUniformMatrix4fv(maResources.m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
+ if (maResources.m_b330Support)
+ {
+ //update ubo
+ Update3DUniformBlock();
+ CHECK_GL_ERROR();
+ }
+ else
+ {
+ //update light information
+ glUniform4fv(maResources.m_3DLightColorID, m_iLightNum, (GLfloat*)m_LightColor);
+ glUniform4fv(maResources.m_3DLightPosID, m_iLightNum, (GLfloat*)m_PositionWorldspace);
+ glUniform1fv(maResources.m_3DLightPowerID, m_iLightNum, m_fLightPower);
+ glUniform1i(maResources.m_3DLightNumID, m_iLightNum);
+ glUniform4fv(maResources.m_3DLightAmbientID, 1, &m_Ambient[0]);
+ CHECK_GL_ERROR();
+ }
}
- CHECK_GL_ERROR();
size_t extrude3DNum = m_Extrude3DList.size();
for (size_t i = 0; i < extrude3DNum; i++)
{
@@ -1472,10 +1525,23 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
extrude3DInfo.zScale *= m_fHeightWeight;
if(!mbPickingMode)
{
- glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
- glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &extrude3DInfo.material);
- CHECK_GL_ERROR();
- glBindBuffer(GL_UNIFORM_BUFFER, 0);
+ if (maResources.m_b330Support)
+ {
+ glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
+ glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &extrude3DInfo.material);
+ CHECK_GL_ERROR();
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+ }
+ else
+ {
+ //update meterial information
+ glUniform4fv(maResources.m_3DMaterialAmbientID, 1, &extrude3DInfo.material.ambient[0]);
+ glUniform4fv(maResources.m_3DMaterialDiffuseID, 1, &extrude3DInfo.material.diffuse[0]);
+ glUniform4fv(maResources.m_3DMaterialSpecularID, 1, &extrude3DInfo.material.specular[0]);
+ glUniform4fv(maResources.m_3DMaterialColorID, 1, &extrude3DInfo.material.materialColor[0]);
+ glUniform1i(maResources.m_3DMaterialTwoSidesID, extrude3DInfo.material.twoSidesLighting);
+ glUniform1f(maResources.m_3DMaterialShininessID, extrude3DInfo.material.shininess);
+ }
}
extrude3DInfo.reverse = 0;
if (extrude3DInfo.rounded)
@@ -1777,7 +1843,16 @@ void OpenGL3DRenderer::ProcessUnrenderedShape(bool bNewScene)
if(mbPickingMode)
RenderExtrude3DObject();
else
- RenderBatchBars(bNewScene);
+ {
+ if (maResources.m_b330Support)
+ {
+ RenderBatchBars(bNewScene);
+ }
+ else
+ {
+ RenderExtrude3DObject();
+ }
+ }
//render text
RenderTextShape();
// render screen text
commit 783372f383650fe3d26f4b02432921a206d99d35
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Jun 14 08:51:43 2014 -0700
add codes for compile the 3.0 shaders
Change-Id: Idc58635cc1604208317319bfa399a1574979a909
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index b24d45e..1e5df81 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -234,10 +234,12 @@ private:
void InitBatch3DUniformBlock();
void UpdateBatch3DUniformBlock();
void RenderBatchBars(bool bNewScene);
+ void CheckGLSLVersion();
private:
struct ShaderResources
{
+ bool m_b330Support;;
// 3DProID
GLint m_3DProID;
GLint m_3DProjectionID;
@@ -246,6 +248,18 @@ private:
GLint m_3DNormalMatrixID;
GLint m_3DVertexID;
GLint m_3DNormalID;
+ //300 verson;
+ GLint m_3DMaterialAmbientID;
+ GLint m_3DMaterialDiffuseID;
+ GLint m_3DMaterialSpecularID;
+ GLint m_3DMaterialColorID;
+ GLint m_3DMaterialTwoSidesID;
+ GLint m_3DMaterialShininessID;
+ GLint m_3DLightColorID;
+ GLint m_3DLightPosID;
+ GLint m_3DLightPowerID;
+ GLint m_3DLightNumID;
+ GLint m_3DLightAmbientID;
// TextProID
GLint m_TextProID;
@@ -380,6 +394,12 @@ private:
MaterialParameters m_Batchmaterial;
GLuint m_Batch3DUBOBuffer;
GLint m_Batch3DActualSizeLight;
+ //for 3.0 version
+ int m_iLightNum;
+ glm::vec4 m_Ambient;
+ glm::vec4 m_LightColor[MAX_LIGHT_NUM];
+ glm::vec4 m_PositionWorldspace[MAX_LIGHT_NUM];
+ float m_fLightPower[MAX_LIGHT_NUM];
};
}
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 287c98a..1799396 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -139,6 +139,7 @@ OpenGL3DRenderer::ShaderResources::ShaderResources()
, m_3DBatchVertexID(0)
, m_3DBatchNormalID(0)
, m_3DBatchColorID(0)
+ , m_b330Support(false)
{
}
@@ -151,16 +152,82 @@ OpenGL3DRenderer::ShaderResources::~ShaderResources()
glDeleteProgram(m_3DBatchProID);
}
+void OpenGL3DRenderer::CheckGLSLVersion()
+{
+ char version[256] = {0};
+ strcpy(version, (char *)glGetString(GL_SHADING_LANGUAGE_VERSION));
+ char *p = version;
+ int iVersion = 0;
+ //get the first point
+ while ((*p != '\0') && (*p != '.'))
+ {
+ iVersion = iVersion * 10 + ((*p) - 0x30);
+ p++;
+ }
+ if (iVersion < 3)
+ {
+ maResources.m_b330Support = false;
+ return;
+ }
+ if (iVersion > 3)
+ {
+ maResources.m_b330Support = true;
+ return;
+ }
+ p++;
+ iVersion = *p - 0x30;
+ if (iVersion >= 3)
+ {
+ maResources.m_b330Support = true;
+ return;
+ }
+ maResources.m_b330Support = false;
+}
+
void OpenGL3DRenderer::ShaderResources::LoadShaders()
{
- m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShader", "shape3DFragmentShader");
- m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
- m_3DViewID = glGetUniformLocation(m_3DProID, "V");
- m_3DModelID = glGetUniformLocation(m_3DProID, "M");
- m_3DNormalMatrixID = glGetUniformLocation(m_3DProID, "normalMatrix");
- m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
- m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
+ if (m_b330Support)
+ {
+ m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShader", "shape3DFragmentShader");
+ m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
+ m_3DViewID = glGetUniformLocation(m_3DProID, "V");
+ m_3DModelID = glGetUniformLocation(m_3DProID, "M");
+ m_3DNormalMatrixID = glGetUniformLocation(m_3DProID, "normalMatrix");
+ m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
+ m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
+
+ m_3DBatchProID = OpenGLHelper::LoadShaders("shape3DVertexShaderBatch", "shape3DFragmentShaderBatch");
+ m_3DBatchProjectionID = glGetUniformLocation(m_3DBatchProID, "P");
+ m_3DBatchViewID = glGetUniformLocation(m_3DBatchProID, "V");
+ m_3DBatchModelID = glGetAttribLocation(m_3DBatchProID, "M");
+ m_3DBatchNormalMatrixID = glGetAttribLocation(m_3DBatchProID, "normalMatrix");
+ m_3DBatchVertexID = glGetAttribLocation(m_3DBatchProID, "vertexPositionModelspace");
+ m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace");
+ m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor");
+ }
+ else
+ {
+ //use 300
+ m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShaderV300", "shape3DFragmentShaderV300");
+ m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
+ m_3DViewID = glGetUniformLocation(m_3DProID, "V");
+ m_3DModelID = glGetUniformLocation(m_3DProID, "M");
+ m_3DNormalMatrixID = glGetUniformLocation(m_3DProID, "normalMatrix");
+ m_3DMaterialAmbientID = glGetUniformLocation(m_3DProID, "materialAmbient");
+ m_3DMaterialDiffuseID = glGetUniformLocation(m_3DProID, "materialDiffuse");
+ m_3DMaterialSpecularID = glGetUniformLocation(m_3DProID, "materialSpecular");
+ m_3DMaterialColorID = glGetUniformLocation(m_3DProID, "materialColor");
+ m_3DMaterialTwoSidesID = glGetUniformLocation(m_3DProID, "twoSidesLighting");
+ m_3DMaterialShininessID = glGetUniformLocation(m_3DProID, "materialShininess");
+ m_3DLightColorID = glGetUniformLocation(m_3DProID, "lightColor");
+ m_3DLightPosID = glGetUniformLocation(m_3DProID, "lightPosWorldspace");
+ m_3DLightPowerID = glGetUniformLocation(m_3DProID, "lightPower");
+ m_3DLightNumID = glGetUniformLocation(m_3DProID, "lightNum");
+ m_3DLightAmbientID = glGetUniformLocation(m_3DProID, "lightAmbient");
+ m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
+ m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
+ }
m_TextProID = OpenGLHelper::LoadShaders("textVertexShader", "textFragmentShader");
m_TextMatrixID = glGetUniformLocation(m_TextProID, "MVP");
m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
@@ -177,14 +244,6 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor");
- m_3DBatchProID = OpenGLHelper::LoadShaders("shape3DVertexShaderBatch", "shape3DFragmentShaderBatch");
- m_3DBatchProjectionID = glGetUniformLocation(m_3DBatchProID, "P");
- m_3DBatchViewID = glGetUniformLocation(m_3DBatchProID, "V");
- m_3DBatchModelID = glGetAttribLocation(m_3DBatchProID, "M");
- m_3DBatchNormalMatrixID = glGetAttribLocation(m_3DBatchProID, "normalMatrix");
- m_3DBatchVertexID = glGetAttribLocation(m_3DBatchProID, "vertexPositionModelspace");
- m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace");
- m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor");
CHECK_GL_ERROR();
}
@@ -258,6 +317,7 @@ void OpenGL3DRenderer::init()
m_fViewAngle = 30.0f;
m_3DProjection = glm::perspective(m_fViewAngle, (float)m_iWidth / (float)m_iHeight, 0.01f, 6000.0f);
+ CheckGLSLVersion();
maResources.LoadShaders();
maPickingResources.LoadShaders();
@@ -280,9 +340,12 @@ void OpenGL3DRenderer::init()
m_Extrude3DInfo.rounded = false;
CHECK_GL_ERROR();
- Init3DUniformBlock();
- InitBatch3DUniformBlock();
-
+ if (maResources.m_b330Support)
+ {
+ Init3DUniformBlock();
+ InitBatch3DUniformBlock();
+ }
+ CHECK_GL_ERROR();
glViewport(0, 0, m_iWidth, m_iHeight);
Set3DSenceInfo(0xFFFFFF, true);
}
commit 1d05b6a490867f3dcdb8d4bf0aed3162af9cf1ff
Author: weigao <weigao at multicorewareinc.com>
Date: Sat Jun 14 08:00:02 2014 -0700
add shaders for 3.0 glsl version
Change-Id: I52dd49132a9b625e8be51b4d5feb7e567ffa0a6e
diff --git a/chart2/Package_opengl.mk b/chart2/Package_opengl.mk
index d8f9fa7..3d68a93 100644
--- a/chart2/Package_opengl.mk
+++ b/chart2/Package_opengl.mk
@@ -30,6 +30,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg
renderTextureFragmentShader.glsl \
shape3DFragmentShaderBatch.glsl \
shape3DVertexShaderBatch.glsl \
+ shape3DFragmentShaderV300.glsl \
+ shape3DVertexShaderV300.glsl \
))
# vim: set noet sw=4 ts=4:
diff --git a/chart2/opengl/shape3DFragmentShaderV300.glsl b/chart2/opengl/shape3DFragmentShaderV300.glsl
new file mode 100644
index 0000000..31a32e0
--- /dev/null
+++ b/chart2/opengl/shape3DFragmentShaderV300.glsl
@@ -0,0 +1,87 @@
+/* -*- 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/.
+ */
+#define MAX_LIGHT_NUM 8
+
+varying vec3 positionWorldspace;
+varying vec3 normalCameraspace;
+
+uniform mat4 V;
+uniform vec4 materialAmbient;
+uniform vec4 materialDiffuse;
+uniform vec4 materialSpecular;
+uniform vec4 materialColor;
+uniform int twoSidesLighting;
+uniform float materialShininess;
+uniform vec4 lightColor[MAX_LIGHT_NUM];
+uniform vec4 lightPosWorldspace[MAX_LIGHT_NUM];
+uniform float lightPower[MAX_LIGHT_NUM];
+uniform int lightNum;
+uniform vec4 lightAmbient;
+
+void main()
+{
+ vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f);
+
+ vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz;
+
+ vec3 MaterialDiffuseColor = materialColor.rgb;
+
+ vec3 normalDirectionCameraspace = normalCameraspace;
+ vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace);
+ float attenuation = 1.0;
+ int i = 0;
+ vec3 lightDirectionCameraspace;
+ vec3 vertexToLightSource;
+
+ vec3 totalAmbient = lightAmbient.rgb *
+ MaterialDiffuseColor *
+ materialAmbient.rgb
+ * 5.0;
+
+ if ((twoSidesLighting == 1) && (!gl_FrontFacing))
+ {
+ normalDirectionCameraspace = -normalDirectionCameraspace;
+ }
+ for (i = 0; i < lightNum; i++)
+ {
+ float LightPower = lightPower[i];
+ lightDirectionCameraspace = normalize((V * lightPosWorldspace[i]).xyz);
+
+ float cosTheta = clamp(dot(normalDirectionCameraspace,lightDirectionCameraspace), 0,1);
+ vec3 lightDiffuse = LightPower *
+ attenuation *
+ lightColor[i].rgb *
+ MaterialDiffuseColor *
+ materialDiffuse.rgb *
+ cosTheta;
+
+ vec3 specularReflection;
+ if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0)
+ {
+ specularReflection = vec3(0.0, 0.0, 0.0);
+ }
+ else
+ {
+ vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace);
+ float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1);
+ specularReflection = attenuation *
+ LightPower *
+ lightColor[i].rgb *
+ materialSpecular.rgb *
+ MaterialDiffuseColor *
+ pow(max(0.0, cosAlpha), materialShininess);
+ }
+ colorTotal += lightDiffuse + specularReflection;
+
+ }
+ colorTotal += totalAmbient;
+ gl_FragColor = vec4(colorTotal, 1.0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/opengl/shape3DVertexShaderV300.glsl b/chart2/opengl/shape3DVertexShaderV300.glsl
new file mode 100644
index 0000000..6737004
--- /dev/null
+++ b/chart2/opengl/shape3DVertexShaderV300.glsl
@@ -0,0 +1,29 @@
+/* -*- 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 vec3 vertexPositionModelspace;
+attribute vec3 vertexNormalModelspace;
+
+varying vec3 positionWorldspace;
+varying vec3 normalCameraspace;
+
+uniform mat4 P;
+uniform mat4 M;
+uniform mat4 V;
+uniform mat3 normalMatrix;
+
+void main()
+{
+ gl_Position = P * V * M * vec4(vertexPositionModelspace,1);
+
+ positionWorldspace = (M * vec4(vertexPositionModelspace,1)).xyz;
+
+ normalCameraspace = normalize(mat3(V) * normalMatrix * vertexNormalModelspace);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 0bed429ef5a44137ad3c82b3b70a2617c7e741c0
Author: weigao <weigao at multicorewareinc.com>
Date: Mon Jun 16 23:40:36 2014 -0700
modify the mouse drag function
Change-Id: I9639b2a29522ba0765f4442c2f78de56388fe754
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 2fd8181..a4e1901 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -414,19 +414,19 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
pScreenText->render();
}
-void GL3DBarChart::mouseDragMove(const Point& , const Point& , sal_uInt16 nButtons)
+void GL3DBarChart::mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 nButtons)
{
if(mbBlockUserInput)
return;
mbBlockUserInput = true;
-
- if(nButtons == MOUSE_RIGHT)
+ long direction = rEndPos.X() - rStartPos.X();
+ if(direction < 0)
{
mnCornerId = (mnCornerId + 1) % 4;
moveToCorner();
}
- else if(nButtons == MOUSE_LEFT)
+ else if(direction > 0)
{
mnCornerId = mnCornerId - 1;
if(mnCornerId < 0)
@@ -437,33 +437,33 @@ void GL3DBarChart::mouseDragMove(const Point& , const Point& , sal_uInt16 nButto
glm::vec3 GL3DBarChart::getCornerPosition(sal_Int8 nId)
{
+ float pi = 3.1415926;
switch(nId)
{
case 0:
{
- return glm::vec3(-30, -30, DEFAULT_CAMERA_HEIGHT);
+ return glm::vec3(mnMaxX / 2 - mnDistance * sin(pi / 4), mnMaxY / 2 - mnDistance * cos(pi / 4), DEFAULT_CAMERA_HEIGHT * 2);
}
break;
case 1:
{
- return glm::vec3(mnMaxX, -30, DEFAULT_CAMERA_HEIGHT);
+ return glm::vec3(mnMaxX / 2 + mnDistance * sin(pi / 4), mnMaxY / 2 - mnDistance * cos(pi / 4), DEFAULT_CAMERA_HEIGHT * 2);
}
break;
case 2:
{
- return glm::vec3(mnMaxX, mnMaxY, DEFAULT_CAMERA_HEIGHT);
+ return glm::vec3(mnMaxX / 2 + mnDistance * sin(pi / 4), mnMaxY / 2 + mnDistance * cos(pi / 4), DEFAULT_CAMERA_HEIGHT * 2);
}
break;
case 3:
{
- return glm::vec3(-30, mnMaxY, DEFAULT_CAMERA_HEIGHT);
+ return glm::vec3(mnMaxX / 2 - mnDistance * sin(pi / 4), mnMaxY / 2 + mnDistance * cos(pi / 4), DEFAULT_CAMERA_HEIGHT * 2);
}
break;
default:
assert(false);
}
-
- return glm::vec3(-30, -30, DEFAULT_CAMERA_HEIGHT);
+ return maDefaultCameraPosition;
}
void GL3DBarChart::moveToCorner()
commit f1c79fc1707bec384c55f7f493962beffda79277
Author: weigao <weigao at multicorewareinc.com>
Date: Mon Jun 16 23:33:03 2014 -0700
add move to default process
Change-Id: I8d562b3e2d1bb83a6e07ed089a3006a109beeece
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index e0689a8..2fd8181 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -355,24 +355,19 @@ void GL3DBarChart::moveToDefault()
glm::vec3 maTargetDirection = maDefaultCameraDirection;
maStepDirection = (maTargetDirection - maCameraDirection)/((float)mnStepsTotal);
- while((mnStep < mnStepsTotal) && mbBlockUserInput)
- {
- ++mnStep;
- maCameraPosition += maStep;
- mpCamera->setPosition(maCameraPosition);
- maCameraDirection += maStepDirection;
- mpCamera->setDirection(maCameraDirection);
- render();
- }
- maShapes.pop_back();
- mbBlockUserInput = false;
- mnStep = 0;
+ maTimer.SetTimeout(TIMEOUT);
+ maTimer.SetTimeoutHdl(LINK(this, GL3DBarChart, MoveToBar));
+ maTimer.Start();
}
void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
{
if(mbBlockUserInput)
return;
+ if (nButtons == MOUSE_RIGHT)
+ {
+ moveToDefault();
+ }
if(nButtons != MOUSE_LEFT)
return;
commit 1877c8ccf0a6aafdcbadc62740656e11af06cf61
Author: weigao <weigao at multicorewareinc.com>
Date: Mon Jun 16 23:21:04 2014 -0700
modify the click view angle
Change-Id: I8717745d2f503f8ad3c21673a07aed867b5681f9
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index 9f51196..e0689a8 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -398,14 +398,15 @@ void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
render();
glm::vec3 maTargetPosition = rBarInfo.maPos;
- maTargetPosition.z += 45;
- maStep = (maTargetPosition - maCameraPosition)/100.0f;
+ maTargetPosition.z += 240;
+ maTargetPosition.y += BAR_SIZE_Y / 2.0f;
+ maStep = (maTargetPosition - maCameraPosition)/((float)mnStepsTotal);
glm::vec3 maTargetDirection = rBarInfo.maPos;
maTargetDirection.x += BAR_SIZE_X / 2.0f;
maTargetDirection.y += BAR_SIZE_Y / 2.0f;
- maStepDirection = (maTargetDirection - maCameraDirection)/100.f;
+ maStepDirection = (maTargetDirection - maCameraDirection)/((float)mnStepsTotal);
maTimer.SetTimeout(TIMEOUT);
maTimer.SetTimeoutHdl(LINK(this, GL3DBarChart, MoveToBar));
commit fc42841c516b36feb13fedf8e15864f41b6aa65d
Author: weigao <weigao at multicorewareinc.com>
Date: Mon Jun 16 23:08:00 2014 -0700
modify the default view angle
Change-Id: Ic7c901108a290a9d9c5a8564b6eefa7ed32a9e1f
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index f2ec238..9f51196 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -36,7 +36,8 @@ GL3DBarChart::GL3DBarChart(
mnStepsTotal(0),
mnCornerId(0),
mbBlockUserInput(false),
- mbNeedsNewRender(true)
+ mbNeedsNewRender(true),
+ mbCameraInit(false)
{
Size aSize = mrWindow.GetSizePixel();
mpRenderer->SetSize(aSize);
@@ -61,9 +62,9 @@ GL3DBarChart::~GL3DBarChart()
namespace {
-const float TEXT_HEIGHT = 15.0f;
-const float DEFAULT_CAMERA_HEIGHT = 500.0f;
-const size_t STEPS = 100;
+const float TEXT_HEIGHT = 10.0f;
+float DEFAULT_CAMERA_HEIGHT = 500.0f;
+const size_t STEPS = 200;
const sal_uLong TIMEOUT = 5;
const sal_uInt32 ID_STEP = 10;
@@ -266,12 +267,28 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer
mnMaxX = nMaxPointCount * (BAR_SIZE_X + BAR_DISTANCE_X) + 40;
mnMaxY = nSeriesIndex * (BAR_SIZE_Y + BAR_DISTANCE_Y) + 40;
-
- maCameraPosition = glm::vec3(-30, -30, DEFAULT_CAMERA_HEIGHT);
- mpCamera->setPosition(maCameraPosition);
- maCameraDirection = glm::vec3(mnMaxX/2, mnMaxY/2, 0);
- mpCamera->setDirection(maCameraDirection);
-
+ if (!mbCameraInit)
+ {
+ mnDistance = sqrt(mnMaxX * mnMaxX + mnMaxY * mnMaxY + DEFAULT_CAMERA_HEIGHT * DEFAULT_CAMERA_HEIGHT);
+ maDefaultCameraDirection = glm::vec3(mnMaxX * 0.4, mnMaxY * 0.35, 0);
+ maDefaultCameraPosition = glm::vec3(maDefaultCameraDirection.x, maDefaultCameraDirection.y - mnDistance, DEFAULT_CAMERA_HEIGHT * 2);
+ mnCornerId = 0;
+ mbCameraInit = true;
+ float pi = 3.1415926f;
+ float angleX = -pi / 6.5f;
+ float angleZ = -pi / 8.0f;
+ glm::mat4 maDefaultRotateMatrix = glm::eulerAngleYXZ(0.0f, angleX, angleZ);
+ maDefaultCameraPosition = glm::vec3(maDefaultRotateMatrix * glm::vec4(maDefaultCameraPosition, 1.0f));
+ maCameraPosition = maDefaultCameraPosition;
+ maCameraDirection = maDefaultCameraDirection;
+ mpCamera->setPosition(maCameraPosition);
+ mpCamera->setDirection(maCameraDirection);
+ }
+ else
+ {
+ mpCamera->setPosition(maCameraPosition);
+ mpCamera->setDirection(maCameraDirection);
+ }
mbNeedsNewRender = true;
}
@@ -328,6 +345,30 @@ public:
}
+void GL3DBarChart::moveToDefault()
+{
+ mnStepsTotal = STEPS;
+ mnStep = 0;
+ mbBlockUserInput = true;
+ glm::vec3 maTargetPosition = maDefaultCameraPosition;
+ maStep = (maTargetPosition - maCameraPosition)/((float)mnStepsTotal);
+
+ glm::vec3 maTargetDirection = maDefaultCameraDirection;
+ maStepDirection = (maTargetDirection - maCameraDirection)/((float)mnStepsTotal);
+ while((mnStep < mnStepsTotal) && mbBlockUserInput)
+ {
+ ++mnStep;
+ maCameraPosition += maStep;
+ mpCamera->setPosition(maCameraPosition);
+ maCameraDirection += maStepDirection;
+ mpCamera->setDirection(maCameraDirection);
+ render();
+ }
+ maShapes.pop_back();
+ mbBlockUserInput = false;
+ mnStep = 0;
+}
+
void GL3DBarChart::clickedAt(const Point& rPos, sal_uInt16 nButtons)
{
if(mbBlockUserInput)
diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx
index 0566904..d3426a3 100644
--- a/chart2/source/view/inc/GL3DBarChart.hxx
+++ b/chart2/source/view/inc/GL3DBarChart.hxx
@@ -58,6 +58,7 @@ public:
private:
void moveToCorner();
+ void moveToDefault();
glm::vec3 getCornerPosition(sal_Int8 nCornerId);
DECL_LINK(MoveCamera, void*);
@@ -77,6 +78,9 @@ private:
glm::vec3 maCameraPosition;
glm::vec3 maCameraDirection;
+ glm::vec3 maDefaultCameraPosition;
+ glm::vec3 maDefaultCameraDirection;
+
Timer maTimer;
glm::vec3 maStep;
glm::vec3 maStepDirection;
@@ -84,6 +88,7 @@ private:
size_t mnStepsTotal;
float mnMaxX;
float mnMaxY;
+ float mnDistance;
/**
* 0 = corner at (0,0,0);
* numbering counter clockwise
@@ -107,6 +112,7 @@ private:
std::map<sal_uInt32, const BarInformation> maBarMap;
bool mbBlockUserInput;
bool mbNeedsNewRender;
+ bool mbCameraInit;
};
}
commit c90b597698d7a41d69daadbaeef22440dde72d7a
Author: weigao <weigao at multicorewareinc.com>
Date: Mon Jun 16 22:58:26 2014 -0700
modify the perspective view angle to 30
Change-Id: I07b39f8b372368f82137feec3a6d12921fc1ec9f
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index f82dbaa..287c98a 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -255,7 +255,7 @@ void OpenGL3DRenderer::init()
glBufferData(GL_ARRAY_BUFFER, sizeof(boundBoxNormal), boundBoxNormal, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
- m_fViewAngle = 60.0f;
+ m_fViewAngle = 30.0f;
m_3DProjection = glm::perspective(m_fViewAngle, (float)m_iWidth / (float)m_iHeight, 0.01f, 6000.0f);
maResources.LoadShaders();
More information about the Libreoffice-commits
mailing list