1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include "GL3DRenderer.hxx"
14 #include <vcl/opengl/OpenGLHelper.hxx>
15 #include <vcl/font.hxx>
16 #include <vcl/virdev.hxx>
18 #include <com/sun/star/awt/Size.hpp>
20 #include <StaticGeometry.h>
21 #include "glm/gtc/matrix_inverse.hpp"
22 #include <boost/checked_delete.hpp>
23 #include <boost/scoped_array.hpp>
27 using namespace com::sun::star
;
35 const int CORNER_DIVION_Y
= 20;
36 const int CORNER_DIVION_Z
= 20;
38 GLfloat texCoords
[] = {
45 glm::vec4
getColorAsVector(sal_uInt32 nColor
)
47 return glm::vec4(((nColor
& 0x00FF0000) >> 16) / 255.0f
,
48 ((nColor
& 0x0000FF00) >> 8) / 255.0f
,
49 (nColor
& 0x000000FF) / 255.0f
,
50 (0xFF - (nColor
& 0xFF000000)/255.0));
55 TextureArrayInfo::TextureArrayInfo():
58 textureArrayHeight(0),
63 OpenGL3DRenderer::OpenGL3DRenderer():
67 , m_3DActualSizeLight(0)
75 , m_TextTexCoordBuf(0)
76 , m_TextTexCoordBufBatch(0)
78 , m_RenderVertexBuf(0)
79 , m_RenderTexCoordBuf(0)
81 , mbPickingMode(false)
83 , mnPickingRboDepth(0)
84 , mnPickingRboColor(0)
85 , m_BatchModelMatrixBuf(0)
86 , m_BatchNormalMatrixBuf(0)
88 , m_Batch3DUBOBuffer(0)
89 , m_Batch3DActualSizeLight(0)
91 , m_bHighLighting(false)
93 , m_fScrollSpeed(0.0f
)
94 , m_fScrollDistance(0.0f
)
97 , m_fCurDistance(0.0f
)
98 , m_ScrollMoveMatrix(glm::mat4(1.0))
99 , m_bUndrawFlag(false)
100 , m_matDiff(glm::mat4(0.0))
102 m_Polygon3DInfo
.lineOnly
= false;
103 m_Polygon3DInfo
.twoSidesLighting
= false;
104 m_Polygon3DInfo
.vertices
= NULL
;
105 m_Polygon3DInfo
.normals
= NULL
;
106 m_Polygon3DInfo
.lineWidth
= 0.001f
;
108 m_Extrude3DInfo
.twoSidesLighting
= false;
110 m_RoundBarMesh
.iMeshSizes
= 0;
113 OpenGL3DRenderer::~OpenGL3DRenderer()
117 glDeleteBuffers(1, &m_CubeVertexBuf
);
118 glDeleteBuffers(1, &m_CubeNormalBuf
);
119 glDeleteBuffers(1, &m_CubeElementBuf
);
120 glDeleteBuffers(1, &m_BoundBox
);
121 glDeleteBuffers(1, &m_BoundBoxNormal
);
122 glDeleteBuffers(1, &m_TextTexCoordBuf
);
123 glDeleteBuffers(1, &m_RenderTexCoordBuf
);
124 glDeleteBuffers(1, &m_RenderVertexBuf
);
125 glDeleteBuffers(1, &m_3DUBOBuffer
);
126 glDeleteBuffers(1, &m_VertexBuffer
);
127 glDeleteBuffers(1, &m_NormalBuffer
);
128 glDeleteBuffers(1, &m_Batch3DUBOBuffer
);
129 glDeleteBuffers(1, &m_3DUBOBuffer
);
130 glDeleteBuffers(1, &m_3DUBOBuffer
);
131 glDeleteBuffers(1, &m_TextTexCoordBufBatch
);
133 glDeleteFramebuffers(1, &mnPickingFbo
);
134 glDeleteRenderbuffers(1, &mnPickingRboDepth
);
135 glDeleteRenderbuffers(1, &mnPickingRboColor
);
137 for (size_t i
= 0; i
< m_TextInfoBatch
.texture
.size(); i
++)
139 glDeleteTextures(1, &m_TextInfoBatch
.texture
[i
].textureID
);
141 m_TextInfoBatch
.texture
.clear();
145 OpenGL3DRenderer::ShaderResources::ShaderResources()
146 : m_b330Support(false)
147 , m_bScrollFlag(false)
149 , m_3DProjectionID(0)
152 , m_3DNormalMatrixID(0)
158 , m_3DMaterialAmbientID(0)
159 , m_3DMaterialDiffuseID(0)
160 , m_3DMaterialSpecularID(0)
161 , m_3DMaterialColorID(0)
162 , m_3DMaterialTwoSidesID(0)
163 , m_3DMaterialShininessID(0)
164 , m_3DLightColorID(0)
166 , m_3DLightPowerID(0)
168 , m_3DLightAmbientID(0)
172 , m_TextTexCoordID(0)
174 , m_ScreenTextProID(0)
175 , m_ScreenTextVertexID(0)
176 , m_ScreenTextTexCoordID(0)
177 , m_ScreenTextTexID(0)
178 , m_ScreenTextColorID(0)
184 , m_3DBatchProjectionID(0)
186 , m_3DBatchModelID(0)
187 , m_3DBatchNormalMatrixID(0)
188 , m_3DBatchVertexID(0)
189 , m_3DBatchNormalID(0)
190 , m_3DBatchColorID(0)
191 , m_3DBatchTransMatrixID(0)
192 , m_3DBatchMinCoordXID(0)
193 , m_3DBatchMaxCoordXID(0)
194 , m_3DBatchUndrawID(0)
195 , mbTexBatchSupport(false)
196 , m_BatchTextProID(0)
197 , m_BatchTextMatrixID(0)
198 , m_BatchTextVertexID(0)
199 , m_BatchTextTexCoordID(0)
200 , m_BatchTextTexID(0)
204 OpenGL3DRenderer::ShaderResources::~ShaderResources()
206 glDeleteProgram(m_CommonProID
);
207 glDeleteProgram(m_TextProID
);
208 glDeleteProgram(m_ScreenTextProID
);
209 glDeleteProgram(m_3DProID
);
210 glDeleteProgram(m_3DBatchProID
);
211 glDeleteProgram(m_BatchTextProID
);
214 void OpenGL3DRenderer::CheckGLSLVersion()
216 maResources
.m_b330Support
= GLEW_VERSION_3_3
;
219 void OpenGL3DRenderer::ShaderResources::LoadShaders()
224 m_3DProID
= OpenGLHelper::LoadShaders("shape3DVertexShader", "shape3DFragmentShader");
225 m_3DProjectionID
= glGetUniformLocation(m_3DProID
, "P");
226 m_3DViewID
= glGetUniformLocation(m_3DProID
, "V");
227 m_3DModelID
= glGetUniformLocation(m_3DProID
, "M");
228 m_3DNormalMatrixID
= glGetUniformLocation(m_3DProID
, "normalMatrix");
229 m_3DVertexID
= glGetAttribLocation(m_3DProID
, "vertexPositionModelspace");
230 m_3DNormalID
= glGetAttribLocation(m_3DProID
, "vertexNormalModelspace");
234 m_3DBatchProID
= OpenGLHelper::LoadShaders("shape3DVertexShaderBatchScroll", "shape3DFragmentShaderBatchScroll");
235 m_3DBatchTransMatrixID
= glGetUniformLocation(m_3DBatchProID
, "transMatrix");
236 m_3DBatchMinCoordXID
= glGetUniformLocation(m_3DBatchProID
, "minCoordX");
237 m_3DBatchMaxCoordXID
= glGetUniformLocation(m_3DBatchProID
, "maxCoordX");
238 m_3DBatchUndrawID
= glGetUniformLocation(m_3DBatchProID
, "undraw");
241 m_3DBatchProID
= OpenGLHelper::LoadShaders("shape3DVertexShaderBatch", "shape3DFragmentShaderBatch");
244 m_3DBatchProjectionID
= glGetUniformLocation(m_3DBatchProID
, "P");
245 m_3DBatchViewID
= glGetUniformLocation(m_3DBatchProID
, "V");
246 m_3DBatchModelID
= glGetAttribLocation(m_3DBatchProID
, "M");
247 m_3DBatchNormalMatrixID
= glGetAttribLocation(m_3DBatchProID
, "normalMatrix");
248 m_3DBatchVertexID
= glGetAttribLocation(m_3DBatchProID
, "vertexPositionModelspace");
249 m_3DBatchNormalID
= glGetAttribLocation(m_3DBatchProID
, "vertexNormalModelspace");
250 m_3DBatchColorID
= glGetAttribLocation(m_3DBatchProID
, "barColor");
252 //check whether the texture array is support
253 mbTexBatchSupport
= GLEW_EXT_texture_array
;
256 if (mbTexBatchSupport
)
258 m_BatchTextProID
= OpenGLHelper::LoadShaders("textVertexShaderBatch", "textFragmentShaderBatch");
259 m_BatchTextMatrixID
= glGetUniformLocation(m_BatchTextProID
, "MVP");
260 m_BatchTextTexID
= glGetUniformLocation(m_BatchTextProID
, "texArray");
261 m_BatchTextVertexID
= glGetAttribLocation(m_BatchTextProID
, "vPosition");
262 m_BatchTextTexCoordID
= glGetAttribLocation(m_BatchTextProID
, "texCoord");
264 mbTexBatchSupport
= m_BatchTextProID
!= 0;
271 m_3DProID
= OpenGLHelper::LoadShaders("shape3DVertexShaderV300", "shape3DFragmentShaderV300");
272 m_3DProjectionID
= glGetUniformLocation(m_3DProID
, "P");
273 m_3DViewID
= glGetUniformLocation(m_3DProID
, "V");
274 m_3DModelID
= glGetUniformLocation(m_3DProID
, "M");
275 m_3DNormalMatrixID
= glGetUniformLocation(m_3DProID
, "normalMatrix");
276 m_3DMaterialAmbientID
= glGetUniformLocation(m_3DProID
, "materialAmbient");
277 m_3DMaterialDiffuseID
= glGetUniformLocation(m_3DProID
, "materialDiffuse");
278 m_3DMaterialSpecularID
= glGetUniformLocation(m_3DProID
, "materialSpecular");
279 m_3DMaterialColorID
= glGetUniformLocation(m_3DProID
, "materialColor");
280 m_3DMaterialTwoSidesID
= glGetUniformLocation(m_3DProID
, "twoSidesLighting");
281 m_3DMaterialShininessID
= glGetUniformLocation(m_3DProID
, "materialShininess");
282 m_3DLightColorID
= glGetUniformLocation(m_3DProID
, "lightColor");
283 m_3DLightPosID
= glGetUniformLocation(m_3DProID
, "lightPosWorldspace");
284 m_3DLightPowerID
= glGetUniformLocation(m_3DProID
, "lightPower");
285 m_3DLightNumID
= glGetUniformLocation(m_3DProID
, "lightNum");
286 m_3DLightAmbientID
= glGetUniformLocation(m_3DProID
, "lightAmbient");
287 m_3DMinCoordXID
= glGetUniformLocation(m_3DProID
, "minCoordX");
288 m_3DMaxCoordXID
= glGetUniformLocation(m_3DProID
, "maxCoordX");
289 m_3DUndrawID
= glGetUniformLocation(m_3DProID
, "undraw");
290 m_3DVertexID
= glGetAttribLocation(m_3DProID
, "vertexPositionModelspace");
291 m_3DNormalID
= glGetAttribLocation(m_3DProID
, "vertexNormalModelspace");
294 if (!mbTexBatchSupport
)
296 m_TextProID
= OpenGLHelper::LoadShaders("textVertexShader", "textFragmentShader");
297 m_TextMatrixID
= glGetUniformLocation(m_TextProID
, "MVP");
298 m_TextVertexID
= glGetAttribLocation(m_TextProID
, "vPosition");
299 m_TextTexCoordID
= glGetAttribLocation(m_TextProID
, "texCoord");
300 m_TextTexID
= glGetUniformLocation(m_TextProID
, "TextTex");
304 m_ScreenTextProID
= OpenGLHelper::LoadShaders("screenTextVertexShader", "screenTextFragmentShader");
305 m_ScreenTextVertexID
= glGetAttribLocation(m_ScreenTextProID
, "vPosition");
306 m_ScreenTextTexCoordID
= glGetAttribLocation(m_ScreenTextProID
, "texCoord");
307 m_ScreenTextTexID
= glGetUniformLocation(m_ScreenTextProID
, "TextTex");
308 m_ScreenTextColorID
= glGetUniformLocation(m_ScreenTextProID
, "textColor");
311 m_CommonProID
= OpenGLHelper::LoadShaders("commonVertexShader", "commonFragmentShader");
312 m_MatrixID
= glGetUniformLocation(m_CommonProID
, "MVP");
313 m_2DColorID
= glGetUniformLocation(m_CommonProID
, "vColor");
314 m_2DVertexID
= glGetAttribLocation(m_CommonProID
, "vPosition");
319 OpenGL3DRenderer::PickingShaderResources::PickingShaderResources()
330 OpenGL3DRenderer::PickingShaderResources::~PickingShaderResources()
332 glDeleteProgram(m_CommonProID
);
335 void OpenGL3DRenderer::PickingShaderResources::LoadShaders()
337 m_CommonProID
= OpenGLHelper::LoadShaders("pickingVertexShader", "pickingFragmentShader");
338 m_MatrixID
= glGetUniformLocation(m_CommonProID
, "MVP");
339 m_2DVertexID
= glGetAttribLocation(m_CommonProID
, "vPosition");
340 m_2DColorID
= glGetUniformLocation(m_CommonProID
, "vColor");
341 m_ModelID
= glGetUniformLocation(m_CommonProID
, "M");
342 m_MinCoordXID
= glGetUniformLocation(m_CommonProID
, "minCoordX");
343 m_MaxCoordXID
= glGetUniformLocation(m_CommonProID
, "maxCoordX");
346 void OpenGL3DRenderer::SetCameraInfo(const glm::vec3
& pos
, const glm::vec3
& direction
, const glm::vec3
& up
)
348 m_CameraInfo
.cameraPos
= pos
;
349 m_CameraInfo
.cameraOrg
= direction
;
350 m_CameraInfo
.cameraUp
= up
;
353 void OpenGL3DRenderer::init()
356 glEnable(GL_CULL_FACE
);
360 #if !defined(ANDROID) && !defined(IOS)
361 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
365 glEnable(GL_DEPTH_TEST
);
366 // Accept fragment if it closer to the camera than the former one
368 glDepthFunc(GL_LESS
);
370 glEnable(GL_LINE_SMOOTH
);
372 glHint(GL_LINE_SMOOTH_HINT
, GL_NICEST
);
376 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
379 glEnable(GL_MULTISAMPLE
);
385 glGenBuffers(1, &m_CubeVertexBuf
);
386 glGenBuffers(1, &m_CubeNormalBuf
);
387 glGenBuffers(1, &m_CubeElementBuf
);
388 glGenBuffers(1, &m_VertexBuffer
);
389 glGenBuffers(1, &m_NormalBuffer
);
390 glGenBuffers(1, &m_BatchModelMatrixBuf
);
391 glGenBuffers(1, &m_BatchNormalMatrixBuf
);
392 glGenBuffers(1, &m_BatchColorBuf
);
393 glGenBuffers(1, &m_TextTexCoordBufBatch
);
394 glGenBuffers(1, &m_BoundBox
);
395 glBindBuffer(GL_ARRAY_BUFFER
, m_BoundBox
);
396 glBufferData(GL_ARRAY_BUFFER
, sizeof(boundBox
), boundBox
, GL_STATIC_DRAW
);
397 glBindBuffer(GL_ARRAY_BUFFER
, 0);
400 glGenBuffers(1, &m_BoundBoxNormal
);
401 glBindBuffer(GL_ARRAY_BUFFER
, m_BoundBoxNormal
);
402 glBufferData(GL_ARRAY_BUFFER
, sizeof(boundBoxNormal
), boundBoxNormal
, GL_STATIC_DRAW
);
403 glBindBuffer(GL_ARRAY_BUFFER
, 0);
406 m_fViewAngle
= 30.0f
;
407 m_3DProjection
= glm::perspective(m_fViewAngle
, (float)m_iWidth
/ (float)m_iHeight
, 0.01f
, 6000.0f
);
411 maResources
.LoadShaders();
412 maPickingResources
.LoadShaders();
414 glGenBuffers(1, &m_TextTexCoordBuf
);
415 glBindBuffer(GL_ARRAY_BUFFER
, m_TextTexCoordBuf
);
416 glBufferData(GL_ARRAY_BUFFER
, sizeof(texCoords
), texCoords
, GL_STATIC_DRAW
);
417 glBindBuffer(GL_ARRAY_BUFFER
, 0);
419 glGenBuffers(1, &m_RenderTexCoordBuf
);
420 glBindBuffer(GL_ARRAY_BUFFER
, m_RenderTexCoordBuf
);
421 glBufferData(GL_ARRAY_BUFFER
, sizeof(coordReverseVertices
), coordReverseVertices
, GL_STATIC_DRAW
);
422 glBindBuffer(GL_ARRAY_BUFFER
, 0);
424 glGenBuffers(1, &m_RenderVertexBuf
);
425 glBindBuffer(GL_ARRAY_BUFFER
, m_RenderVertexBuf
);
426 glBufferData(GL_ARRAY_BUFFER
, sizeof(squareVertices
), squareVertices
, GL_STATIC_DRAW
);
427 glBindBuffer(GL_ARRAY_BUFFER
, 0);
430 OpenGLHelper::createFramebuffer(m_iWidth
, m_iHeight
, mnPickingFbo
, mnPickingRboDepth
, mnPickingRboColor
);
432 m_Extrude3DInfo
.rounded
= false;
434 if (maResources
.m_b330Support
)
436 Init3DUniformBlock();
437 InitBatch3DUniformBlock();
439 m_TextInfoBatch
.batchNum
= 512;
441 glViewport(0, 0, m_iWidth
, m_iHeight
);
442 Set3DSenceInfo(0xFFFFFF, true);
443 m_GlobalScaleMatrix
= glm::scale(glm::vec3(0.01f
, 0.01f
, 0.01f
));
446 void OpenGL3DRenderer::SetSize(const Size
& rSize
)
448 m_iWidth
= rSize
.Width();
449 m_iHeight
= rSize
.Height();
452 void OpenGL3DRenderer::AddVertexData(GLuint vertexBuf
)
454 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuf
);
455 glBufferData(GL_ARRAY_BUFFER
, m_Vertices
.size() * sizeof(glm::vec3
), &m_Vertices
[0], GL_STATIC_DRAW
);
457 glBindBuffer(GL_ARRAY_BUFFER
, 0);
460 void OpenGL3DRenderer::AddNormalData(GLuint normalBuf
)
462 glBindBuffer(GL_ARRAY_BUFFER
, normalBuf
);
463 glBufferData(GL_ARRAY_BUFFER
, m_Normals
.size() * sizeof(glm::vec3
), &m_Normals
[0], GL_STATIC_DRAW
);
465 glBindBuffer(GL_ARRAY_BUFFER
, 0);
468 void OpenGL3DRenderer::AddIndexData(GLuint indexBuf
)
470 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuf
);
471 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, m_Indices
.size() * sizeof(unsigned short), &m_Indices
[0], GL_STATIC_DRAW
);
473 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
476 bool OpenGL3DRenderer::GetSimilarVertexIndex(PackedVertex
& packed
,
477 std::map
<PackedVertex
,unsigned short> & VertexToOutIndex
,
478 unsigned short & result
481 std::map
<PackedVertex
,unsigned short>::iterator it
= VertexToOutIndex
.find(packed
);
482 if ( it
== VertexToOutIndex
.end() )
493 void OpenGL3DRenderer::SetVertex(PackedVertex
&packed
,
494 std::map
<PackedVertex
,unsigned short> &VertexToOutIndex
,
495 std::vector
<glm::vec3
> &vertex
,
496 std::vector
<glm::vec3
> &normal
,
497 std::vector
<unsigned short> &indices
)
499 unsigned short index
;
500 bool found
= GetSimilarVertexIndex(packed
, VertexToOutIndex
, index
);
502 { // A similar vertex is already in the VBO, use it instead !
503 indices
.push_back( index
);
506 { // If not, it needs to be added in the output data.
507 vertex
.push_back(packed
.position
);
508 normal
.push_back(packed
.normal
);
509 size_t newindex
= vertex
.size() - 1;
510 indices
.push_back( newindex
);
511 VertexToOutIndex
[ packed
] = newindex
;
515 void OpenGL3DRenderer::CreateActualRoundedCube(float fRadius
, int iSubDivY
, int iSubDivZ
, float width
, float height
, float depth
)
517 float topThreshold
= depth
- 2 * fRadius
;
518 float bottomThreshold
= fRadius
;
520 std::vector
<glm::vec3
> vertices
;
521 std::vector
<glm::vec3
> normals
;
522 GenerateRoundCornerBar(vertices
, normals
, fRadius
, iSubDivY
, iSubDivZ
, width
, height
, depth
);
523 std::map
<PackedVertex
,unsigned short> VertexToOutIndex
;
524 glm::vec3 actualVerteices
[3];
525 glm::vec3 actualNormals
[3];
526 std::vector
<unsigned short> indices
[5];
527 glm::vec3 externSurNormal
;
528 glm::mat4 corrctCoord
= glm::translate(glm::vec3(width
/ 2.0f
, height
/ 2.0f
, depth
/ 2.0f
- fRadius
));
529 m_RoundBarMesh
.topThreshold
= topThreshold
;
530 m_RoundBarMesh
.bottomThreshold
= bottomThreshold
;
531 m_RoundBarMesh
.iMeshStartIndices
= m_Vertices
.size();
532 for (int k
= 0; k
< 5; k
++)
534 m_RoundBarMesh
.iElementStartIndices
[k
] = indices
[k
].size();
536 for (size_t i
= 0; i
< vertices
.size(); i
+= 3)
538 for (int k
= 0; k
< 3; k
++)
540 actualVerteices
[k
] = glm::vec3(corrctCoord
* glm::vec4(vertices
[i
+ k
], 1.0));
541 actualNormals
[k
] = normals
[i
+ k
];
543 float maxZ
= std::max(std::max(actualVerteices
[0].z
, actualVerteices
[1].z
), actualVerteices
[2].z
);
544 float minZ
= std::min(std::min(actualVerteices
[0].z
, actualVerteices
[1].z
), actualVerteices
[2].z
);
545 int surfaceIndex
= (minZ
>= topThreshold
- 0.001) ? TOP_SURFACE
: ((maxZ
<= bottomThreshold
+ 0.001) ? BOTTOM_SURFACE
: MIDDLE_SURFACE
);
546 for (int k
= 0; k
< 3; k
++)
549 PackedVertex packed
= {actualVerteices
[k
], actualNormals
[k
]};
550 SetVertex(packed
, VertexToOutIndex
, m_Vertices
, m_Normals
, indices
[surfaceIndex
]);
554 if ((surfaceIndex
== TOP_SURFACE
) || (surfaceIndex
== BOTTOM_SURFACE
))
556 actualVerteices
[k
].z
= 0.0f
;
557 externSurNormal
= (surfaceIndex
== TOP_SURFACE
) ? glm::vec3(0.0, 0.0, 1.0) : glm::vec3(0.0, 0.0, -1.0);
558 int tmpSurfaceIndex
= (surfaceIndex
== TOP_SURFACE
) ? FLAT_TOP_SURFACE
: FLAT_BOTTOM_SURFACE
;
559 PackedVertex packed
= {actualVerteices
[k
], externSurNormal
};
560 SetVertex(packed
, VertexToOutIndex
, m_Vertices
, m_Normals
, indices
[tmpSurfaceIndex
]);
566 m_RoundBarMesh
.iMeshSizes
= m_Vertices
.size() - m_RoundBarMesh
.iMeshStartIndices
;
567 for (int k
= 0; k
< 5; k
++)
569 m_RoundBarMesh
.iElementSizes
[k
] = indices
[k
].size() - m_RoundBarMesh
.iElementStartIndices
[k
];
570 m_RoundBarMesh
.iElementStartIndices
[k
] = m_Indices
.size() * sizeof(unsigned short);
571 for (unsigned int IdxCnt
= 0; IdxCnt
< indices
[k
].size(); IdxCnt
++)
573 m_Indices
.push_back(indices
[k
][IdxCnt
]);
579 VertexToOutIndex
.clear();
582 int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector
<glm::vec3
> &vertices
, std::vector
<glm::vec3
> &normals
, float fRadius
, int iSubDivY
, int iSubDivZ
, float width
, float height
, float depth
)
584 //float fAddAngleY = 360.0f/float(iSubDivY), fAddAngleZ = 180.0f/float(iSubDivZ);
585 float fAddAngleY
= 360.0f
/float(iSubDivY
);
586 float fAddAngleZ
= 180.0f
/float(iSubDivZ
);
587 float fCurAngleY
= 0.0f
;
590 const float PI
= float(atan(1.0)*4.0);
592 float xOffset
[] = {(width
/ 2 - fRadius
), -(width
/ 2 - fRadius
), -(width
/ 2 - fRadius
), (width
/ 2 - fRadius
), (width
/ 2 - fRadius
)};
593 float yOffset
[] = {(height
/ 2 - fRadius
), -(height
/ 2 - fRadius
), (height
/ 2 - fRadius
)};
594 float zOffset
[] = {-(depth
/ 2 - fRadius
), -(depth
/ 2 - fRadius
), (depth
/ 2 - fRadius
), (depth
/ 2 - fRadius
), -(depth
/ 2 - fRadius
)};
595 int iIndices
[] = {0, 1, 2, 2, 3, 0};
596 while(iStepsY
<= iSubDivY
)
598 float fNextAngleY
= fCurAngleY
+fAddAngleY
;
599 if ((fCurAngleY
< 90.0f
) && (fNextAngleY
>= 90.0f
))
603 else if ((fCurAngleY
< 180.0f
) && (fNextAngleY
>= 180.0f
))
605 fNextAngleY
= 180.0f
;
607 else if ((fCurAngleY
< 270.0f
) && (fNextAngleY
>= 270.0f
))
609 fNextAngleY
= 270.0f
;
611 else if ((fCurAngleY
< 360.0f
) && (fNextAngleY
>= 360.0f
))
613 fNextAngleY
= 360.0f
;
615 float fSineY
= sin(fCurAngleY
/180.0f
*PI
), fCosY
= cos(fCurAngleY
/180.0f
*PI
);
616 float fNextSineY
= sin(fNextAngleY
/180.0f
*PI
), fNextCosY
= cos(fNextAngleY
/180.0f
*PI
);
617 glm::vec3
vDirY(fCosY
, 0.0f
, -fSineY
), vNextDirY(fNextCosY
, 0.0f
, -fNextSineY
);
618 float fCurAngleZ
= 0.0f
;
621 if ((fCurAngleY
>= 0) && (fCurAngleY
< 90.0))
625 else if ((fCurAngleY
>= 90) && (fCurAngleY
< 180.0))
629 else if ((fCurAngleY
>= 180) && (fCurAngleY
< 270.0))
633 else if ((fCurAngleY
>= 270) && (fCurAngleY
< 360.0))
637 while(iStepsZ
<= iSubDivZ
)
640 float fNextAngleZ
= fCurAngleZ
+fAddAngleZ
;
642 float fSineZ
= sin(fCurAngleZ
/180.0f
*PI
), fCosZ
= cos(fCurAngleZ
/180.0f
*PI
);
643 float fNextSineZ
= sin(fNextAngleZ
/180.0f
*PI
), fNextCosZ
= cos(fNextAngleZ
/180.0f
*PI
);
645 if ((fCurAngleZ
< 90.0f
) && (fNextAngleZ
>= 90.0f
))
650 if ((fCurAngleZ
>= 0.0f
) && (fCurAngleZ
< 90.0f
))
659 glm::vec3 vQuadPoints
[] =
661 glm::vec3(vDirY
.x
*fSineZ
*fRadius
, fCosZ
*fRadius
, vDirY
.z
*fSineZ
*fRadius
),
662 glm::vec3(vDirY
.x
*fNextSineZ
*fRadius
, fNextCosZ
*fRadius
, vDirY
.z
*fNextSineZ
*fRadius
),
663 glm::vec3(vNextDirY
.x
*fNextSineZ
*fRadius
, fNextCosZ
*fRadius
, vNextDirY
.z
*fNextSineZ
*fRadius
),
664 glm::vec3(vNextDirY
.x
*fSineZ
*fRadius
, fCosZ
*fRadius
, vNextDirY
.z
*fSineZ
*fRadius
)
667 glm::vec3 vActualQuadPoints
[] =
670 glm::vec3(vQuadPoints
[0].x
+ xOffset
[xzIndex
], vQuadPoints
[0].y
+ yOffset
[yIndex
], vQuadPoints
[0].z
+ zOffset
[xzIndex
]),
671 glm::vec3(vQuadPoints
[1].x
+ xOffset
[xzIndex
], vQuadPoints
[1].y
+ yOffset
[yIndex
], vQuadPoints
[1].z
+ zOffset
[xzIndex
]),
672 glm::vec3(vQuadPoints
[2].x
+ xOffset
[xzIndex
], vQuadPoints
[2].y
+ yOffset
[yIndex
], vQuadPoints
[2].z
+ zOffset
[xzIndex
]),
673 glm::vec3(vQuadPoints
[3].x
+ xOffset
[xzIndex
], vQuadPoints
[3].y
+ yOffset
[yIndex
], vQuadPoints
[3].z
+ zOffset
[xzIndex
])
676 glm::vec3 vNormals
[] =
678 glm::normalize(vQuadPoints
[0]),
679 glm::normalize(vQuadPoints
[1]),
680 glm::normalize(vQuadPoints
[2]),
681 glm::normalize(vQuadPoints
[3])
683 for (int i
= 0; i
< 6; i
++)
685 int index
= iIndices
[i
];
686 vertices
.push_back(vActualQuadPoints
[index
]);
687 normals
.push_back(vNormals
[index
]);
689 iFacesAdded
+= 2; // Keep count of added faces
690 if (((fCurAngleY
< 90.0) && (fNextAngleY
>= 90.0)) ||
691 ((fCurAngleY
< 180.0) && (fNextAngleY
>= 180.0)) ||
692 ((fCurAngleY
< 270.0) && (fNextAngleY
>= 270.0)) ||
693 ((fCurAngleY
< 360.0) && (fNextAngleY
>= 360.0)))
695 glm::vec3 vXZQuadNextPoints
[] =
697 glm::vec3(vQuadPoints
[3].x
+ xOffset
[xzIndex
], vQuadPoints
[3].y
+ yOffset
[yIndex
], vQuadPoints
[3].z
+ zOffset
[xzIndex
]),
698 glm::vec3(vQuadPoints
[2].x
+ xOffset
[xzIndex
], vQuadPoints
[2].y
+ yOffset
[yIndex
], vQuadPoints
[2].z
+ zOffset
[xzIndex
]),
699 glm::vec3(vQuadPoints
[2].x
+ xOffset
[xzIndex
+ 1], vQuadPoints
[2].y
+ yOffset
[yIndex
], vQuadPoints
[2].z
+ zOffset
[xzIndex
+ 1]),
700 glm::vec3(vQuadPoints
[3].x
+ xOffset
[xzIndex
+ 1], vQuadPoints
[3].y
+ yOffset
[yIndex
], vQuadPoints
[3].z
+ zOffset
[xzIndex
+ 1])
702 glm::vec3 vXZNextNormals
[] =
704 glm::normalize(vQuadPoints
[3]),
705 glm::normalize(vQuadPoints
[2]),
706 glm::normalize(vQuadPoints
[2]),
707 glm::normalize(vQuadPoints
[3])
709 for (int i
= 0; i
< 6; i
++)
711 int index
= iIndices
[i
];
712 vertices
.push_back(vXZQuadNextPoints
[index
]);
713 normals
.push_back(vXZNextNormals
[index
]);
717 if ((fCurAngleZ
< 90.0) && (fNextAngleZ
>= 90.0))
719 glm::vec3 vYQuadNextPoints
[] =
721 glm::vec3(vQuadPoints
[1].x
+ xOffset
[xzIndex
], vQuadPoints
[1].y
+ yOffset
[yIndex
], vQuadPoints
[1].z
+ zOffset
[xzIndex
]),
722 glm::vec3(vQuadPoints
[1].x
+ xOffset
[xzIndex
], vQuadPoints
[1].y
+ yOffset
[yIndex
+ 1], vQuadPoints
[1].z
+ zOffset
[xzIndex
]),
723 glm::vec3(vQuadPoints
[2].x
+ xOffset
[xzIndex
], vQuadPoints
[2].y
+ yOffset
[yIndex
+ 1], vQuadPoints
[2].z
+ zOffset
[xzIndex
]),
724 glm::vec3(vQuadPoints
[2].x
+ xOffset
[xzIndex
], vQuadPoints
[2].y
+ yOffset
[yIndex
], vQuadPoints
[2].z
+ zOffset
[xzIndex
])
726 glm::vec3 vYNextNormals
[] =
728 glm::normalize(vQuadPoints
[1]),
729 glm::normalize(vQuadPoints
[1]),
730 glm::normalize(vQuadPoints
[2]),
731 glm::normalize(vQuadPoints
[2])
733 for (int i
= 0; i
< 6; i
++)
735 int index
= iIndices
[i
];
736 vertices
.push_back(vYQuadNextPoints
[index
]);
737 normals
.push_back(vYNextNormals
[index
]);
742 if ((iStepsZ
> iSubDivZ
) && (fCurAngleZ
< 180.0f
))
746 fCurAngleZ
= fNextAngleZ
;
749 if ((iStepsY
> iSubDivY
) && (fCurAngleY
< 360.0f
))
753 fCurAngleY
= fNextAngleY
;
755 //draw the rectangle face
757 glm::vec3 vTopPoints
[] =
759 glm::vec3(xOffset
[0], height
/ 2, zOffset
[0]),
760 glm::vec3(xOffset
[1], height
/ 2, zOffset
[1]),
761 glm::vec3(xOffset
[2], height
/ 2, zOffset
[2]),
762 glm::vec3(xOffset
[3], height
/ 2, zOffset
[3])
764 glm::vec3 vTopNormal
= glm::vec3(0.0f
, 1.0f
, 0.0f
);
765 for (int i
= 0; i
< 6; i
++)
767 int index
= iIndices
[i
];
768 vertices
.push_back(vTopPoints
[index
]);
769 normals
.push_back(vTopNormal
);
773 glm::vec3 vBottomPoints
[] =
775 glm::vec3(xOffset
[3], -height
/ 2, zOffset
[3]),
776 glm::vec3(xOffset
[2], -height
/ 2, zOffset
[2]),
777 glm::vec3(xOffset
[1], -height
/ 2, zOffset
[1]),
778 glm::vec3(xOffset
[0], -height
/ 2, zOffset
[0])
780 glm::vec3 vBottomNormal
= glm::vec3(0.0f
, -1.0f
, 0.0f
);
781 for (int i
= 0; i
< 6; i
++)
783 int index
= iIndices
[i
];
784 vertices
.push_back(vBottomPoints
[index
]);
785 normals
.push_back(vBottomNormal
);
789 glm::vec3 vLeftPoints
[] =
791 glm::vec3(-width
/ 2, yOffset
[0], zOffset
[0]),
792 glm::vec3(-width
/ 2, yOffset
[1], zOffset
[1]),
793 glm::vec3(-width
/ 2, yOffset
[1], zOffset
[2]),
794 glm::vec3(-width
/ 2, yOffset
[0], zOffset
[3])
796 glm::vec3 vLeftNormal
= glm::vec3(-1.0f
, 0.0f
, 0.0f
);
797 for (int i
= 0; i
< 6; i
++)
799 int index
= iIndices
[i
];
800 vertices
.push_back(vLeftPoints
[index
]);
801 normals
.push_back(vLeftNormal
);
804 glm::vec3 vRightPoints
[] =
806 glm::vec3(width
/ 2, yOffset
[0], zOffset
[3]),
807 glm::vec3(width
/ 2, yOffset
[1], zOffset
[2]),
808 glm::vec3(width
/ 2, yOffset
[1], zOffset
[1]),
809 glm::vec3(width
/ 2, yOffset
[0], zOffset
[0])
811 glm::vec3 vRightNormal
= glm::vec3(1.0f
, 0.0f
, 0.0f
);
812 for (int i
= 0; i
< 6; i
++)
814 int index
= iIndices
[i
];
815 vertices
.push_back(vRightPoints
[index
]);
816 normals
.push_back(vRightNormal
);
820 glm::vec3 vFrontPoints
[] =
822 glm::vec3(xOffset
[0], yOffset
[0], depth
/ 2),
823 glm::vec3(xOffset
[1], yOffset
[0], depth
/ 2),
824 glm::vec3(xOffset
[2], yOffset
[1], depth
/ 2),
825 glm::vec3(xOffset
[3], yOffset
[1], depth
/ 2)
827 glm::vec3 vFrontNormal
= glm::vec3(0.0f
, 0.0f
, 1.0f
);
828 for (int i
= 0; i
< 6; i
++)
830 int index
= iIndices
[i
];
831 vertices
.push_back(vFrontPoints
[index
]);
832 normals
.push_back(vFrontNormal
);
835 glm::vec3 vBackPoints
[] =
837 glm::vec3(xOffset
[0], yOffset
[1], -depth
/ 2),
838 glm::vec3(xOffset
[1], yOffset
[1], -depth
/ 2),
839 glm::vec3(xOffset
[2], yOffset
[0], -depth
/ 2),
840 glm::vec3(xOffset
[3], yOffset
[0], -depth
/ 2)
842 glm::vec3 vBackNormal
= glm::vec3(0.0f
, 0.0f
, -1.0f
);
843 for (int i
= 0; i
< 6; i
++)
845 int index
= iIndices
[i
];
846 vertices
.push_back(vBackPoints
[index
]);
847 normals
.push_back(vBackNormal
);
853 void OpenGL3DRenderer::RenderLine3D(const Polygon3DInfo
& polygon
)
856 glUseProgram(maResources
.m_CommonProID
);
857 PosVecf3 trans
= {0.0f
, 0, 0.0};
858 PosVecf3 angle
= {0.0f
, 0.0f
, 0.0f
};
859 PosVecf3 scale
= {1.0f
, 1.0f
, 1.0f
};
860 MoveModelf(trans
, angle
, scale
);
861 m_Model
= m_GlobalScaleMatrix
* m_Model
;
862 m_3DMVP
= m_3DProjection
* m_3DView
* m_Model
;
864 for (size_t i
= 0; i
< polygon
.verticesList
.size(); i
++)
866 //move the circle to the pos, and scale using the xScale and Y scale
867 Vertices3D
*pointList
= polygon
.verticesList
[i
];
868 //if line only, using the common shader to render
871 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
872 glBufferData(GL_ARRAY_BUFFER
, pointList
->size() * sizeof(glm::vec3
), &pointList
[0][0], GL_STATIC_DRAW
);
874 glUniform4fv(maResources
.m_2DColorID
, 1, &polygon
.id
[0]);
876 glUniform4fv(maResources
.m_2DColorID
, 1, &polygon
.polygonColor
[0]);
877 glUniformMatrix4fv(maResources
.m_MatrixID
, 1, GL_FALSE
, &m_3DMVP
[0][0]);
880 // 1rst attribute buffer : vertices
881 glEnableVertexAttribArray(maResources
.m_2DVertexID
);
883 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
885 glVertexAttribPointer(maResources
.m_2DVertexID
, // attribute
888 GL_FALSE
, // normalized?
890 (void*)0 // array buffer offset
894 glLineWidth(polygon
.lineWidth
);
896 glDrawArrays(GL_LINE_STRIP
, 0, pointList
->size());
898 glDisableVertexAttribArray(maResources
.m_2DVertexID
);
900 glBindBuffer(GL_ARRAY_BUFFER
, 0);
907 void OpenGL3DRenderer::RenderPolygon3D(const Polygon3DInfo
& polygon
)
910 size_t verticesNum
= polygon
.verticesList
.size();
911 size_t normalsNum
= polygon
.normalsList
.size();
912 //check whether the number of vertices and normals are equal
913 if (m_CameraInfo
.cameraPos
.z
>= 0.0f
)
914 glPolygonOffset(1.0, 1.0);
916 glPolygonOffset(-1.0, -1.0);
918 if (verticesNum
!= normalsNum
)
922 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
926 glUseProgram(maPickingResources
.m_CommonProID
);
927 float minCoordX
= 0.0f
;
928 float maxCoordX
= m_fMinCoordX
+ m_fMaxCoordX
;
929 glUniform1fv(maPickingResources
.m_MinCoordXID
, 1, &minCoordX
);
930 glUniform1fv(maPickingResources
.m_MaxCoordXID
, 1, &maxCoordX
);
934 glUseProgram(maResources
.m_3DProID
);
935 glUniformMatrix4fv(maResources
.m_3DViewID
, 1, GL_FALSE
, &m_3DView
[0][0]);
936 glUniformMatrix4fv(maResources
.m_3DProjectionID
, 1, GL_FALSE
, &m_3DProjection
[0][0]);
938 if (maResources
.m_b330Support
)
941 Update3DUniformBlock();
942 glBindBuffer(GL_UNIFORM_BUFFER
, m_3DUBOBuffer
);
943 glBufferSubData(GL_UNIFORM_BUFFER
, m_3DActualSizeLight
, sizeof(MaterialParameters
), &polygon
.material
);
948 float minCoordX
= 0.0f
;
949 float maxCoordX
= m_fMinCoordX
+ m_fMaxCoordX
;
950 glUniform1fv(maResources
.m_3DMinCoordXID
, 1, &minCoordX
);
951 glUniform1fv(maResources
.m_3DMaxCoordXID
, 1, &maxCoordX
);
952 glUniform1i(maResources
.m_3DUndrawID
, m_bUndrawFlag
);
954 //update light information
955 glUniform4fv(maResources
.m_3DLightColorID
, m_iLightNum
, reinterpret_cast<GLfloat
*>(m_LightColor
));
956 glUniform4fv(maResources
.m_3DLightPosID
, m_iLightNum
, reinterpret_cast<GLfloat
*>(m_PositionWorldspace
));
957 glUniform1fv(maResources
.m_3DLightPowerID
, m_iLightNum
, m_fLightPower
);
958 glUniform1i(maResources
.m_3DLightNumID
, m_iLightNum
);
959 glUniform4fv(maResources
.m_3DLightAmbientID
, 1, &m_Ambient
[0]);
961 //update meterial information
962 glUniform4fv(maResources
.m_3DMaterialAmbientID
, 1, &polygon
.material
.ambient
[0]);
963 glUniform4fv(maResources
.m_3DMaterialDiffuseID
, 1, &polygon
.material
.diffuse
[0]);
964 glUniform4fv(maResources
.m_3DMaterialSpecularID
, 1, &polygon
.material
.specular
[0]);
965 glUniform4fv(maResources
.m_3DMaterialColorID
, 1, &polygon
.material
.materialColor
[0]);
966 glUniform1i(maResources
.m_3DMaterialTwoSidesID
, polygon
.material
.twoSidesLighting
);
967 glUniform1f(maResources
.m_3DMaterialShininessID
, polygon
.material
.shininess
);
971 for (size_t i
= 0; i
< verticesNum
; i
++)
973 //move the circle to the pos, and scale using the xScale and Y scale
974 Vertices3D
*pointList
= polygon
.verticesList
[i
];
975 Normals3D
*normalList
= polygon
.normalsList
[i
];
976 PosVecf3 trans
= {0.0f
, 0.0f
, 0.0};
977 PosVecf3 angle
= {0.0f
, 0.0f
, 0.0f
};
978 PosVecf3 scale
= {1.0f
, 1.0f
, 1.0f
};
979 MoveModelf(trans
, angle
, scale
);
980 m_Model
= m_GlobalScaleMatrix
* m_Model
;
981 glm::mat3
normalMatrix(m_Model
);
982 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
986 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
987 glBufferData(GL_ARRAY_BUFFER
, pointList
->size() * sizeof(glm::vec3
), &pointList
[0][0], GL_STATIC_DRAW
);
993 glBindBuffer(GL_ARRAY_BUFFER
, m_NormalBuffer
);
995 glBufferData(GL_ARRAY_BUFFER
, normalList
->size() * sizeof(glm::vec3
), &normalList
[0][0], GL_STATIC_DRAW
);
997 glUniformMatrix4fv(maResources
.m_3DModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
999 glUniformMatrix3fv(maResources
.m_3DNormalMatrixID
, 1, GL_FALSE
, &normalInverseTranspos
[0][0]);
1004 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
1005 glUniformMatrix4fv(maPickingResources
.m_MatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
1006 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &polygon
.id
[0]);
1009 GLint maVertexID
= mbPickingMode
? maPickingResources
.m_2DVertexID
: maResources
.m_3DVertexID
;
1010 // 1rst attribute buffer : vertices
1011 glEnableVertexAttribArray(maVertexID
);
1013 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
1015 glVertexAttribPointer(maVertexID
, // attribute
1018 GL_FALSE
, // normalized?
1020 (void*)0 // array buffer offset
1025 // 2nd attribute buffer : normals
1026 glEnableVertexAttribArray(maResources
.m_3DNormalID
);
1028 glBindBuffer(GL_ARRAY_BUFFER
, m_NormalBuffer
);
1030 glVertexAttribPointer(maResources
.m_3DNormalID
, // attribute
1033 GL_FALSE
, // normalized?
1035 (void*)0 // array buffer offset
1039 glDrawArrays(GL_POLYGON
, 0, pointList
->size());
1041 glDisableVertexAttribArray(maVertexID
);
1044 glDisableVertexAttribArray(maResources
.m_3DNormalID
);
1047 glBindBuffer(GL_ARRAY_BUFFER
, 0);
1056 template< typename T
>
1057 struct DeletePointer
1059 void operator()(T
* p
)
1067 void OpenGL3DRenderer::ReleasePolygonShapes()
1069 for (size_t i
= 0; i
< m_Polygon3DInfoList
.size(); i
++)
1071 Polygon3DInfo
&polygon
= m_Polygon3DInfoList
[i
];
1072 std::for_each(polygon
.verticesList
.begin(),
1073 polygon
.verticesList
.end(), DeletePointer
<Vertices3D
>());
1074 std::for_each(polygon
.normalsList
.begin(),
1075 polygon
.normalsList
.end(), DeletePointer
<Normals3D
>());
1076 delete polygon
.vertices
;
1077 delete polygon
.normals
;
1079 m_Polygon3DInfoList
.clear();
1082 void OpenGL3DRenderer::RenderPolygon3DObject()
1084 glDepthMask(GL_FALSE
);
1086 for (size_t i
= 0; i
< m_Polygon3DInfoList
.size(); i
++)
1088 Polygon3DInfo
&polygon
= m_Polygon3DInfoList
[i
];
1089 if (polygon
.lineOnly
|| (!polygon
.fillStyle
))
1091 //just use the common shader is ok for lines
1092 RenderLine3D(polygon
);
1097 RenderPolygon3D(polygon
);
1100 glDepthMask(GL_TRUE
);
1104 void OpenGL3DRenderer::Set3DSenceInfo(sal_uInt32 nColor
, bool twoSidesLighting
)
1106 m_Polygon3DInfo
.material
.twoSidesLighting
= twoSidesLighting
;
1107 if (maResources
.m_b330Support
)
1109 m_LightsInfo
.ambient
= getColorAsVector(nColor
);
1110 m_LightsInfo
.lightNum
= 0;
1115 m_Ambient
= getColorAsVector(nColor
);;
1117 SetLightInfo(true, 0xFFFFFF, glm::vec4(-1.0, -1.0, 1.0, 0.0));
1118 SetLightInfo(true, 0xFFFFFF, glm::vec4(-1.0, 1.0, 1.0, 0.0));
1119 SetLightInfo(true, 0xFFFFFF, glm::vec4(1.0, -1.0, 1.0, 0.0));
1120 SetLightInfo(true, 0xFFFFFF, glm::vec4(1.0, 1.0, 1.0, 0.0));
1123 void OpenGL3DRenderer::SetLightInfo(bool lightOn
, sal_uInt32 nColor
, const glm::vec4
& direction
)
1127 if (maResources
.m_b330Support
)
1129 if (m_LightsInfo
.lightNum
>= MAX_LIGHT_NUM
)
1133 m_LightsInfo
.light
[m_LightsInfo
.lightNum
].lightColor
= getColorAsVector(nColor
);
1134 m_LightsInfo
.light
[m_LightsInfo
.lightNum
].positionWorldspace
= direction
;
1135 m_LightsInfo
.light
[m_LightsInfo
.lightNum
].lightPower
= 0.3f
;
1136 m_LightsInfo
.lightNum
++;
1140 if (m_iLightNum
>= MAX_LIGHT_NUM
)
1144 m_LightColor
[m_iLightNum
] = getColorAsVector(nColor
);
1145 m_PositionWorldspace
[m_iLightNum
] = direction
;
1146 m_fLightPower
[m_iLightNum
] = 0.3f
;
1152 void OpenGL3DRenderer::AddShapePolygon3DObject(sal_uInt32 nColor
, bool lineOnly
, sal_uInt32 nLineColor
,long fillStyle
, sal_uInt32 specular
, sal_uInt32 nUniqueId
)
1154 m_Polygon3DInfo
.polygonColor
= getColorAsVector(nColor
);
1155 m_Polygon3DInfo
.id
= getColorAsVector(nUniqueId
);
1156 m_Polygon3DInfo
.material
.materialColor
= m_Polygon3DInfo
.polygonColor
;//material color seems to be the same for all parts, so we use the polygon color
1158 m_Polygon3DInfo
.lineOnly
= lineOnly
;
1160 // if line only, use line color
1161 if (m_Polygon3DInfo
.lineOnly
)
1163 m_Polygon3DInfo
.polygonColor
= getColorAsVector(nLineColor
);
1167 m_Polygon3DInfo
.fillStyle
= fillStyle
;
1169 //material specular;
1170 m_Polygon3DInfo
.material
.specular
= getColorAsVector(specular
);
1172 m_Polygon3DInfo
.material
.diffuse
= glm::vec4(1.0, 1.0, 1.0, 1.0);
1174 m_Polygon3DInfo
.material
.ambient
= glm::vec4(0.2, 0.2, 0.2, 1.0);
1176 m_Polygon3DInfo
.material
.shininess
= 1.0f
;
1179 void OpenGL3DRenderer::EndAddShapePolygon3DObject()
1181 m_Polygon3DInfoList
.push_back(m_Polygon3DInfo
);
1182 m_Polygon3DInfo
.normals
= NULL
;
1183 m_Polygon3DInfo
.vertices
= NULL
;
1184 // TODO: moggi: memory leak???
1185 m_Polygon3DInfo
.verticesList
.clear();
1186 m_Polygon3DInfo
.normalsList
.clear();
1189 void OpenGL3DRenderer::AddPolygon3DObjectNormalPoint(float x
, float y
, float z
)
1191 if (m_Polygon3DInfo
.fillStyle
)
1193 if (!m_Polygon3DInfo
.normals
)
1195 m_Polygon3DInfo
.normals
= new Normals3D
;
1197 m_Polygon3DInfo
.normals
->push_back(glm::vec3(x
, y
, z
));
1201 void OpenGL3DRenderer::EndAddPolygon3DObjectNormalPoint()
1203 m_Polygon3DInfo
.normalsList
.push_back(m_Polygon3DInfo
.normals
);
1204 m_Polygon3DInfo
.normals
= NULL
;
1207 void OpenGL3DRenderer::AddPolygon3DObjectPoint(float x
, float y
, float z
)
1209 if (!m_Polygon3DInfo
.vertices
)
1211 m_Polygon3DInfo
.vertices
= new Vertices3D
;
1213 //float actualX = x - (float)m_iWidth / 2;
1214 //float actualY = y - (float)m_iHeight / 2;
1218 m_Polygon3DInfo
.vertices
->push_back(glm::vec3(actualX
, actualY
, actualZ
));
1221 void OpenGL3DRenderer::EndAddPolygon3DObjectPoint()
1223 m_Polygon3DInfo
.verticesList
.push_back(m_Polygon3DInfo
.vertices
);
1224 m_Polygon3DInfo
.vertices
= NULL
;
1227 void OpenGL3DRenderer::AddShape3DExtrudeObject(bool roundedCorner
, sal_uInt32 nColor
, sal_uInt32 specular
, const glm::mat4
& modelMatrix
, sal_uInt32 nUniqueId
)
1229 m_Extrude3DInfo
.id
= getColorAsVector(nUniqueId
);
1230 m_Extrude3DInfo
.orgID
= nUniqueId
;
1231 glm::vec4 tranform
= modelMatrix
* glm::vec4(0.0, 0.0, 0.0, 1.0);
1232 glm::vec4 DirX
= modelMatrix
* glm::vec4(1.0, 0.0, 0.0, 0.0);
1233 glm::vec4 DirY
= modelMatrix
* glm::vec4(0.0, 1.0, 0.0, 0.0);
1234 glm::vec4 DirZ
= modelMatrix
* glm::vec4(0.0, 0.0, 1.0, 0.0);
1235 m_Extrude3DInfo
.xScale
= glm::length(DirX
);
1236 m_Extrude3DInfo
.yScale
= glm::length(DirY
);
1237 m_Extrude3DInfo
.zScale
= glm::length(DirZ
);
1238 glm::mat4 transformMatrixInverse
= glm::inverse(glm::translate(glm::vec3(tranform
)));
1239 glm::mat4 scaleMatrixInverse
= glm::inverse(glm::scale(glm::vec3(m_Extrude3DInfo
.xScale
, m_Extrude3DInfo
.yScale
, m_Extrude3DInfo
.zScale
)));
1240 m_Extrude3DInfo
.rotation
= transformMatrixInverse
* modelMatrix
* scaleMatrixInverse
;
1243 m_Extrude3DInfo
.extrudeColor
= getColorAsVector(nColor
);
1244 m_Extrude3DInfo
.material
.materialColor
= m_Extrude3DInfo
.extrudeColor
;//material color seems to be the same for all parts, so we use the polygon color
1246 //material specular;
1247 m_Extrude3DInfo
.material
.specular
= getColorAsVector(specular
);
1249 m_Extrude3DInfo
.material
.diffuse
= glm::vec4(1.0, 1.0, 1.0, 1.0);
1251 m_Extrude3DInfo
.material
.ambient
= glm::vec4(0.2, 0.2, 0.2, 1.0);
1253 m_Extrude3DInfo
.material
.shininess
= 1.0f
;
1254 m_Extrude3DInfo
.xTransform
= tranform
.x
;
1255 m_Extrude3DInfo
.yTransform
= tranform
.y
;
1256 m_Extrude3DInfo
.zTransform
= tranform
.z
;
1258 float height
= m_Extrude3DInfo
.yScale
/ m_Extrude3DInfo
.xScale
;
1259 float radius
= height
> 0.2f
? 0.2f
: height
/ 4.0f
;
1260 float depth
= 1 + 2 * radius
;
1261 bool NORoundedCube
= (radius
> (width
/ 2)) || (radius
> (height
/ 2)) || (radius
> (depth
/ 2));
1262 if (!NORoundedCube
&& roundedCorner
&& (m_RoundBarMesh
.iMeshSizes
== 0))
1264 CreateActualRoundedCube(radius
, CORNER_DIVION_Y
, CORNER_DIVION_Z
, width
, height
, depth
);
1265 AddVertexData(m_CubeVertexBuf
);
1266 AddNormalData(m_CubeNormalBuf
);
1267 AddIndexData(m_CubeElementBuf
);
1268 for (int j
= 0; j
< 5; j
++)
1270 m_Extrude3DInfo
.startIndex
[j
] = m_RoundBarMesh
.iElementStartIndices
[j
];
1271 m_Extrude3DInfo
.size
[j
] = m_RoundBarMesh
.iElementSizes
[j
];
1276 m_Extrude3DInfo
.rounded
= true;
1278 m_Batchmaterial
= m_Extrude3DInfo
.material
;
1281 void OpenGL3DRenderer::EndAddShape3DExtrudeObject()
1283 m_Extrude3DList
.push_back(m_Extrude3DInfo
);
1286 void OpenGL3DRenderer::Init3DUniformBlock()
1291 GLuint a3DLightBlockIndex
= glGetUniformBlockIndex(maResources
.m_3DProID
, "GlobalLights");
1292 GLuint a3DMaterialBlockIndex
= glGetUniformBlockIndex(maResources
.m_3DProID
, "GlobalMaterialParameters");
1294 if ((GL_INVALID_INDEX
== a3DLightBlockIndex
) || (GL_INVALID_INDEX
== a3DMaterialBlockIndex
))
1298 int nUniformBufferAlignSize
= 1;
1299 glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT
, &nUniformBufferAlignSize
);
1300 GLint nBlockDataSizeLight
= 0, nBlockDataSizeMertrial
= 0;
1301 glGetActiveUniformBlockiv(maResources
.m_3DProID
, a3DLightBlockIndex
, GL_UNIFORM_BLOCK_DATA_SIZE
, &nBlockDataSizeLight
);
1302 glGetActiveUniformBlockiv(maResources
.m_3DProID
, a3DMaterialBlockIndex
, GL_UNIFORM_BLOCK_DATA_SIZE
, &nBlockDataSizeMertrial
);
1304 glGenBuffers(1, &m_3DUBOBuffer
);
1305 glBindBuffer(GL_UNIFORM_BUFFER
, m_3DUBOBuffer
);
1307 m_3DActualSizeLight
= ((nBlockDataSizeLight
/ nUniformBufferAlignSize
) + std::min(nBlockDataSizeLight
% nUniformBufferAlignSize
, 1)) * nUniformBufferAlignSize
;
1308 // cout << "nBlockDataSizeMertrial = " << nBlockDataSizeMertrial << ", nBlockDataSizeLight = " << nBlockDataSizeLight << ", m_3DActualSizeLight = " << m_3DActualSizeLight << endl;
1309 int dataSize
= m_3DActualSizeLight
+ nBlockDataSizeMertrial
;
1310 glBufferData(GL_UNIFORM_BUFFER
, dataSize
, NULL
, GL_DYNAMIC_DRAW
);
1311 glBindBufferRange(GL_UNIFORM_BUFFER
, 0, m_3DUBOBuffer
, 0, nBlockDataSizeLight
);
1313 glUniformBlockBinding(maResources
.m_3DProID
, a3DLightBlockIndex
, 0);
1315 glBindBufferRange(GL_UNIFORM_BUFFER
, 1, m_3DUBOBuffer
, ((nBlockDataSizeLight
/ nUniformBufferAlignSize
) + std::min(nBlockDataSizeLight
% nUniformBufferAlignSize
, 1)) * nUniformBufferAlignSize
, nBlockDataSizeMertrial
);
1316 glUniformBlockBinding(maResources
.m_3DProID
, a3DMaterialBlockIndex
, 1);
1317 //for the light source uniform, we must calc the offset of each element
1319 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
1322 void OpenGL3DRenderer::InitBatch3DUniformBlock()
1327 GLuint a3DLightBlockIndex
= glGetUniformBlockIndex(maResources
.m_3DBatchProID
, "GlobalLights");
1328 GLuint a3DMaterialBlockIndex
= glGetUniformBlockIndex(maResources
.m_3DBatchProID
, "GlobalMaterialParameters");
1330 if ((GL_INVALID_INDEX
== a3DLightBlockIndex
) || (GL_INVALID_INDEX
== a3DMaterialBlockIndex
))
1334 int nUniformBufferAlignSize
= 1;
1335 glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT
, &nUniformBufferAlignSize
);
1336 GLint nBlockDataSizeLight
= 0, nBlockDataSizeMertrial
= 0;
1337 glGetActiveUniformBlockiv(maResources
.m_3DBatchProID
, a3DLightBlockIndex
, GL_UNIFORM_BLOCK_DATA_SIZE
, &nBlockDataSizeLight
);
1338 glGetActiveUniformBlockiv(maResources
.m_3DBatchProID
, a3DMaterialBlockIndex
, GL_UNIFORM_BLOCK_DATA_SIZE
, &nBlockDataSizeMertrial
);
1340 glGenBuffers(1, &m_Batch3DUBOBuffer
);
1341 glBindBuffer(GL_UNIFORM_BUFFER
, m_Batch3DUBOBuffer
);
1343 m_Batch3DActualSizeLight
= ((nBlockDataSizeLight
/ nUniformBufferAlignSize
) + std::min(nBlockDataSizeLight
% nUniformBufferAlignSize
, 1)) * nUniformBufferAlignSize
;
1344 // cout << "nBlockDataSizeMertrial = " << nBlockDataSizeMertrial << ", nBlockDataSizeLight = " << nBlockDataSizeLight << ", m_3DActualSizeLight = " << m_3DActualSizeLight << endl;
1345 int dataSize
= m_Batch3DActualSizeLight
+ nBlockDataSizeMertrial
;
1346 glBufferData(GL_UNIFORM_BUFFER
, dataSize
, NULL
, GL_DYNAMIC_DRAW
);
1347 glBindBufferRange(GL_UNIFORM_BUFFER
, 2, m_Batch3DUBOBuffer
, 0, nBlockDataSizeLight
);
1349 glUniformBlockBinding(maResources
.m_3DBatchProID
, a3DLightBlockIndex
, 2);
1351 glBindBufferRange(GL_UNIFORM_BUFFER
, 3, m_Batch3DUBOBuffer
, ((nBlockDataSizeLight
/ nUniformBufferAlignSize
) + std::min(nBlockDataSizeLight
% nUniformBufferAlignSize
, 1)) * nUniformBufferAlignSize
, nBlockDataSizeMertrial
);
1352 glUniformBlockBinding(maResources
.m_3DBatchProID
, a3DMaterialBlockIndex
, 3);
1353 //for the light source uniform, we must calc the offset of each element
1355 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
1358 void OpenGL3DRenderer::UpdateBatch3DUniformBlock()
1364 glBindBuffer(GL_UNIFORM_BUFFER
, m_Batch3DUBOBuffer
);
1366 glBufferSubData(GL_UNIFORM_BUFFER
, 0, sizeof(GLint
), &m_LightsInfo
.lightNum
);
1368 //current std140 alignment: 16
1369 glBufferSubData(GL_UNIFORM_BUFFER
, 16, sizeof(glm::vec4
), &m_LightsInfo
.ambient
[0]);
1371 //current std140 alignment: 16
1372 glBufferSubData(GL_UNIFORM_BUFFER
, 32, sizeof(LightSource
) * MAX_LIGHT_NUM
, &m_LightsInfo
.light
);
1374 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
1377 void OpenGL3DRenderer::Update3DUniformBlock()
1383 glBindBuffer(GL_UNIFORM_BUFFER
, m_3DUBOBuffer
);
1385 glBufferSubData(GL_UNIFORM_BUFFER
, 0, sizeof(GLint
), &m_LightsInfo
.lightNum
);
1387 //current std140 alignment: 16
1388 glBufferSubData(GL_UNIFORM_BUFFER
, 16, sizeof(glm::vec4
), &m_LightsInfo
.ambient
[0]);
1390 //current std140 alignment: 16
1391 glBufferSubData(GL_UNIFORM_BUFFER
, 32, sizeof(LightSource
) * MAX_LIGHT_NUM
, &m_LightsInfo
.light
);
1393 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
1396 void OpenGL3DRenderer::RenderExtrudeFlatSurface(const Extrude3DInfo
& extrude3D
, int surIndex
)
1398 float xyScale
= extrude3D
.xScale
;
1399 PosVecf3 trans
= {extrude3D
.xTransform
,
1400 extrude3D
.yTransform
,
1401 extrude3D
.zTransform
};
1402 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
1403 glm::mat4 flatScale
= glm::scale(glm::vec3(xyScale
, xyScale
, xyScale
));
1404 m_Model
= m_ScrollMoveMatrix
* m_GlobalScaleMatrix
* aTranslationMatrix
* extrude3D
.rotation
* flatScale
;
1407 glm::mat3
normalMatrix(m_Model
);
1408 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
1409 glUniformMatrix4fv(maResources
.m_3DModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1410 glUniformMatrix3fv(maResources
.m_3DNormalMatrixID
, 1, GL_FALSE
, &normalInverseTranspos
[0][0]);
1414 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
1415 glUniformMatrix4fv(maPickingResources
.m_ModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1416 glUniformMatrix4fv(maPickingResources
.m_MatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
1417 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &extrude3D
.id
[0]);
1420 glDrawElements(GL_TRIANGLES
, extrude3D
.size
[surIndex
], GL_UNSIGNED_SHORT
, reinterpret_cast<GLvoid
*>(extrude3D
.startIndex
[surIndex
]));
1423 void OpenGL3DRenderer::RenderExtrudeBottomSurface(const Extrude3DInfo
& extrude3D
)
1425 float xyScale
= extrude3D
.xScale
;
1426 float zScale
= extrude3D
.zScale
;
1427 float actualZTrans
= zScale
- m_RoundBarMesh
.bottomThreshold
* xyScale
;
1428 PosVecf3 trans
= {extrude3D
.xTransform
,
1429 extrude3D
.yTransform
,
1430 extrude3D
.zTransform
};
1431 //PosVecf3 angle = {0.0f, 0.0f, 0.0f};
1432 if (actualZTrans
< 0.0f
)
1434 // the height of rounded corner is higher than the cube than use the org scale matrix
1435 // yScale /= (float)(1 + BOTTOM_THRESHOLD);
1436 zScale
/= (float)(m_RoundBarMesh
.bottomThreshold
);
1437 PosVecf3 scale
= {xyScale
, xyScale
, zScale
};
1438 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
1439 glm::mat4 aScaleMatrix
= glm::scale(glm::vec3(scale
.x
, scale
.y
, scale
.z
));
1440 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* aScaleMatrix
;
1444 glm::mat4 topTrans
= glm::translate(glm::vec3(0.0, 0.0, actualZTrans
));
1445 glm::mat4 topScale
= glm::scale(glm::vec3(xyScale
, xyScale
, xyScale
));
1446 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
1447 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* topTrans
* topScale
;
1449 m_Model
= m_ScrollMoveMatrix
* m_GlobalScaleMatrix
* m_Model
;
1452 glm::mat3
normalMatrix(m_Model
);
1453 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
1454 glUniformMatrix4fv(maResources
.m_3DModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1455 glUniformMatrix3fv(maResources
.m_3DNormalMatrixID
, 1, GL_FALSE
, &normalInverseTranspos
[0][0]);
1459 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
1460 glUniformMatrix4fv(maPickingResources
.m_ModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1461 glUniformMatrix4fv(maPickingResources
.m_MatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
1462 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &extrude3D
.id
[0]);
1464 glDrawElements(GL_TRIANGLES
, extrude3D
.size
[BOTTOM_SURFACE
], GL_UNSIGNED_SHORT
, reinterpret_cast<GLvoid
*>(extrude3D
.startIndex
[BOTTOM_SURFACE
]));
1467 void OpenGL3DRenderer::RenderExtrudeMiddleSurface(const Extrude3DInfo
& extrude3D
)
1469 float xyScale
= extrude3D
.xScale
;
1470 float zScale
= extrude3D
.zScale
;
1471 float actualZScale
= zScale
- m_RoundBarMesh
.bottomThreshold
* xyScale
;
1472 PosVecf3 trans
= {extrude3D
.xTransform
,
1473 extrude3D
.yTransform
,
1474 extrude3D
.zTransform
};
1475 if (actualZScale
< 0.0f
)
1477 // the height of rounded corner is higher than the cube than use the org scale matrix
1478 // yScale /= (float)(1 + BOTTOM_THRESHOLD);
1479 // PosVecf3 scale = {xzScale, yScale, xzScale};
1480 // MoveModelf(trans, angle, scale);
1485 glm::mat4 scale
= glm::scale(glm::vec3(xyScale
, xyScale
,actualZScale
));
1486 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
1487 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* scale
;
1490 if (extrude3D
.reverse
)
1492 glm::mat4 reverseMatrix
= glm::translate(glm::vec3(0.0, 0.0, -1.0));
1493 m_Model
= m_Model
* reverseMatrix
;
1495 m_Model
= m_ScrollMoveMatrix
* m_GlobalScaleMatrix
* m_Model
;
1498 glm::mat3
normalMatrix(m_Model
);
1499 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
1500 glUniformMatrix4fv(maResources
.m_3DModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1501 glUniformMatrix3fv(maResources
.m_3DNormalMatrixID
, 1, GL_FALSE
, &normalInverseTranspos
[0][0]);
1505 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
1506 glUniformMatrix4fv(maPickingResources
.m_ModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1507 glUniformMatrix4fv(maPickingResources
.m_MatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
1508 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &extrude3D
.id
[0]);
1510 glDrawElements(GL_TRIANGLES
, extrude3D
.size
[MIDDLE_SURFACE
], GL_UNSIGNED_SHORT
, reinterpret_cast<GLvoid
*>(extrude3D
.startIndex
[MIDDLE_SURFACE
]));
1513 void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo
& extrude3D
)
1515 float xyScale
= extrude3D
.xScale
;
1516 float zScale
= extrude3D
.zScale
;
1517 float actualZTrans
= zScale
- m_RoundBarMesh
.bottomThreshold
* xyScale
;
1518 PosVecf3 trans
= {extrude3D
.xTransform
,
1519 extrude3D
.yTransform
,
1520 extrude3D
.zTransform
};
1521 if (actualZTrans
< 0.0f
)
1523 // the height of rounded corner is higher than the cube than use the org scale matrix
1524 //yScale /= (float)(1 + BOTTOM_THRESHOLD);
1525 zScale
/= (float)(m_RoundBarMesh
.bottomThreshold
);
1526 glm::mat4 orgTrans
= glm::translate(glm::vec3(0.0, 0.0, -1.0));
1527 glm::mat4 scale
= glm::scale(glm::vec3(xyScale
, xyScale
, zScale
));
1528 //MoveModelf(trans, angle, scale);
1529 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
1530 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* scale
* orgTrans
;
1534 // use different matrices for different parts
1535 glm::mat4 orgTrans
= glm::translate(glm::vec3(0.0, 0.0, -1.0));
1536 glm::mat4 topTrans
= glm::translate(glm::vec3(0.0, 0.0, actualZTrans
));
1537 glm::mat4 topScale
= glm::scale(glm::vec3(xyScale
, xyScale
, xyScale
));
1538 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
1539 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* topTrans
* topScale
* orgTrans
;
1541 m_Model
= m_ScrollMoveMatrix
* m_GlobalScaleMatrix
* m_Model
;
1544 glm::mat3
normalMatrix(m_Model
);
1545 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
1546 glUniformMatrix4fv(maResources
.m_3DModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1547 glUniformMatrix3fv(maResources
.m_3DNormalMatrixID
, 1, GL_FALSE
, &normalInverseTranspos
[0][0]);
1551 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
1552 glUniformMatrix4fv(maPickingResources
.m_ModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1553 glUniformMatrix4fv(maPickingResources
.m_MatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
1554 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &extrude3D
.id
[0]);
1556 glDrawElements(GL_TRIANGLES
, extrude3D
.size
[TOP_SURFACE
], GL_UNSIGNED_SHORT
, reinterpret_cast<GLvoid
*>(extrude3D
.startIndex
[TOP_SURFACE
]));
1559 void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo
& extrude3D
)
1561 float xScale
= extrude3D
.xScale
;
1562 float yScale
= extrude3D
.yScale
;
1563 float zScale
= extrude3D
.zScale
;
1564 glm::mat4 transformMatrix
= glm::translate(glm::vec3(extrude3D
.xTransform
, extrude3D
.yTransform
, extrude3D
.zTransform
));
1565 glm::mat4 scaleMatrix
= glm::scale(glm::vec3(xScale
, yScale
, zScale
));
1566 m_Model
= transformMatrix
* extrude3D
.rotation
* scaleMatrix
;
1567 if (extrude3D
.reverse
)
1569 glm::mat4 reverseMatrix
= glm::translate(glm::vec3(0.0, 0.0, -1.0));
1570 m_Model
= m_Model
* reverseMatrix
;
1572 m_Model
= m_ScrollMoveMatrix
* m_GlobalScaleMatrix
* m_Model
;
1575 glm::mat3
normalMatrix(m_Model
);
1576 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
1577 glUniformMatrix4fv(maResources
.m_3DModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1578 glUniformMatrix3fv(maResources
.m_3DNormalMatrixID
, 1, GL_FALSE
, &normalInverseTranspos
[0][0]);
1582 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
1583 glUniformMatrix4fv(maPickingResources
.m_ModelID
, 1, GL_FALSE
, &m_Model
[0][0]);
1584 glUniformMatrix4fv(maPickingResources
.m_MatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
1585 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &extrude3D
.id
[0]);
1587 glDrawArrays(GL_TRIANGLES
, 0, 36);
1590 void OpenGL3DRenderer::RenderExtrudeSurface(const Extrude3DInfo
& extrude3D
)
1592 RenderExtrudeMiddleSurface(extrude3D
);
1593 // check reverse flag to decide whether to render the top middle
1594 if (extrude3D
.reverse
)
1596 RenderExtrudeBottomSurface(extrude3D
);
1597 RenderExtrudeFlatSurface(extrude3D
, FLAT_TOP_SURFACE
);
1601 RenderExtrudeTopSurface(extrude3D
);
1602 RenderExtrudeFlatSurface(extrude3D
, FLAT_BOTTOM_SURFACE
);
1605 void OpenGL3DRenderer::ReleaseExtrude3DShapes()
1607 m_Extrude3DList
.clear();
1610 void OpenGL3DRenderer::RenderExtrude3DObject()
1613 glEnable(GL_DEPTH_TEST
);
1614 glEnable(GL_CULL_FACE
);
1615 glCullFace(GL_BACK
);
1619 glUseProgram(maPickingResources
.m_CommonProID
);
1620 glUniform1fv(maPickingResources
.m_MinCoordXID
, 1, &m_fMinCoordX
);
1621 glUniform1fv(maPickingResources
.m_MaxCoordXID
, 1, &m_fMaxCoordX
);
1625 glUseProgram(maResources
.m_3DProID
);
1626 glUniformMatrix4fv(maResources
.m_3DViewID
, 1, GL_FALSE
, &m_3DView
[0][0]);
1627 glUniformMatrix4fv(maResources
.m_3DProjectionID
, 1, GL_FALSE
, &m_3DProjection
[0][0]);
1629 if (maResources
.m_b330Support
)
1632 Update3DUniformBlock();
1637 glUniform1fv(maResources
.m_3DMinCoordXID
, 1, &m_fMinCoordX
);
1638 glUniform1fv(maResources
.m_3DMaxCoordXID
, 1, &m_fMaxCoordX
);
1639 glUniform1i(maResources
.m_3DUndrawID
, m_bUndrawFlag
);
1640 //update light information
1641 glUniform4fv(maResources
.m_3DLightColorID
, m_iLightNum
, reinterpret_cast<GLfloat
*>(m_LightColor
));
1642 glUniform4fv(maResources
.m_3DLightPosID
, m_iLightNum
, reinterpret_cast<GLfloat
*>(m_PositionWorldspace
));
1643 glUniform1fv(maResources
.m_3DLightPowerID
, m_iLightNum
, m_fLightPower
);
1644 glUniform1i(maResources
.m_3DLightNumID
, m_iLightNum
);
1645 glUniform4fv(maResources
.m_3DLightAmbientID
, 1, &m_Ambient
[0]);
1649 size_t extrude3DNum
= m_Extrude3DList
.size();
1650 for (size_t i
= 0; i
< extrude3DNum
; i
++)
1652 Extrude3DInfo extrude3DInfo
= m_Extrude3DList
[i
];
1653 GLuint vertexBuf
= extrude3DInfo
.rounded
? m_CubeVertexBuf
: m_BoundBox
;
1654 GLuint normalBuf
= extrude3DInfo
.rounded
? m_CubeNormalBuf
: m_BoundBoxNormal
;
1657 glUniform4fv(maPickingResources
.m_2DColorID
, 1, &extrude3DInfo
.id
[0]);
1658 // 1st attribute buffer : vertices
1660 GLint aVertexID
= mbPickingMode
? maPickingResources
.m_2DVertexID
: maResources
.m_3DVertexID
;
1661 glEnableVertexAttribArray(aVertexID
);
1662 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuf
);
1663 glVertexAttribPointer(aVertexID
, // attribute
1666 GL_FALSE
, // normalized?
1668 (void*)0 // array buffer offset
1673 // 2nd attribute buffer : normals
1674 glEnableVertexAttribArray(maResources
.m_3DNormalID
);
1675 glBindBuffer(GL_ARRAY_BUFFER
, normalBuf
);
1676 glVertexAttribPointer(maResources
.m_3DNormalID
, // attribute
1679 GL_FALSE
, // normalized?
1681 (void*)0 // array buffer offset
1686 if (maResources
.m_b330Support
)
1688 glBindBuffer(GL_UNIFORM_BUFFER
, m_3DUBOBuffer
);
1689 glBufferSubData(GL_UNIFORM_BUFFER
, m_3DActualSizeLight
, sizeof(MaterialParameters
), &extrude3DInfo
.material
);
1691 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
1695 //update meterial information
1696 glUniform4fv(maResources
.m_3DMaterialAmbientID
, 1, &extrude3DInfo
.material
.ambient
[0]);
1697 glUniform4fv(maResources
.m_3DMaterialDiffuseID
, 1, &extrude3DInfo
.material
.diffuse
[0]);
1698 glUniform4fv(maResources
.m_3DMaterialSpecularID
, 1, &extrude3DInfo
.material
.specular
[0]);
1699 glUniform4fv(maResources
.m_3DMaterialColorID
, 1, &extrude3DInfo
.material
.materialColor
[0]);
1700 glUniform1i(maResources
.m_3DMaterialTwoSidesID
, extrude3DInfo
.material
.twoSidesLighting
);
1701 glUniform1f(maResources
.m_3DMaterialShininessID
, extrude3DInfo
.material
.shininess
);
1704 extrude3DInfo
.reverse
= 0;
1705 if (extrude3DInfo
.rounded
)
1707 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, m_CubeElementBuf
);
1708 RenderExtrudeSurface(extrude3DInfo
);
1709 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
1713 RenderNonRoundedBar(extrude3DInfo
);
1715 glDisableVertexAttribArray(aVertexID
);
1717 glDisableVertexAttribArray(maResources
.m_3DNormalID
);
1720 glBindBuffer(GL_ARRAY_BUFFER
, 0);
1721 glDisable(GL_CULL_FACE
);
1724 void OpenGL3DRenderer::CreateScreenTextTexture(
1725 const boost::shared_array
<sal_uInt8
> &bitmapBuf
,
1726 const ::Size
& rSizePixels
, const glm::vec2
& vTopLeft
,
1727 const glm::vec2
& vBottomRight
, const glm::vec3
& vPos
,
1728 const glm::vec4
& vScreenTextColor
, sal_uInt32 nUniqueId
)
1730 long bmpWidth
= rSizePixels
.Width();
1731 long bmpHeight
= rSizePixels
.Height();
1734 aTextInfo
.id
= getColorAsVector(nUniqueId
);
1735 aTextInfo
.uniqueId
= nUniqueId
;
1736 aTextInfo
.vertex
[0] = vBottomRight
.x
;
1737 aTextInfo
.vertex
[1] = vBottomRight
.y
;
1738 aTextInfo
.vertex
[2] = 0;
1740 aTextInfo
.vertex
[3] = vBottomRight
.x
;
1741 aTextInfo
.vertex
[4] = vTopLeft
.y
;
1742 aTextInfo
.vertex
[5] = 0;
1744 aTextInfo
.vertex
[6] = vTopLeft
.x
;
1745 aTextInfo
.vertex
[7] = vTopLeft
.y
;
1746 aTextInfo
.vertex
[8] = 0;
1748 aTextInfo
.vertex
[9] = vTopLeft
.x
;
1749 aTextInfo
.vertex
[10] = vBottomRight
.y
;
1750 aTextInfo
.vertex
[11] = 0;
1751 aTextInfo
.pos
= vPos
;
1752 aTextInfo
.textColor
= vScreenTextColor
;
1755 glGenTextures(1, &aTextInfo
.texture
);
1757 glBindTexture(GL_TEXTURE_2D
, aTextInfo
.texture
);
1759 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
1761 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
1763 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1765 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1767 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, bmpWidth
, bmpHeight
, 0, GL_RGB
, GL_UNSIGNED_BYTE
, bitmapBuf
.get());
1769 glBindTexture(GL_TEXTURE_2D
, 0);
1771 m_ScreenTextInfoList
.push_back(aTextInfo
);
1772 m_ScreenTexturelist
.push_back(aTextInfo
.texture
);
1775 void OpenGL3DRenderer::CreateTextTextureSingle(const boost::shared_array
<sal_uInt8
> &bitmapBuf
,
1776 const ::Size
& rSizePixels
,
1777 const glm::vec3
& vTopLeft
, const glm::vec3
& vTopRight
,
1778 const glm::vec3
& vBottomRight
, const glm::vec3
& vBottomLeft
,
1779 sal_uInt32 nUniqueId
)
1781 long bmpWidth
= rSizePixels
.Width();
1782 long bmpHeight
= rSizePixels
.Height();
1785 aTextInfo
.id
= getColorAsVector(nUniqueId
);
1786 aTextInfo
.vertex
[0] = vBottomRight
.x
;
1787 aTextInfo
.vertex
[1] = vBottomRight
.y
;
1788 aTextInfo
.vertex
[2] = vBottomRight
.z
;
1790 aTextInfo
.vertex
[3] = vTopRight
.x
;
1791 aTextInfo
.vertex
[4] = vTopRight
.y
;
1792 aTextInfo
.vertex
[5] = vTopRight
.z
;
1794 aTextInfo
.vertex
[9] = vBottomLeft
.x
;
1795 aTextInfo
.vertex
[10] = vBottomLeft
.y
;
1796 aTextInfo
.vertex
[11] = vBottomLeft
.z
;
1798 aTextInfo
.vertex
[6] = vTopLeft
.x
;
1799 aTextInfo
.vertex
[7] = vTopLeft
.y
;
1800 aTextInfo
.vertex
[8] = vTopLeft
.z
;
1803 glGenTextures(1, &aTextInfo
.texture
);
1805 glBindTexture(GL_TEXTURE_2D
, aTextInfo
.texture
);
1807 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1809 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1811 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, bmpWidth
, bmpHeight
, 0, GL_RGB
, GL_UNSIGNED_BYTE
, bitmapBuf
.get());
1813 glBindTexture(GL_TEXTURE_2D
, 0);
1815 m_TextInfoList
.push_back(aTextInfo
);
1816 m_Texturelist
.push_back(aTextInfo
.texture
);
1820 void OpenGL3DRenderer::CreateTextTextureBatch(const boost::shared_array
<sal_uInt8
> &bitmapBuf
,
1821 const ::Size
& rSizePixels
,
1822 const glm::vec3
& vTopLeft
, const glm::vec3
& vTopRight
,
1823 const glm::vec3
& vBottomRight
, const glm::vec3
& vBottomLeft
,
1824 sal_uInt32 nUniqueId
)
1826 long bmpWidth
= rSizePixels
.Width();
1827 long bmpHeight
= rSizePixels
.Height();
1828 glm::vec4 id
= getColorAsVector(nUniqueId
);
1829 m_TextInfoBatch
.idList
.push_back(id
);
1830 m_TextInfoBatch
.vertexList
.push_back(glm::vec3(vBottomRight
.x
, vBottomRight
.y
, vBottomRight
.z
));
1831 m_TextInfoBatch
.vertexList
.push_back(glm::vec3(vTopRight
.x
, vTopRight
.y
, vTopRight
.z
));
1832 m_TextInfoBatch
.vertexList
.push_back(glm::vec3(vTopLeft
.x
, vTopLeft
.y
, vTopLeft
.z
));
1833 m_TextInfoBatch
.vertexList
.push_back(glm::vec3(vBottomLeft
.x
, vBottomLeft
.y
, vBottomLeft
.z
));
1834 //find the last vector, which size is small than default batch number;
1836 while ((m_TextInfoBatch
.texture
.size() > 0) &&
1837 (m_TextInfoBatch
.texture
[index
].subTextureNum
>= m_TextInfoBatch
.batchNum
) &&
1838 (index
< m_TextInfoBatch
.texture
.size() - 1))
1842 //if the sub texture number of the last texture array reach the largest, create a new textur array
1843 if ((m_TextInfoBatch
.texture
.size() == 0) ||
1844 (m_TextInfoBatch
.texture
[index
].subTextureNum
>= m_TextInfoBatch
.batchNum
))
1846 TextureArrayInfo textureArray
;
1847 glGenTextures(1, &textureArray
.textureID
);
1849 glBindTexture(GL_TEXTURE_2D_ARRAY
, textureArray
.textureID
);
1850 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1851 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1852 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1853 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
1855 textureArray
.textureArrayWidth
= bmpHeight
* 8;
1856 textureArray
.textureArrayHeight
= bmpHeight
;
1857 glTexImage3D(GL_TEXTURE_2D_ARRAY
, 0, GL_RGB
, textureArray
.textureArrayWidth
, textureArray
.textureArrayHeight
,
1858 m_TextInfoBatch
.batchNum
, 0, GL_RGB
, GL_UNSIGNED_BYTE
, NULL
);
1860 if (m_TextInfoBatch
.texture
.size() > 0)
1864 m_TextInfoBatch
.texture
.push_back(textureArray
);
1865 glBindTexture(GL_TEXTURE_2D_ARRAY
, 0);
1867 glBindTexture(GL_TEXTURE_2D_ARRAY
, m_TextInfoBatch
.texture
[index
].textureID
);
1869 glTexSubImage3D(GL_TEXTURE_2D_ARRAY
, 0, 0, 0, m_TextInfoBatch
.texture
[index
].subTextureNum
, bmpWidth
, bmpHeight
, 1, GL_RGB
, GL_UNSIGNED_BYTE
, bitmapBuf
.get());
1871 //calc texture coordinate
1872 m_TextInfoBatch
.textureCoordList
.push_back(glm::vec3((float)bmpWidth
/ (float)m_TextInfoBatch
.texture
[index
].textureArrayWidth
,
1874 m_TextInfoBatch
.texture
[index
].subTextureNum
));
1875 m_TextInfoBatch
.textureCoordList
.push_back(glm::vec3((float)bmpWidth
/ (float)m_TextInfoBatch
.texture
[index
].textureArrayWidth
,
1876 (float)bmpHeight
/ (float)m_TextInfoBatch
.texture
[index
].textureArrayHeight
,
1877 m_TextInfoBatch
.texture
[index
].subTextureNum
));
1878 m_TextInfoBatch
.textureCoordList
.push_back(glm::vec3(0,
1879 (float)bmpHeight
/ (float)m_TextInfoBatch
.texture
[index
].textureArrayHeight
,
1880 m_TextInfoBatch
.texture
[index
].subTextureNum
));
1881 m_TextInfoBatch
.textureCoordList
.push_back(glm::vec3(0,
1883 m_TextInfoBatch
.texture
[index
].subTextureNum
));
1884 m_TextInfoBatch
.texture
[index
].subTextureNum
++;
1885 glBindTexture(GL_TEXTURE_2D_ARRAY
, 0);
1888 void OpenGL3DRenderer::CreateTextTexture(const boost::shared_array
<sal_uInt8
> &bitmapBuf
,
1889 const ::Size
& rSizePixels
,
1890 const glm::vec3
& vTopLeft
, const glm::vec3
& vTopRight
,
1891 const glm::vec3
& vBottomRight
, const glm::vec3
& vBottomLeft
,
1892 sal_uInt32 nUniqueId
)
1894 if (maResources
.mbTexBatchSupport
)
1896 CreateTextTextureBatch(bitmapBuf
, rSizePixels
, vTopLeft
, vTopRight
, vBottomRight
, vBottomLeft
, nUniqueId
);
1900 CreateTextTextureSingle(bitmapBuf
, rSizePixels
, vTopLeft
, vTopRight
, vBottomRight
, vBottomLeft
, nUniqueId
);
1904 void OpenGL3DRenderer::ReleaseTextShapes()
1906 m_TextInfoList
.clear();
1909 void OpenGL3DRenderer::ReleaseTextTexture()
1911 for (size_t i
= 0; i
< m_Texturelist
.size(); i
++)
1913 glDeleteTextures(1, &m_Texturelist
[i
]);
1915 m_Texturelist
.clear();
1918 void OpenGL3DRenderer::ReleaseScreenTextShapes()
1920 m_ScreenTextInfoList
.clear();
1923 void OpenGL3DRenderer::ReleaseScreenTextTexture()
1925 for (size_t i
= 0; i
< m_ScreenTexturelist
.size(); i
++)
1927 glDeleteTextures(1, &m_ScreenTexturelist
[i
]);
1929 m_ScreenTexturelist
.clear();
1933 void OpenGL3DRenderer::RenderScreenTextShape()
1937 glUseProgram(maResources
.m_ScreenTextProID
);
1939 for (size_t i
= 0; i
< m_ScreenTextInfoList
.size(); i
++)
1941 TextInfo textInfo
= m_ScreenTextInfoList
[i
];
1942 //calc the position and check whether it can be displayed
1943 if (textInfo
.uniqueId
)
1945 glm::vec3 worldPos
= glm::vec3(m_ScrollMoveMatrix
* m_GlobalScaleMatrix
* glm::vec4(textInfo
.pos
, 1));
1946 if ((worldPos
.x
< m_fMinCoordX
) || (worldPos
.x
> m_fMaxCoordX
))
1948 glm::vec4 pos
= m_3DProjection
* m_3DView
* glm::vec4(worldPos
, 1);
1949 const float xTrans
= pos
.x
/ pos
.w
;
1950 const float yTrans
= pos
.y
/ pos
.w
;
1951 for (int j
= 0; j
< 12; j
++)
1955 textInfo
.vertex
[j
] += xTrans
;
1959 textInfo
.vertex
[j
] += yTrans
;
1963 glUniform4fv(maResources
.m_ScreenTextColorID
, 1, &textInfo
.textColor
[0]);
1964 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
1966 glBufferData(GL_ARRAY_BUFFER
, sizeof(textInfo
.vertex
), textInfo
.vertex
, GL_STATIC_DRAW
);
1969 // 1rst attribute buffer : vertices
1970 glEnableVertexAttribArray(maResources
.m_ScreenTextVertexID
);
1971 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
1972 glVertexAttribPointer(
1973 maResources
.m_ScreenTextVertexID
,
1976 GL_FALSE
, // normalized?
1978 (void*)0 // array buffer offset
1982 glEnableVertexAttribArray(maResources
.m_ScreenTextTexCoordID
);
1983 glBindBuffer(GL_ARRAY_BUFFER
, m_TextTexCoordBuf
);
1984 glVertexAttribPointer(
1985 maResources
.m_ScreenTextTexCoordID
,
1988 GL_FALSE
, // normalized?
1990 (void*)0 // array buffer offset
1994 glBindTexture(GL_TEXTURE_2D
, textInfo
.texture
);
1996 glUniform1i(maResources
.m_ScreenTextTexID
, 0);
1998 //TODO: moggi: get rid fo GL_QUADS
1999 glDrawArrays(GL_QUADS
, 0, 4);
2002 glDisableVertexAttribArray(maResources
.m_ScreenTextTexCoordID
);
2004 glDisableVertexAttribArray(maResources
.m_ScreenTextVertexID
);
2006 glBindTexture(GL_TEXTURE_2D
, 0);
2010 void OpenGL3DRenderer::ReleaseTextShapesBatch()
2012 for (size_t i
= 0; i
< m_TextInfoBatch
.texture
.size(); i
++)
2014 m_TextInfoBatch
.texture
[i
].subTextureNum
= 0;
2016 m_TextInfoBatch
.vertexList
.clear();
2017 m_TextInfoBatch
.textureCoordList
.clear();
2018 m_TextInfoBatch
.idList
.clear();
2021 void OpenGL3DRenderer::RenderTextShapeBatch()
2023 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_GlobalScaleMatrix
;
2024 glUseProgram(maResources
.m_BatchTextProID
);
2026 glUniformMatrix4fv(maResources
.m_BatchTextMatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
2027 glEnableVertexAttribArray(maResources
.m_BatchTextVertexID
);
2028 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
2029 glVertexAttribPointer(
2030 maResources
.m_BatchTextVertexID
,
2033 GL_FALSE
, // normalized?
2035 (void*)0 // array buffer offset
2039 glEnableVertexAttribArray(maResources
.m_BatchTextTexCoordID
);
2040 glBindBuffer(GL_ARRAY_BUFFER
, m_TextTexCoordBufBatch
);
2042 glVertexAttribPointer(
2043 maResources
.m_BatchTextTexCoordID
,
2046 GL_FALSE
, // normalized?
2048 (void*)0 // array buffer offset
2050 //use texture array to get the vertex
2051 for (size_t i
= 0; i
< m_TextInfoBatch
.texture
.size(); i
++)
2053 int vertexNum
= m_TextInfoBatch
.texture
[i
].subTextureNum
;
2054 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
2056 glBufferData(GL_ARRAY_BUFFER
, 4 * vertexNum
* sizeof(glm::vec3
), &m_TextInfoBatch
.vertexList
[4 * i
* m_TextInfoBatch
.batchNum
], GL_STATIC_DRAW
);
2057 glBindBuffer(GL_ARRAY_BUFFER
, m_TextTexCoordBufBatch
);
2059 glBufferData(GL_ARRAY_BUFFER
, 4 * vertexNum
* sizeof(glm::vec3
), &m_TextInfoBatch
.textureCoordList
[4 * i
* m_TextInfoBatch
.batchNum
], GL_STATIC_DRAW
);
2060 glBindTexture(GL_TEXTURE_2D_ARRAY
, m_TextInfoBatch
.texture
[i
].textureID
);
2062 glUniform1i(maResources
.m_BatchTextTexID
, 0);
2064 //TODO: moggi: get rid fo GL_QUADS
2065 glDrawArrays(GL_QUADS
, 0, 4 * vertexNum
);
2067 glDisableVertexAttribArray(maResources
.m_BatchTextVertexID
);
2069 glDisableVertexAttribArray(maResources
.m_BatchTextTexCoordID
);
2071 glBindTexture(GL_TEXTURE_2D_ARRAY
, 0);
2075 void OpenGL3DRenderer::RenderTextShape()
2078 for (size_t i
= 0; i
< m_TextInfoList
.size(); i
++)
2080 TextInfo
&textInfo
= m_TextInfoList
[i
];
2081 PosVecf3 trans
= {0, 0, 0};
2082 PosVecf3 angle
= {0.0f
, 0.0f
, 0.0f
};
2083 PosVecf3 scale
= {1.0, 1.0, 1.0f
};
2084 MoveModelf(trans
, angle
, scale
);
2085 m_Model
= m_GlobalScaleMatrix
* m_Model
;
2086 glm::mat4 aMVP
= m_3DProjection
* m_3DView
* m_Model
;
2087 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
2089 glBufferData(GL_ARRAY_BUFFER
, sizeof(textInfo
.vertex
), textInfo
.vertex
, GL_STATIC_DRAW
);
2091 glUseProgram(maResources
.m_TextProID
);
2094 glUniformMatrix4fv(maResources
.m_TextMatrixID
, 1, GL_FALSE
, &aMVP
[0][0]);
2095 // 1rst attribute buffer : vertices
2096 glEnableVertexAttribArray(maResources
.m_TextVertexID
);
2097 glBindBuffer(GL_ARRAY_BUFFER
, m_VertexBuffer
);
2098 glVertexAttribPointer(
2099 maResources
.m_TextVertexID
,
2102 GL_FALSE
, // normalized?
2104 (void*)0 // array buffer offset
2108 glEnableVertexAttribArray(maResources
.m_TextTexCoordID
);
2109 glBindBuffer(GL_ARRAY_BUFFER
, m_TextTexCoordBuf
);
2110 glVertexAttribPointer(
2111 maResources
.m_TextTexCoordID
,
2114 GL_FALSE
, // normalized?
2116 (void*)0 // array buffer offset
2120 glBindTexture(GL_TEXTURE_2D
, textInfo
.texture
);
2122 glUniform1i(maResources
.m_TextTexID
, 0);
2124 //TODO: moggi: get rid fo GL_QUADS
2125 glDrawArrays(GL_QUADS
, 0, 4);
2127 glDisableVertexAttribArray(maResources
.m_TextTexCoordID
);
2129 glDisableVertexAttribArray(maResources
.m_TextVertexID
);
2131 glBindTexture(GL_TEXTURE_2D
, 0);
2137 void OpenGL3DRenderer::CreateSceneBoxView()
2139 m_CameraInfo
.cameraPos
= glm::vec3(m_GlobalScaleMatrix
* glm::vec4(m_CameraInfo
.cameraPos
, 1.0));
2140 m_CameraInfo
.cameraOrg
= glm::vec3(m_GlobalScaleMatrix
* glm::vec4(m_CameraInfo
.cameraOrg
, 1.0));
2141 m_3DView
= glm::lookAt(m_CameraInfo
.cameraPos
,
2142 m_CameraInfo
.cameraOrg
,
2143 m_CameraInfo
.cameraUp
);
2144 m_3DView
= m_3DView
+ m_matDiff
;
2147 void OpenGL3DRenderer::AddMatrixDiff(const glm::mat4
& aMat
)
2149 m_matDiff
= m_matDiff
+ aMat
;
2152 void OpenGL3DRenderer::ResetMatrixDiff()
2154 m_matDiff
= glm::mat4(0.0);
2157 void OpenGL3DRenderer::ClearBuffer()
2160 glDisable(GL_DEPTH_TEST
);
2163 #if defined(IOS) || defined(ANDROID)
2164 glClearDepthf(1.0f
);
2169 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
2173 * TODO: moggi: use a shader!!!
2175 glColor3f (0.3f, 0.3f, 0.3f);
2176 glVertex3f (-1.0f, -1.0f, -1.0f);
2177 glVertex3f (1.0f, -1.0f, -1.0f);
2179 glColor3f (0.0f, 0.0f, 0.0f);
2180 glVertex3f (1.0f, 1.0f, -1.0f);
2181 glVertex3f (-1.0f, 1.0f, -1.0f);
2185 glEnable(GL_DEPTH_TEST
);
2189 void OpenGL3DRenderer::ProcessUnrenderedShape(bool bNewScene
)
2191 glViewport(0, 0, m_iWidth
, m_iHeight
);
2195 CreateSceneBoxView();
2197 CalcScrollMoveMatrix(bNewScene
);
2200 RenderPolygon3DObject();
2201 //Shape3DExtrudeObject
2203 RenderExtrude3DObject();
2206 if (maResources
.m_b330Support
)
2208 RenderBatchBars(bNewScene
);
2212 RenderExtrude3DObject();
2216 if (maResources
.mbTexBatchSupport
)
2218 RenderTextShapeBatch();
2224 // render screen text
2225 RenderScreenTextShape();
2227 OUString aFileName
= OUString("D://shaderout_") + OUString::number(m_iWidth
) + "_" + OUString::number(m_iHeight
) + ".png";
2228 OpenGLHelper::renderToFile(m_iWidth
, m_iHeight
, aFileName
);
2232 void OpenGL3DRenderer::MoveModelf(const PosVecf3
& trans
, const PosVecf3
& angle
, const PosVecf3
& scale
)
2234 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
2235 glm::mat4 aScaleMatrix
= glm::scale(glm::vec3(scale
.x
, scale
.y
, scale
.z
));
2236 glm::mat4 aRotationMatrix
= glm::eulerAngleYXZ(angle
.y
, angle
.x
, angle
.z
);
2237 m_Model
= aTranslationMatrix
* aRotationMatrix
* aScaleMatrix
;
2240 void OpenGL3DRenderer::SetPickingMode(bool bPickingMode
)
2242 mbPickingMode
= bPickingMode
;
2245 glBindFramebuffer(GL_FRAMEBUFFER
, mnPickingFbo
);
2246 glDisable(GL_MULTISAMPLE
);
2250 glBindFramebuffer(GL_FRAMEBUFFER
, 0);
2251 glEnable(GL_MULTISAMPLE
);
2255 sal_uInt32
OpenGL3DRenderer::GetPixelColorFromPoint(long nX
, long nY
)
2257 static sal_uInt32 nId
= 0;
2258 OUString aFileName
= "/home/moggi/work/picking_" + OUString::number(nId
++) + ".png";
2259 OpenGLHelper::renderToFile(m_iWidth
, m_iHeight
, aFileName
);
2260 boost::scoped_array
<sal_uInt8
> buf(new sal_uInt8
[4]);
2261 glReadPixels(nX
, m_iHeight
-nY
, 1, 1, GL_BGRA
, GL_UNSIGNED_BYTE
, buf
.get());
2262 Color
aColor(255-buf
[3], buf
[2], buf
[1], buf
[0]);
2263 return aColor
.GetColor();
2266 void OpenGL3DRenderer::ReleaseBatchBarInfo()
2268 for (int i
= 0; i
< 3; i
++)
2270 m_BarSurface
[i
].modelMatrixList
.clear();
2271 m_BarSurface
[i
].normalMatrixList
.clear();
2272 m_BarSurface
[i
].colorList
.clear();
2273 m_BarSurface
[i
].mapId2Color
.clear();
2277 void OpenGL3DRenderer::ReleaseShapes()
2279 ReleasePolygonShapes();
2280 ReleaseExtrude3DShapes();
2281 ReleaseTextShapes();
2282 //ReleaseScreenTextShapes();
2283 ReleaseBatchBarInfo();
2284 ReleaseTextShapesBatch();
2287 void OpenGL3DRenderer::GetBatchMiddleInfo(const Extrude3DInfo
&extrude3D
)
2289 float xyScale
= extrude3D
.xScale
;
2290 float zScale
= extrude3D
.zScale
;
2291 float actualZScale
= zScale
- m_RoundBarMesh
.bottomThreshold
* xyScale
;
2292 PosVecf3 trans
= {extrude3D
.xTransform
,
2293 extrude3D
.yTransform
,
2294 extrude3D
.zTransform
};
2295 if (actualZScale
< 0.0f
)
2301 glm::mat4 scale
= glm::scale(glm::vec3(xyScale
, xyScale
,actualZScale
));
2302 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
2303 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* scale
;
2306 m_Model
= m_GlobalScaleMatrix
* m_Model
;
2307 glm::mat3
normalMatrix(m_Model
);
2308 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
2309 m_BarSurface
[MIDDLE_SURFACE
].modelMatrixList
.push_back(m_Model
);
2310 m_BarSurface
[MIDDLE_SURFACE
].normalMatrixList
.push_back(normalInverseTranspos
);
2311 m_BarSurface
[MIDDLE_SURFACE
].colorList
.push_back(extrude3D
.material
.materialColor
);
2312 m_BarSurface
[MIDDLE_SURFACE
].mapId2Color
[extrude3D
.orgID
] = m_BarSurface
[MIDDLE_SURFACE
].colorList
.size() - 1;
2315 void OpenGL3DRenderer::GetBatchTopAndFlatInfo(const Extrude3DInfo
&extrude3D
)
2317 float xyScale
= extrude3D
.xScale
;
2318 float zScale
= extrude3D
.zScale
;
2319 float actualZTrans
= zScale
- m_RoundBarMesh
.bottomThreshold
* xyScale
;
2320 PosVecf3 trans
= {extrude3D
.xTransform
,
2321 extrude3D
.yTransform
,
2322 extrude3D
.zTransform
};
2323 glm::mat4 orgTrans
= glm::translate(glm::vec3(0.0, 0.0, -1.0));
2324 if (actualZTrans
< 0.0f
)
2326 // the height of rounded corner is higher than the cube than use the org scale matrix
2327 //yScale /= (float)(1 + BOTTOM_THRESHOLD);
2328 zScale
/= (float)(m_RoundBarMesh
.bottomThreshold
);
2329 glm::mat4 scale
= glm::scale(glm::vec3(xyScale
, xyScale
, zScale
));
2330 //MoveModelf(trans, angle, scale);
2331 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
2332 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* scale
* orgTrans
;
2336 // use different matrices for different parts
2337 glm::mat4 topTrans
= glm::translate(glm::vec3(0.0, 0.0, actualZTrans
));
2338 glm::mat4 topScale
= glm::scale(glm::vec3(xyScale
, xyScale
, xyScale
));
2339 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
2340 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* topTrans
* topScale
* orgTrans
;
2343 m_Model
= m_GlobalScaleMatrix
* m_Model
;
2344 glm::mat3
normalMatrix(m_Model
);
2345 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
2346 m_BarSurface
[TOP_SURFACE
].modelMatrixList
.push_back(m_Model
);
2347 m_BarSurface
[TOP_SURFACE
].normalMatrixList
.push_back(normalInverseTranspos
);
2348 m_BarSurface
[TOP_SURFACE
].colorList
.push_back(extrude3D
.material
.materialColor
);
2349 m_BarSurface
[TOP_SURFACE
].mapId2Color
[extrude3D
.orgID
] = m_BarSurface
[TOP_SURFACE
].colorList
.size() - 1;
2351 glm::mat4 aTranslationMatrix
= glm::translate(glm::vec3(trans
.x
, trans
.y
, trans
.z
));
2352 glm::mat4 flatScale
= glm::scale(glm::vec3(xyScale
, xyScale
, xyScale
));
2353 m_Model
= aTranslationMatrix
* extrude3D
.rotation
* flatScale
;
2354 m_Model
= m_GlobalScaleMatrix
* m_Model
;
2355 normalMatrix
= glm::mat3(m_Model
);
2356 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
2358 m_BarSurface
[FLAT_BOTTOM_SURFACE
].modelMatrixList
.push_back(m_Model
);
2359 m_BarSurface
[FLAT_BOTTOM_SURFACE
].normalMatrixList
.push_back(normalInverseTranspos
);
2360 m_BarSurface
[FLAT_BOTTOM_SURFACE
].colorList
.push_back(extrude3D
.material
.materialColor
);
2361 m_BarSurface
[FLAT_BOTTOM_SURFACE
].mapId2Color
[extrude3D
.orgID
] = m_BarSurface
[FLAT_BOTTOM_SURFACE
].colorList
.size() - 1;
2364 void OpenGL3DRenderer::GetBatchBarsInfo()
2366 for (size_t i
= 0; i
< m_Extrude3DList
.size(); i
++)
2368 Extrude3DInfo
&extrude3DInfo
= m_Extrude3DList
[i
];
2369 if (m_Extrude3DInfo
.rounded
)
2371 GetBatchTopAndFlatInfo(extrude3DInfo
);
2372 GetBatchMiddleInfo(extrude3DInfo
);
2376 glm::mat4 transformMatrix
= glm::translate(glm::vec3(extrude3DInfo
.xTransform
, extrude3DInfo
.yTransform
, extrude3DInfo
.zTransform
));
2377 glm::mat4 scaleMatrix
= glm::scale(glm::vec3(extrude3DInfo
.xScale
, extrude3DInfo
.yScale
, extrude3DInfo
.zScale
));
2378 m_Model
= transformMatrix
* extrude3DInfo
.rotation
* scaleMatrix
;
2379 m_Model
= m_GlobalScaleMatrix
* m_Model
;
2380 glm::mat3
normalMatrix(m_Model
);
2381 glm::mat3 normalInverseTranspos
= glm::inverseTranspose(normalMatrix
);
2382 m_BarSurface
[0].modelMatrixList
.push_back(m_Model
);
2383 m_BarSurface
[0].normalMatrixList
.push_back(normalInverseTranspos
);
2384 m_BarSurface
[0].colorList
.push_back(extrude3DInfo
.material
.materialColor
);
2385 m_BarSurface
[0].mapId2Color
[extrude3DInfo
.orgID
] = m_BarSurface
[0].colorList
.size() - 1;
2390 void OpenGL3DRenderer::SetHighLightBar(BatchBarInfo
&barInfo
)
2392 std::map
<sal_uInt32
, unsigned int> ::iterator it
= barInfo
.mapId2Color
.find(m_uiSelectID
);
2393 if (it
!= barInfo
.mapId2Color
.end())
2395 unsigned int idx
= it
->second
;
2396 barInfo
.selectBarColor
= barInfo
.colorList
[idx
];
2397 barInfo
.colorList
[idx
] = glm::vec4(1.0, 1.0, 1.0, 1.0);
2401 void OpenGL3DRenderer::DisableHighLightBar(BatchBarInfo
&barInfo
)
2403 std::map
<sal_uInt32
, unsigned int> ::iterator it
= barInfo
.mapId2Color
.find(m_uiSelectID
);
2404 if (it
!= barInfo
.mapId2Color
.end())
2406 unsigned int idx
= it
->second
;
2407 barInfo
.colorList
[idx
] = barInfo
.selectBarColor
;
2411 void OpenGL3DRenderer::StartClick(sal_uInt32
&selectID
)
2413 m_bHighLighting
= true;
2414 m_uiSelectID
= selectID
;
2415 for (unsigned int i
= 0; i
< 3; i
++)
2417 SetHighLightBar(m_BarSurface
[i
]);
2421 void OpenGL3DRenderer::EndClick()
2423 m_bHighLighting
= false;
2424 for (unsigned int i
= 0; i
< 3; i
++)
2426 DisableHighLightBar(m_BarSurface
[i
]);
2430 void OpenGL3DRenderer::SetScroll()
2432 maResources
.m_bScrollFlag
= true;
2435 void OpenGL3DRenderer::SetScrollSpeed(float scrollSpeed
)
2437 m_fScrollSpeed
= scrollSpeed
;
2439 void OpenGL3DRenderer::SetScrollDistance(float scrollDistance
)
2441 m_fScrollDistance
= scrollDistance
;
2444 void OpenGL3DRenderer::SetSceneEdge(float minCoordX
, float maxCoordX
)
2446 m_fMinCoordX
= minCoordX
* 0.01;
2447 m_fMaxCoordX
= maxCoordX
* 0.01;
2450 void OpenGL3DRenderer::CalcScrollMoveMatrix(bool bNewScene
)
2452 if (!maResources
.m_bScrollFlag
)
2455 m_fCurDistance
= -m_fScrollSpeed
;
2456 m_fCurDistance
+= m_fCurDistance
>= m_fScrollDistance
? 0.0f
: m_fScrollSpeed
;
2457 m_ScrollMoveMatrix
= glm::translate(glm::vec3(-m_fCurDistance
* 0.01, 0.0f
, 0.0f
));
2458 m_bUndrawFlag
= m_fCurDistance
>= m_fScrollDistance
;
2461 glm::mat4
OpenGL3DRenderer::GetDiffOfTwoCameras(const glm::vec3
& rBeginPos
, const glm::vec3
& rEndPos
, const glm::vec3
& rBeginDirection
, const glm::vec3
& rEndDirection
)
2463 glm::mat4 aBegin
= glm::lookAt(glm::vec3(m_GlobalScaleMatrix
* glm::vec4(rBeginPos
, 1.0)),
2464 glm::vec3(m_GlobalScaleMatrix
* glm::vec4(rBeginDirection
, 1.0)),
2465 glm::vec3(0, 0, 1));
2466 glm::mat4 aEnd
= glm::lookAt(glm::vec3(m_GlobalScaleMatrix
* glm::vec4(rEndPos
, 1.0)),
2467 glm::vec3(m_GlobalScaleMatrix
* glm::vec4(rEndDirection
, 1.0)),
2468 glm::vec3(0, 0, 1));
2469 return aEnd
- aBegin
;
2472 glm::mat4
OpenGL3DRenderer::GetDiffOfTwoCameras(const glm::vec3
& rEndPos
, const glm::vec3
& rEndDirection
)
2474 glm::mat4 aEnd
= glm::lookAt(glm::vec3(m_GlobalScaleMatrix
* glm::vec4(rEndPos
, 1.0)),
2475 glm::vec3(m_GlobalScaleMatrix
* glm::vec4(rEndDirection
, 1.0)),glm::vec3(0, 0, 1));
2476 return aEnd
- m_3DView
;
2479 glm::mat4
OpenGL3DRenderer::GetProjectionMatrix()
2481 return m_3DProjection
;
2484 glm::mat4
OpenGL3DRenderer::GetViewMatrix()
2489 glm::mat4
OpenGL3DRenderer::GetGlobalScaleMatrix()
2491 return m_GlobalScaleMatrix
;
2494 void OpenGL3DRenderer::RenderBatchBars(bool bNewScene
)
2496 if (m_BarSurface
[0].modelMatrixList
.empty())
2502 if (m_bHighLighting
)
2504 for (unsigned int i
= 0; i
< 3; i
++)
2506 SetHighLightBar(m_BarSurface
[i
]);
2510 glEnable(GL_DEPTH_TEST
);
2511 glEnable(GL_CULL_FACE
);
2512 glCullFace(GL_BACK
);
2513 glPolygonOffset(0.0f
, 0.0f
);
2514 glUseProgram(maResources
.m_3DBatchProID
);
2515 UpdateBatch3DUniformBlock();
2516 glBindBuffer(GL_UNIFORM_BUFFER
, m_Batch3DUBOBuffer
);
2517 glBufferSubData(GL_UNIFORM_BUFFER
, m_Batch3DActualSizeLight
, sizeof(MaterialParameters
), &m_Batchmaterial
);
2519 glBindBuffer(GL_UNIFORM_BUFFER
, 0);
2520 if (maResources
.m_bScrollFlag
)
2522 glUniform1fv(maResources
.m_3DBatchMinCoordXID
, 1, &m_fMinCoordX
);
2523 glUniform1fv(maResources
.m_3DBatchMaxCoordXID
, 1, &m_fMaxCoordX
);
2524 glUniform1i(maResources
.m_3DBatchUndrawID
, m_bUndrawFlag
);
2525 glUniformMatrix4fv(maResources
.m_3DBatchTransMatrixID
, 1, GL_FALSE
, &m_ScrollMoveMatrix
[0][0]);
2527 glUniformMatrix4fv(maResources
.m_3DBatchViewID
, 1, GL_FALSE
, &m_3DView
[0][0]);
2528 glUniformMatrix4fv(maResources
.m_3DBatchProjectionID
, 1, GL_FALSE
, &m_3DProjection
[0][0]);
2530 GLuint vertexBuf
= m_Extrude3DInfo
.rounded
? m_CubeVertexBuf
: m_BoundBox
;
2531 GLuint normalBuf
= m_Extrude3DInfo
.rounded
? m_CubeNormalBuf
: m_BoundBoxNormal
;
2533 glEnableVertexAttribArray(maResources
.m_3DBatchVertexID
);
2534 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuf
);
2535 glVertexAttribPointer(maResources
.m_3DBatchVertexID
, // attribute
2538 GL_FALSE
, // normalized?
2540 (void*)0 // array buffer offset
2543 glEnableVertexAttribArray(maResources
.m_3DBatchNormalID
);
2544 glBindBuffer(GL_ARRAY_BUFFER
, normalBuf
);
2545 glVertexAttribPointer(maResources
.m_3DBatchNormalID
, // attribute
2548 GL_FALSE
, // normalized?
2550 (void*)0 // array buffer offset
2553 for (unsigned int i
= 0; i
< 4 ; i
++)
2555 glEnableVertexAttribArray(maResources
.m_3DBatchModelID
+ i
);
2556 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchModelMatrixBuf
);
2557 glVertexAttribPointer(maResources
.m_3DBatchModelID
+ i
, 4, GL_FLOAT
, GL_FALSE
, sizeof(glm::mat4
), reinterpret_cast<GLvoid
*>(sizeof(GLfloat
) * i
* 4));
2558 glVertexAttribDivisor(maResources
.m_3DBatchModelID
+ i
, 1);
2561 for (unsigned int i
= 0; i
< 3 ; i
++)
2563 glEnableVertexAttribArray(maResources
.m_3DBatchNormalMatrixID
+ i
);
2564 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchNormalMatrixBuf
);
2565 glVertexAttribPointer(maResources
.m_3DBatchNormalMatrixID
+ i
, 3, GL_FLOAT
, GL_FALSE
, sizeof(glm::mat3
), reinterpret_cast<GLvoid
*>(sizeof(GLfloat
) * i
* 3));
2566 glVertexAttribDivisor(maResources
.m_3DBatchNormalMatrixID
+ i
, 1);
2568 glEnableVertexAttribArray(maResources
.m_3DBatchColorID
);
2569 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchColorBuf
);
2570 glVertexAttribPointer(maResources
.m_3DBatchColorID
, 4, GL_FLOAT
, GL_FALSE
, sizeof(glm::vec4
), 0);
2571 glVertexAttribDivisor(maResources
.m_3DBatchColorID
, 1);
2572 if (m_Extrude3DInfo
.rounded
)
2574 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, m_CubeElementBuf
);
2575 for (int i
= 0; i
< 2; i
++)
2577 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchModelMatrixBuf
);
2578 glBufferData(GL_ARRAY_BUFFER
, sizeof(glm::mat4
) * m_BarSurface
[i
].modelMatrixList
.size(), &m_BarSurface
[i
].modelMatrixList
[0][0], GL_DYNAMIC_DRAW
);
2579 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchNormalMatrixBuf
);
2580 glBufferData(GL_ARRAY_BUFFER
, sizeof(glm::mat3
) * m_BarSurface
[i
].normalMatrixList
.size(), &m_BarSurface
[i
].normalMatrixList
[0][0], GL_DYNAMIC_DRAW
);
2581 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchColorBuf
);
2582 glBufferData(GL_ARRAY_BUFFER
, sizeof(glm::vec4
) * m_BarSurface
[i
].colorList
.size(), &m_BarSurface
[i
].colorList
[0], GL_DYNAMIC_DRAW
);
2583 glDrawElementsInstancedBaseVertex(GL_TRIANGLES
,
2584 m_Extrude3DInfo
.size
[i
],
2586 reinterpret_cast<GLvoid
*>(m_Extrude3DInfo
.startIndex
[i
]),
2587 m_BarSurface
[i
].modelMatrixList
.size(),
2593 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchModelMatrixBuf
);
2594 glBufferData(GL_ARRAY_BUFFER
, sizeof(glm::mat4
) * m_BarSurface
[0].modelMatrixList
.size(), &m_BarSurface
[0].modelMatrixList
[0][0], GL_DYNAMIC_DRAW
);
2595 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchNormalMatrixBuf
);
2596 glBufferData(GL_ARRAY_BUFFER
, sizeof(glm::mat3
) * m_BarSurface
[0].normalMatrixList
.size(), &m_BarSurface
[0].normalMatrixList
[0][0], GL_DYNAMIC_DRAW
);
2597 glBindBuffer(GL_ARRAY_BUFFER
, m_BatchColorBuf
);
2598 glBufferData(GL_ARRAY_BUFFER
, sizeof(glm::vec4
) * m_BarSurface
[0].colorList
.size(), &m_BarSurface
[0].colorList
[0], GL_DYNAMIC_DRAW
);
2599 glDrawArraysInstanced(GL_TRIANGLES
, 0, 36, m_BarSurface
[0].modelMatrixList
.size());
2601 glDisableVertexAttribArray(maResources
.m_3DBatchVertexID
);
2602 glDisableVertexAttribArray(maResources
.m_3DBatchNormalID
);
2603 glDisableVertexAttribArray(maResources
.m_3DBatchColorID
);
2604 glVertexAttribDivisor(maResources
.m_3DBatchColorID
, 0);
2605 for (unsigned int i
= 0; i
< 4 ; i
++)
2607 glDisableVertexAttribArray(maResources
.m_3DBatchModelID
+ i
);
2608 glVertexAttribDivisor(maResources
.m_3DBatchModelID
+ i
, 0);
2610 for (unsigned int i
= 0; i
< 3 ; i
++)
2612 glDisableVertexAttribArray(maResources
.m_3DBatchNormalMatrixID
+ i
);
2613 glVertexAttribDivisor(maResources
.m_3DBatchNormalMatrixID
+ i
, 0);
2616 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, 0);
2617 glDisable(GL_CULL_FACE
);
2621 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */