13 #ifndef OGLPLUS_SHAPES_DRAW_1107121519_HPP
14 #define OGLPLUS_SHAPES_DRAW_1107121519_HPP
16 #include <oglplus/config/basic.hpp>
33 const size_t _sizeof_index;
36 template <
typename IT>
37 static size_t _do_get_sizeof_index(
const std::vector<IT>*)
42 template <
class ShapeBuilder>
43 static size_t _get_sizeof_index(
const ShapeBuilder&)
45 return _do_get_sizeof_index(
46 (
typename ShapeBuilder::IndexArray*)
nullptr
50 template <
typename IT>
53 return oglplus::GetDataType<IT>();
56 template <
class ShapeBuilder>
59 return _do_get_index_data_type(
60 (
typename ShapeBuilder::IndexArray*)
nullptr
64 template <
class ShapeBuilder>
66 : _sizeof_index(_get_sizeof_index(builder))
67 , _index_data_type(_get_index_data_type(builder))
79 return _index_data_type;
87 OGLPLUS_ENUM_CLASS_VALUE(DrawArrays, 0)
88 OGLPLUS_ENUM_CLASS_COMMA
89 OGLPLUS_ENUM_CLASS_VALUE(DrawElements, 1)
139 GLuint inst_count = 1,
144 IndexPtr_(index_info),
152 template <
typename IT>
154 const std::vector<IT>& indices,
155 GLuint inst_count = 1,
161 IndexDataType_(indices),
168 template <
typename IT>
169 static DataType IndexDataType_(
const std::vector<IT>&)
171 return GetDataType<IT>();
174 template <
typename IT>
175 void* IndexPtr_(
const std::vector<IT>& indices)
const
177 const IT* base = indices.empty() ?
nullptr : indices.data();
178 return (
void*)(base + first);
181 void* IndexPtr_(
const ElementIndexInfo& index_info)
const
183 return (
void*)(first * index_info.Size());
186 void SetupPrimitiveRestart_(
void)
const;
187 void CleanupPrimitiveRestart_(
void)
const;
196 void DrawArrays_(GLuint inst_count, GLuint base_inst)
const;
206 class DrawingInstructionWriter;
223 typedef std::vector<DrawOperation> DrawOperationSeq;
224 DrawOperationSeq _ops;
230 : _ops(std::move(ops))
233 friend class DrawingInstructionWriter;
236 template <
class IndexArray>
237 struct DrawFromIndices_
239 const IndexArray& _indices;
241 DrawFromIndices_(
const IndexArray& indices)
251 op.Draw(_indices, inst_count, base_inst);
256 struct DrawFromIndexInfo_
261 : _index_info(index_info)
270 op.Draw(_index_info, inst_count, base_inst);
275 template <
typename DrawFun,
typename Driver>
277 const DrawFun& draw_fun,
278 const GLuint inst_count,
279 const GLuint base_inst,
283 auto i=_ops.begin(),e=_ops.end();
290 draw_fun(*i, inst_count, base_inst);
292 else do_draw =
false;
293 GLuint prev_phase = i->phase;
298 if(prev_phase != i->phase)
300 do_draw = driver(i->phase);
301 prev_phase = i->phase;
303 if(do_draw) draw_fun(*i, inst_count, base_inst);
310 : _ops(std::move(temp._ops))
317 const std::vector<DrawOperation>& Operations(
void)
const
324 inline bool operator()(GLuint )
const
330 template <
typename IT,
typename Driver>
332 const std::vector<IT>& indices,
339 DrawFromIndices_<std::vector<IT>>(indices),
346 template <
typename IT>
348 const std::vector<IT>& indices,
349 GLuint inst_count = 1,
354 DrawFromIndices_<std::vector<IT>>(indices),
361 template <
typename Driver>
370 DrawFromIndexInfo_(index_info),
379 GLuint inst_count = 1,
384 DrawFromIndexInfo_(index_info),
395 class DrawingInstructionWriter
398 typedef DrawingInstructions::DrawOperationSeq Operations;
405 static void AddInstruction(
406 DrawingInstructions& instr,
407 const DrawOperation& operation
410 instr._ops.push_back(operation);
413 static DrawingInstructions MakeInstructions(
const DrawOperation& operation)
415 DrawingInstructions instr;
416 instr._ops.push_back(operation);
420 static DrawingInstructions MakeInstructions(Operations&& ops)
422 return DrawingInstructions(std::forward<Operations>(ops));
429 struct WithAdjacency { };
439 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
440 #include <oglplus/shapes/draw.ipp>
441 #endif // OGLPLUS_LINK_LIBRARY
443 #endif // include guard
DataType
OpenGL data type enumeration.
Definition: data_type.hpp:34
PrimitiveType
Primitive type enumeration.
Definition: primitive_type.hpp:29
GLuint first
The first element.
Definition: draw.hpp:111
OpenGL primitive type-related declarations.
Helper class storing information about shape element index datatype.
Definition: draw.hpp:30
oglplus::ShapeDrawOperationMethod Method
Enumeration of drawing methods.
Definition: draw.hpp:103
size_t Size(void) const
Returns the size (in bytes) of index type used by ShapeBuilder.
Definition: draw.hpp:71
PrimitiveType mode
The primitive type to be used to draw.
Definition: draw.hpp:108
GLuint restart_index
Primitive restart index.
Definition: draw.hpp:126
Data type-related declarations.
static GLuint NoRestartIndex(void)
Special constant for disabling primitive restart.
Definition: draw.hpp:117
Structure containing information about how to draw a part of a shape.
Definition: draw.hpp:100
void Draw(const std::vector< IT > &indices, GLuint inst_count=1, GLuint base_inst=0) const
Draw the part of a shape.
Definition: draw.hpp:153
oglplus::DataType DataType(void) const
Returns the GL datatype of index type used by ShapeBuilder.
Definition: draw.hpp:77
GLuint count
Count of elements.
Definition: draw.hpp:114
ShapeDrawOperationMethod
Enumeration of drawing methods.
Definition: draw.hpp:86
Method method
The method to be used to draw.
Definition: draw.hpp:106
GLuint phase
The phase of the drawing process.
Definition: draw.hpp:135
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219