Commit 8864611b authored by Jan Möbius's avatar Jan Möbius

Merge branch 'acg_utils' into 'master'

Helper functions in ACG

New functions for implementing shader based picking in nodes.

See merge request !199
parents 04e8f854 f191b651
Pipeline #3722 passed with stage
in 69 minutes and 26 seconds
......@@ -229,6 +229,25 @@ void GLPrimitive::draw_primitive()
//------------------------------------------------------------------------
void GLPrimitive::draw_primitive(GLSL::Program* _program)
{
if (checkVBO())
{
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
vertexDecl_.activateShaderPipeline(_program);
if (numTris_)
glDrawArrays(GL_TRIANGLES, 0, numTris_ * 3);
else
glDrawArrays(GL_LINES, 0, numLines_ * 2);
vertexDecl_.deactivateShaderPipeline(_program);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
//------------------------------------------------------------------------
void GLPrimitive::addToRenderer_primitive( class IRenderer* _renderer, RenderObject* _ro )
{
if (checkVBO())
......
......@@ -80,9 +80,17 @@ public:
GLPrimitive();
virtual ~GLPrimitive();
// bind vbo + gl draw call
// bind vbo + gl draw call (fixed function mode)
// use this function in compatibility profile
void draw_primitive();
// activate vertex declaration + gl draw call (shader mode)
// _program may be nullptr, in that case the attribute locations are as follows.
// 0 : float3 position
// 1 : float3 normal
// 2 : float2 texcoord
void draw_primitive(GLSL::Program* _program);
// add to deferred draw call to renderer
void addToRenderer_primitive(class IRenderer* _renderer, struct RenderObject* _ro);
......
......@@ -59,6 +59,7 @@
#include <ACG/GL/acg_glew.hh>
#include "GLState.hh"
#include <OpenMesh/Core/Utils/vector_cast.hh>
#include <cstring>
......@@ -1070,6 +1071,19 @@ Vec4uc GLState::pick_get_name_color (size_t _idx)
//-----------------------------------------------------------------------------
Vec4f GLState::pick_get_name_color_norm (unsigned int _idx)
{
Vec4f rv(0.0f, 0.0f, 0.0f, 0.0f);
if (colorPicking_)
{
Vec4uc color_abs = colorStack_.getIndexColor(_idx);
rv = OpenMesh::vector_cast<Vec4f, Vec4uc>(color_abs) / 255.0f;
}
return rv;
}
//-----------------------------------------------------------------------------
void GLState::pick_push_name (size_t _idx)
{
colorStack_.pushIndex (_idx);
......
......@@ -1114,6 +1114,9 @@ public:
/// for each primitive
Vec4uc pick_get_name_color (size_t _idx);
/// same as pick_get_name_color, but the resulting color channels are normalized in [0.0, 1.0] range
Vec4f pick_get_name_color_norm (unsigned int _idx);
/// creates a new name the stack (like glPushName())
void pick_push_name (size_t _idx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment