59 #define ACG_POLYLINENODET_C 63 #include "PolyLineNodeT.hh" 64 #include <ACG/GL/gl.hh> 65 #include <ACG/GL/ShaderCache.hh> 66 #include <ACG/Utils/VSToolsT.hh> 77 template <
class PolyLine>
104 template <
class PolyLine>
112 template <
class PolyLine>
128 template <
class PolyLine>
140 template <
class PolyLine>
182 if (_drawMode & DrawModes::POINTS_COLORED)
191 if (_drawMode & DrawModes::POINTS_COLORED)
255 if (
polyline_.vertex_normals_available()) {
257 std::vector<Point> ps;
261 if (
polyline_.vertex_binormals_available())
273 int stride =
polyline_.vertex_binormals_available() ? 3 : 2;
276 glArrayElement(stride * i);
277 glArrayElement(stride * i + 1);
281 if (
polyline_.vertex_binormals_available()) {
285 glArrayElement(stride * i);
286 glArrayElement(stride * i + 2);
306 if(
polyline_.vertex_selections_available())
335 if(
polyline_.vertex_selections_available())
368 template <
class PolyLine>
395 pick_vertices( _state);
398 pick_spheres( _state);
401 pick_spheres_screen( _state);
409 pick_edges(_state, 0);
418 pick_vertices( _state);
421 pick_spheres( _state);
424 pick_spheres_screen( _state);
446 template <
class PolyLine>
457 glDepthRange(0.0, 0.999999);
461 if (pickShader && pickShader->isLinked())
478 pickShader->setUniform(
"mWVP", transform);
479 pickShader->setUniform(
"pickVertexOffset", pickOffsetIndex);
484 pickShader->disable();
499 glDepthRange(0.0, 1.0);
503 glPointSize(point_size_old);
510 template <
class PolyLine>
530 template <
class PolyLine>
560 template <
class PolyLine>
569 glDepthRange(0.0, 0.999999);
573 if (pickShader && pickShader->isLinked())
590 pickShader->setUniform(
"mWVP", transform);
591 pickShader->setUniform(
"pickVertexOffset", pickOffsetIndex);
594 glDrawArrays(GL_LINE_STRIP, 0, numIndices);
597 pickShader->disable();
611 for (
unsigned int i = 0; i < n_end; ++i) {
622 glDepthRange(0.0, 1.0);
628 template <
class PolyLine>
640 size_t curOffset = 12;
643 if (
polyline_.vertex_normals_available())
652 if (_colorSource == 1)
659 if (_colorSource == 2)
681 template <
class PolyLine>
688 for (
unsigned int i = 0; i <
polyline_.get_num_custom_properties(); ++i) {
690 typename PolyLine::CustomPropertyHandle proph =
polyline_.enumerate_custom_property_handles(i);
694 const void* propDataBuf =
polyline_.get_custom_property_buffer(proph);
696 typename std::map< typename PolyLine::CustomPropertyHandle, int >::iterator mapEntry =
polylinePropMap_.find(proph);
704 unsigned int propSize = 0;
733 char* vboData_ =
new char[bufferSize];
773 template <
class PolyLine>
781 unsigned char* ucdata = ((
unsigned char*)_dst) + byteOffset;
784 if (_colorSourceVertex)
795 for (
int i = 0; i < 3; ++i)
798 int ival = int(col[i] * 255.0);
799 ival = std::min(std::max(ival, 0), 255);
807 template <
class PolyLine>
813 float* fdata = (
float*)_dst;
816 for (
unsigned int j = 0 ; j < 3 ; ++j)
820 if (
polyline_.vertex_normals_available() )
821 for (
unsigned int j = 0 ; j < 3 ; ++j)
822 *(fdata++) =
polyline_.vertex_normal(_vertex)[j];
832 if (customElementOffset >= 0)
842 if (!elementInputStride)
843 elementInputStride = elementSize;
850 memcpy((
char*)_dst + ve->
getByteOffset(), src + elementInputStride * _vertex, elementSize);
857 template <
class PolyLine>
869 _state.
enable(GL_COLOR_MATERIAL);
870 _state.
enable(GL_LIGHTING);
873 ro.setMaterial(_mat);
886 ro.debugName =
"PolyLine";
897 for (
unsigned int i = 0; i < _drawMode.
getNumLayers(); ++i) {
911 ro.setMaterial(&localMaterial);
914 switch (props->primitive()) {
916 case ACG::SceneGraph::DrawModes::PRIMITIVE_POINT:
919 ro.debugName =
"polyline.Points.selected";
921 ro.setMaterial(&localMaterial);
939 ro.debugName =
"polyline.Points";
941 ro.setMaterial(&localMaterial);
961 case ACG::SceneGraph::DrawModes::PRIMITIVE_WIREFRAME:
962 case ACG::SceneGraph::DrawModes::PRIMITIVE_EDGE:
965 ro.debugName =
"polyline.Wireframe.selected";
967 ro.setMaterial(&localMaterial);
985 ro.debugName =
"polyline.Wireframe";
987 ro.setMaterial(&localMaterial);
1012 case ACG::SceneGraph::DrawModes::PRIMITIVE_POLYGON:
1039 if (
polyline_.vertex_selections_available())
1041 ro.debugName =
"polyline.Sphere.selected";
1042 localMaterial.
baseColor(selectionColor);
1043 ro.setMaterial(&localMaterial);
1054 radius = (p | viewDir) * r;
1063 ro.debugName =
"polyline.Sphere";
1065 ro.setMaterial(&localMaterial);
1076 radius = (p | viewDir) * r;
1095 template <
class PolyLine>
1101 customBuffers_.push_back( std::pair<ACG::VertexElement, const void*>(_desc, _buffer) );
1108 std::cerr <<
"PolyLineNodeT::addCustomBuffer - null pointer buffer" << std::endl;
1115 template <
class PolyLine>
const VertexElement * findElementByUsage(VERTEX_USAGE _usage) const
DrawModes::DrawMode availableDrawModes() const
return available draw modes
Vec3d eye() const
get eye point
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
unsigned int pick_current_index() const
Returns the current color picking index (can be used for caching)
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
Vec3d eye() const
get eye point
void pointSize(float _sz)
set point size (default: 1.0)
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
double fovy() const
get field of view in y direction
void draw(GLState &, const DrawModes::DrawMode &_drawMode)
draw lines and normals
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void deactivateFixedFunction() const
unsigned int getVertexStride(unsigned int i=0) const
Interface class between scenegraph and renderer.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
std::vector< std::pair< ACG::VertexElement, const void * > > customBuffers_
Custom vertex data for shader based rendering.
size_t n_edges() const
Get number of edges.
VectorT< float, 4 > Vec4f
void setCustomBuffer(int _id, const void *_buffer)
DrawMode WIREFRAME
draw wireframe
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
bool updateVBO_
Flag to trigger update of vbo.
PolyLine & polyline_
The associated poly line.
size_t getNumLayers() const
returns the layer count
void setVertexStride(unsigned int _stride)
int viewport_height() const
get viewport height
ACG::VertexDeclaration vertexDeclVCol_
Vertex layout with vertex colors.
void baseColor(const Vec4f &_c)
set the base color
static void genBuffersARB(GLsizei n, GLuint *buffers)
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
Class to define the vertex input layout.
const Vec4f & ambient_color() const
get ambient color
defined by user via VertexElement::shaderInputName_
unsigned int type_
GL_FLOAT, GL_UNSIGNED_BYTE, GL_INT, ...
unsigned int vbo_
VBO used to render the poly line.
void writeVertex(unsigned int _vertex, void *_dst)
Write vertex data for rendering to a buffer.
DrawModes::DrawMode POINTS_SPHERES_SCREEN
This defines a local point spheres draw mode for all polyLine nodes with constant screen size...
bool is_closed() const
Check if the polyline is marked as closed.
static unsigned int getElementSize(const VertexElement *_pElement)
void activateShaderPipeline(GLSL::Program *_prog) const
ShaderGenDesc shaderDesc
Drawmode and other shader params.
void deactivateShaderPipeline(GLSL::Program *_prog) const
void writeVertexColor(unsigned int _vertex, bool _colorSourceVertex, void *_dst) const
Write color for rendering to a buffer.
std::map< typename PolyLine::CustomPropertyHandle, int > polylinePropMap_
Map from custom properties in PolyLine to id in customBuffers_.
ACG::VertexDeclaration vertexDecl_
Vertex layout without vertex colors.
DrawMode POINTS
draw unlighted points using the default base color
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
PickTarget
What target to use for picking.
void set_point_size(float _f)
set point size
float line_width() const
get line width
ACGDLLEXPORT const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased=false)
Add a custom DrawMode.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
static void enable(GLenum _cap)
replaces glEnable, but supports locking
VectorT< float, 3 > Vec3f
static void bufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
std::vector< Point > & points()
Get all points of the polyline.
ACG::VertexDeclaration vertexDeclECol_
Vertex layout with edge colors.
void applyRenderObjectSettings(DrawModes::DrawModePrimitive _primitive, RenderObject *_obj) const
Set shaders, textures and uniforms as provided by user to a render-object.
float point_size() const
get point size
int addCustomBuffer(const ACG::VertexElement &_desc, const void *_buffer)
Description of one vertex element.
void updateVBO()
Trigger an update of the vbo.
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
GLSphere * sphere_
Sphere for VertexSphere DrawMode.
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
unsigned int getByteOffset() const
const Vec4f & ambient_color() const
get ambient color
void setByteOffset(unsigned int _offset)
Point & point(unsigned int _i)
Get a point of the polyline.
bool colored() const
Are colors used?
unsigned int numElements_
how many elements of type_
const VertexElement * getElement(unsigned int i) const
void pick(GLState &_state, PickTarget _target)
picking
float point_size() const
get point size
DrawMode EDGES_COLORED
draw edges with colors (without shading)
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void setupVertexDeclaration(VertexDeclaration *_dst, int _colorSource) const
Create the vertex declaration.
Namespace providing different geometric functions concerning angles.
int viewport_width() const
get viewport width
picks verices (may not be implemented for all nodes)
std::vector< unsigned int > selectedEdgeIndexBuffer_
Index buffer for selected edges.
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
Scalar length() const
Compute the length of the polyline (in future cached method)
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
const char * shaderInputName_
set shader input name, if usage_ = VERTEX_USAGE_USER_DEFINED otherwise this is set automatically...
bool get_custom_property_shader_binding(CustomPropertyHandle _property_handle, unsigned int *_propsize, const char **_input_name, unsigned int *_datatype) const
Get shader binding information.
void addElement(const VertexElement *_pElement)
picks edges (may not be implemented for all nodes)
const GLMatrixd & projection() const
get projection matrix
int priority
Priority to allow sorting of objects.
Vec3d viewing_direction() const
get viewing ray
static unsigned int getElementSize(const VertexElement *_pElement)
const Vec4f & diffuse_color() const
get diffuse color
const GLMatrixd & modelview() const
get modelview matrix
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
static unsigned int getGLTypeSize(unsigned int _type)
unsigned int getByteOffset() const
double fovy() const
get field of view in y direction
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
pick any of the prior targets (should be implemented for all nodes)
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
size_t n_vertices() const
Get number of vertices.
int viewport_height() const
get viewport height
DrawModeProperties stores a set of properties that defines, how to render an object.
float line_width() const
get line width
void set_color(const Vec4f &_col)
set color
const Vec4f & diffuse_color() const
get diffuse color
~PolyLineNodeT()
Destructor.
DrawModes::DrawMode POINTS_SPHERES
This defines a local point spheres draw mode for all polyLine nodes.
void set_line_width(float _f)
set line width
std::vector< unsigned int > selectedVertexIndexBuffer_
Index buffer for selected vertices.
PolyLineNodeT(PolyLine &_pl, BaseNode *_parent=0, std::string _name="<PolyLineNode>")
Constructor.
void update()
Trigger an update of the vbo.
VectorT< double, 3 > Vec3d
VERTEX_USAGE usage_
position, normal, shader input ..
void activateFixedFunction() const
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
int findElementIdByUsage(VERTEX_USAGE _usage) const
Vec3d viewing_direction() const
get viewing ray
const void * pointer_
Offset in bytes to the first occurrence of this element in vertex buffer; Or address to vertex data i...