2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "scene-graph-dynamics-debug-renderer.h"
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/render/gl-resources/context.h>
24 #include <dali/internal/render/shaders/program.h>
25 #include <dali/internal/render/shaders/shader.h>
36 DynamicsDebugRenderer::DynamicsDebugRenderer(const Shader& debugShader)
37 : mShader(const_cast<Shader&>(debugShader)),
40 mViewMatrix(Matrix::IDENTITY),
41 mProjectionMatrix(Matrix::IDENTITY),
44 DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);
47 DynamicsDebugRenderer::~DynamicsDebugRenderer()
51 void DynamicsDebugRenderer::Initialize(Context& context)
53 DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);
58 void DynamicsDebugRenderer::UpdateMatrices( BufferIndex bufferIndex, const Matrix& projectionMatrix, const Matrix& viewMatrix )
60 mProjectionMatrix = projectionMatrix;
61 mViewMatrix = viewMatrix;
62 mBufferIndex = bufferIndex;
65 void DynamicsDebugRenderer::UpdateBuffer( const Integration::DynamicsDebugVertexContainer& vertices )
67 if( NULL != mContext )
71 mBuffer = new GpuBuffer(*mContext, GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW);
74 if( vertices.size() > 1 )
76 mBuffer->UpdateDataBuffer( vertices.size() * sizeof(vertices[0]), vertices.data() );
78 mNumberOfPoints = vertices.size();
82 void DynamicsDebugRenderer::Render()
84 if( mBuffer && mNumberOfPoints )
86 Integration::DynamicsDebugVertex* vertex = 0;
88 Program& program = mShader.Apply(*mContext, mBufferIndex, GEOMETRY_TYPE_IMAGE, Matrix::IDENTITY, Matrix::IDENTITY, mViewMatrix, mProjectionMatrix, Color::WHITE, SHADER_DEFAULT);
89 const GLint positionLoc = program.GetAttribLocation(Program::ATTRIB_POSITION);
90 const GLint colorLoc = program.GetAttribLocation(Program::ATTRIB_COLOR);
92 mContext->VertexAttribPointer(positionLoc, 3, GL_FLOAT, false, sizeof(Integration::DynamicsDebugVertex), (void*)&vertex->position);
93 mContext->VertexAttribPointer(colorLoc, 4, GL_FLOAT, false, sizeof(Integration::DynamicsDebugVertex), (void*)&vertex->color);
94 mContext->EnableVertexAttributeArray(positionLoc);
95 mContext->EnableVertexAttributeArray(colorLoc);
96 mContext->DrawArrays( GL_LINES, 0, mNumberOfPoints );
97 mContext->DisableVertexAttributeArray(positionLoc);
98 mContext->DisableVertexAttributeArray(colorLoc);
99 mContext->BindArrayBuffer( 0 );
104 } // namespace SceneGraph
106 } // namespace Internal