diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-05-15 11:22:02 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-05-15 14:01:10 +0200 |
commit | 42edee1ee1c993715a41b483eb4b67fb75a844e3 (patch) | |
tree | 941bfe7077525583d6d0ec5956eab061ba91ed38 | |
parent | try a better idea (diff) | |
download | core-42edee1ee1c993715a41b483eb4b67fb75a844e3.tar.gz core-42edee1ee1c993715a41b483eb4b67fb75a844e3.zip |
implement new struct and shaders for picking
Change-Id: Ib3e08d69c031aa3130b10c0745119cf5935d86db
-rw-r--r-- | chart2/Package_opengl.mk | 2 | ||||
-rw-r--r-- | chart2/opengl/pickingFragmentShader.glsl | 17 | ||||
-rw-r--r-- | chart2/opengl/pickingVertexShader.glsl | 21 | ||||
-rw-r--r-- | chart2/source/view/inc/GL3DRenderer.hxx | 20 | ||||
-rw-r--r-- | chart2/source/view/main/GL3DRenderer.cxx | 11 |
5 files changed, 71 insertions, 0 deletions
diff --git a/chart2/Package_opengl.mk b/chart2/Package_opengl.mk index d96a1cef2b7d..cb8c45670870 100644 --- a/chart2/Package_opengl.mk +++ b/chart2/Package_opengl.mk @@ -16,6 +16,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg commonVertexShader.glsl \ debugFragmentShader.glsl \ debugVertexShader.glsl \ + pickingVertexShader.glsl \ + pickingFragmentShader.glsl \ symbolFragmentShader.glsl \ symbolVertexShader.glsl \ textFragmentShader.glsl \ diff --git a/chart2/opengl/pickingFragmentShader.glsl b/chart2/opengl/pickingFragmentShader.glsl new file mode 100644 index 000000000000..805789e731ed --- /dev/null +++ b/chart2/opengl/pickingFragmentShader.glsl @@ -0,0 +1,17 @@ +/* -*- 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/. + */ + +varying vec4 fragmentColor; + +void main() +{ + gl_FragColor = fragmentColor; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/opengl/pickingVertexShader.glsl b/chart2/opengl/pickingVertexShader.glsl new file mode 100644 index 000000000000..f32e3fd38a91 --- /dev/null +++ b/chart2/opengl/pickingVertexShader.glsl @@ -0,0 +1,21 @@ +/* -*- 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 vPosition; +uniform mat4 MVP; +uniform vec4 vColor; +varying vec4 fragmentColor; + +void main() +{ + gl_Position = MVP * vec4(vPosition, 1); + fragmentColor = vColor; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx index 6bfc38373d46..2154f7d9809a 100644 --- a/chart2/source/view/inc/GL3DRenderer.hxx +++ b/chart2/source/view/inc/GL3DRenderer.hxx @@ -255,7 +255,27 @@ private: void LoadShaders(); }; + struct PickingShaderResources + { + // CommonProID + GLint m_CommonProID; + GLint m_2DVertexID; + GLint m_2DColorID; + GLint m_MatrixID; + + PickingShaderResources(): + m_CommonProID(0) {} + + ~PickingShaderResources() + { + glDeleteProgram(m_CommonProID); + } + + void LoadShaders(); + }; + ShaderResources maResources; + PickingShaderResources maPickingResources; // Projection matrix : default 45 degree Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units glm::mat4 m_Projection; diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx index 6ef1fa78b65f..cbfebedb6e76 100644 --- a/chart2/source/view/main/GL3DRenderer.cxx +++ b/chart2/source/view/main/GL3DRenderer.cxx @@ -131,6 +131,14 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders() CHECK_GL_ERROR(); } +void OpenGL3DRenderer::PickingShaderResources::LoadShaders() +{ + m_CommonProID = OpenGLHelper::LoadShaders("pickingVertexShader", "pickingFragmentShader"); + m_MatrixID = glGetUniformLocation(m_CommonProID, "MVP"); + m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition"); + m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor"); +} + void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up) { m_CameraInfo.cameraPos = pos; @@ -212,7 +220,10 @@ void OpenGL3DRenderer::init() m_fViewAngle = 60.0f; m_3DProjection = glm::perspective(m_fViewAngle, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f); + maResources.LoadShaders(); + maPickingResources.LoadShaders(); + glGenBuffers(1, &m_TextTexCoordBuf); glBindBuffer(GL_ARRAY_BUFFER, m_TextTexCoordBuf); glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW); |