32 #ifndef DepthSortCallback_INCLUDE_ONCE 33 #define DepthSortCallback_INCLUDE_ONCE 101 typedef Point<unsigned int> PointUInt;
102 typedef Line<unsigned int> LineUInt;
103 typedef Triangle<unsigned int> TriangleUInt;
104 typedef Quad<unsigned int> QuadUInt;
106 typedef Point<unsigned short> PointUShort;
107 typedef Line<unsigned short> LineUShort;
108 typedef Triangle<unsigned short> TriangleUShort;
109 typedef Quad<unsigned short> QuadUShort;
111 typedef Point<unsigned char> PointUByte;
112 typedef Line<unsigned char> LineUByte;
113 typedef Triangle<unsigned char> TriangleUByte;
114 typedef Quad<unsigned char> QuadUByte;
119 PrimitiveZ(
int tri=0,
float z=0.0f): mPrimitiveIndex(tri), mZ(z) {}
120 unsigned int mPrimitiveIndex;
123 class Sorter_Back_To_Front
126 bool operator()(
const PrimitiveZ& t1,
const PrimitiveZ& t2)
const {
return t1.mZ < t2.mZ; }
128 class Sorter_Front_To_Back
131 bool operator()(
const PrimitiveZ& t1,
const PrimitiveZ& t2)
const {
return t1.mZ > t2.mZ; }
138 VL_DEBUG_SET_OBJECT_NAME()
179 for(
size_t i=0; i<verts->
size(); ++i)
185 for(
size_t idraw=0; idraw<geometry->
drawCalls().size(); ++idraw)
188 if (dc->classType() == DrawElementsUInt::Type())
191 if (dc->classType() == DrawElementsUShort::Type())
194 if (dc->classType() == DrawElementsUByte::Type())
199 template<
typename T,
typename deT>
200 void sort(deT* polys, std::vector<Point<T> >& sorted_points, std::vector<Line<T> >& sorted_lines, std::vector<Triangle<T> >& sorted_triangles, std::vector<Quad<T> >& sorted_quads)
202 if (polys->primitiveType() ==
PT_QUADS)
205 mPrimitiveZ.resize( polys->indexBuffer()->size() / 4 );
209 const typename deT::index_type* it = polys->indexBuffer()->begin();
210 const typename deT::index_type* end = polys->indexBuffer()->end();
211 for(
unsigned iz=0; it != end; it+=4, ++iz)
224 sorted_quads.resize( polys->indexBuffer()->size() / 4 );
225 Quad<T>* tris = (Quad<T>*)polys->indexBuffer()->ptr();
227 sorted_quads[i] = tris[
mPrimitiveZ[i].mPrimitiveIndex ];
228 memcpy(&tris[0], &sorted_quads[0],
sizeof(sorted_quads[0])*sorted_quads.size() );
234 mPrimitiveZ.resize( polys->indexBuffer()->size() / 3 );
238 const typename deT::index_type* it = polys->indexBuffer()->begin();
239 const typename deT::index_type* end = polys->indexBuffer()->end();
240 for(
unsigned iz=0; it != end; it+=3, ++iz)
253 sorted_triangles.resize( polys->indexBuffer()->size() / 3 );
254 Triangle<T>* tris = (Triangle<T>*)polys->indexBuffer()->ptr();
256 sorted_triangles[i] = tris[
mPrimitiveZ[i].mPrimitiveIndex ];
257 memcpy(&tris[0], &sorted_triangles[0],
sizeof(sorted_triangles[0])*sorted_triangles.size() );
260 if (polys->primitiveType() ==
PT_LINES)
263 mPrimitiveZ.resize( polys->indexBuffer()->size() / 2 );
267 const typename deT::index_type* it = polys->indexBuffer()->begin();
268 const typename deT::index_type* end = polys->indexBuffer()->end();
269 for(
unsigned iz=0; it != end; it+=2, ++iz)
282 sorted_lines.resize( polys->indexBuffer()->size() / 2 );
283 Line<T>* tris = (Line<T>*)polys->indexBuffer()->ptr();
285 sorted_lines[i] = tris[
mPrimitiveZ[i].mPrimitiveIndex ];
286 memcpy(&tris[0], &sorted_lines[0],
sizeof(sorted_lines[0])*sorted_lines.size() );
292 mPrimitiveZ.resize( polys->indexBuffer()->size() );
296 const typename deT::index_type* it = polys->indexBuffer()->begin();
297 const typename deT::index_type* end = polys->indexBuffer()->end();
298 for(
unsigned iz=0; it != end; ++it, ++iz)
311 sorted_points.resize( polys->indexBuffer()->size() );
312 Point<T>* tris = (Point<T>*)polys->indexBuffer()->ptr();
314 sorted_points[i] = tris[
mPrimitiveZ[i].mPrimitiveIndex ];
315 memcpy(&tris[0], &sorted_points[0],
sizeof(sorted_points[0])*sorted_points.size() );
320 if (polys->indexBuffer()->bufferObject()->handle())
325 polys->indexBuffer()->setBufferObjectDirty(
false);
328 polys->indexBuffer()->setBufferObjectDirty(
true);
The ArrayAbstract class defines an abstract interface to conveniently manipulate data stored in a Buf...
Associates a Renderable object to an Effect and Transform.
const mat4 & viewMatrix() const
Returns the Camera's view matrix (inverse of the modeling matrix).
virtual void onActorRenderStarted(Actor *actor, real, const Camera *cam, Renderable *renderable, const Shader *, int pass)
Performs the actual sorting.
std::vector< vec3 > mEyeSpaceVerts
Transform * transform()
Returns the Transform bound tho an Actor.
void setBufferObjectDirty(bool dirty=true)
Whether BufferObjects associated to a Renderable should be recomputed on the next rendering...
std::vector< QuadUInt > mSortedQuadsUInt
const ArrayAbstract * vertexArray() const
Conventional vertex array.
void sort(deT *polys, std::vector< Point< T > > &sorted_points, std::vector< Line< T > > &sorted_lines, std::vector< Triangle< T > > &sorted_triangles, std::vector< Quad< T > > &sorted_quads)
std::vector< LineUByte > mSortedLinesUByte
Data is specified many times and used many times as the source of drawing and image specification com...
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
virtual vec3 getAsVec3(size_t vector_index) const =0
Returns a vector from the buffer as a vec3 value.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Visualization Library main namespace.
void setDisplayListDirty(bool dirty)
Whether the display list associated to a Renderable should be recompiled at the next rendering...
DepthSortCallback sorts the primitives of the Geometry bound to the Actor in which the callback is in...
std::vector< TriangleUByte > mSortedTrianglesUByte
An abstract class that represents all the objects that can be rendered.
void setSortMode(ESortMode sort_mode)
void onActorDelete(Actor *)
Event notifying that an Actor is being deleted.
std::vector< PointUByte > mSortedPointsUByte
T * as()
Casts an Object to the specified class.
std::vector< TriangleUInt > mSortedTrianglesUInt
std::vector< LineUInt > mSortedLinesUInt
The ActorEventCallback class defines a callback object to react to Actor-related events.
Manages most of the OpenGL rendering states responsible of the final aspect of the rendered objects...
The base class of DrawArrays, DrawElements, MultiDrawElements and DrawRangeElements.
fmat4 mat4
Defined as: 'typedef fmat4 mat4'. See also VL_PIPELINE_PRECISION.
virtual size_t size() const =0
Returns the number of elements of an array.
std::vector< PrimitiveZ > mPrimitiveZ
std::vector< PointUInt > mSortedPointsUInt
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
ESortMode sortMode() const
void invalidateCache()
Forces sorting at the next rendering.
std::vector< QuadUShort > mSortedQuadsUShort
std::vector< QuadUByte > mSortedQuadsUByte
std::vector< PointUShort > mSortedPointsUShort
std::vector< TriangleUShort > mSortedTrianglesUShort
std::vector< LineUShort > mSortedLinesUShort
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.
DepthSortCallback()
Constructor.