2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include "scene-graph-dynamics-debug-renderer.h"
21 #include <dali/integration-api/debug.h>
22 #include <dali/internal/render/gl-resources/context.h>
23 #include <dali/internal/render/shaders/program.h>
24 #include <dali/internal/render/shaders/shader.h>
35 DynamicsDebugRenderer::DynamicsDebugRenderer(const Shader& debugShader)
36 : mShader(const_cast<Shader&>(debugShader)),
39 mViewMatrix(Matrix::IDENTITY),
40 mProjectionMatrix(Matrix::IDENTITY),
43 DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);
46 DynamicsDebugRenderer::~DynamicsDebugRenderer()
50 void DynamicsDebugRenderer::Initialize(Context& context)
52 DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);
57 void DynamicsDebugRenderer::UpdateMatrices( BufferIndex bufferIndex, const Matrix& projectionMatrix, const Matrix& viewMatrix )
59 mProjectionMatrix = projectionMatrix;
60 mViewMatrix = viewMatrix;
61 mBufferIndex = bufferIndex;
64 void DynamicsDebugRenderer::UpdateBuffer( const Integration::DynamicsDebugVertexContainer& vertices )
66 if( NULL != mContext )
70 mBuffer = new GpuBuffer(*mContext, GL_ARRAY_BUFFER, GL_STATIC_DRAW);
73 if( vertices.size() > 1 )
75 mBuffer->UpdateDataBuffer( vertices.size() * sizeof(vertices[0]), vertices.data() );
77 mNumberOfPoints = vertices.size();
81 void DynamicsDebugRenderer::Render()
83 if( mBuffer && mNumberOfPoints )
85 Integration::DynamicsDebugVertex* vertex = 0;
87 Program& program = mShader.Apply(*mContext, mBufferIndex, GEOMETRY_TYPE_IMAGE, Matrix::IDENTITY, Matrix::IDENTITY, mViewMatrix, mProjectionMatrix, Color::WHITE, SHADER_DEFAULT);
88 const GLint positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
89 const GLint colorLoc = program.GetAttribLocation(Program::ATTRIB_COLOR);
91 mContext->VertexAttribPointer(positionLoc, 3, GL_FLOAT, false, sizeof(Integration::DynamicsDebugVertex), (void*)&vertex->position);
92 mContext->VertexAttribPointer(colorLoc, 4, GL_FLOAT, false, sizeof(Integration::DynamicsDebugVertex), (void*)&vertex->color);
93 mContext->EnableVertexAttributeArray(positionLoc);
94 mContext->EnableVertexAttributeArray(colorLoc);
95 mContext->DrawArrays( GL_LINES, 0, mNumberOfPoints );
96 mContext->DisableVertexAttributeArray(positionLoc);
97 mContext->DisableVertexAttributeArray(colorLoc);
98 mContext->BindArrayBuffer( 0 );
103 } // namespace SceneGraph
105 } // namespace Internal