CommandBufferHandle.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_GR_COMMAND_BUFFER_HANDLE_H
  6. #define ANKI_GR_COMMAND_BUFFER_HANDLE_H
  7. #include "anki/gr/GrHandle.h"
  8. namespace anki {
  9. /// @addtogroup graphics
  10. /// @{
  11. /// Command buffer handle
  12. class CommandBufferHandle: public GrHandle<CommandBufferImpl>
  13. {
  14. public:
  15. using Base = GrHandle<CommandBufferImpl>;
  16. using UserCallback = Error(*)(void*);
  17. CommandBufferHandle();
  18. ~CommandBufferHandle();
  19. /// Create command buffer
  20. ANKI_USE_RESULT Error create(GrManager* manager,
  21. CommandBufferInitHints hints = CommandBufferInitHints());
  22. /// Add a user command at the end of the command buffer
  23. void pushBackUserCommand(UserCallback callback, void* data);
  24. /// Add another command buffer for execution
  25. void pushBackOtherCommandBuffer(CommandBufferHandle& commands);
  26. /// Flush command buffer for deffered execution.
  27. void flush();
  28. /// Flush and wait to finish
  29. void finish();
  30. /// Compute initialization hints
  31. CommandBufferInitHints computeInitHints() const;
  32. /// @name State manipulation
  33. /// @{
  34. /// Set clear color buffers value
  35. void setClearColor(F32 r, F32 g, F32 b, F32 a);
  36. /// Set clear depth buffer value
  37. void setClearDepth(F32 value);
  38. /// Set clear stencil buffer value
  39. void setClearStencil(U32 value);
  40. /// Clear color/depth/stencil buffers
  41. void clearBuffers(U32 mask);
  42. /// Set the viewport
  43. void setViewport(U16 minx, U16 miny, U16 maxx, U16 maxy);
  44. /// Set the color mask
  45. void setColorWriteMask(Bool red, Bool green, Bool blue, Bool alpha);
  46. /// Enable/disable depth test
  47. void enableDepthTest(Bool enable);
  48. /// Set depth compare function
  49. void setDepthFunction(GLenum func);
  50. /// Set depth write mask
  51. void setDepthWriteMask(Bool write);
  52. /// Enable or note stencil test
  53. void enableStencilTest(Bool enable);
  54. /// Set stencil function. Equivalent to glStencilFunc
  55. void setStencilFunction(GLenum function, U32 reference, U32 mask);
  56. /// Set the stencil mask. Equivalent to glStencilMask
  57. void setStencilPlaneMask(U32 mask);
  58. /// Set the operations of stencil fail, depth fail, depth pass. Equivalent
  59. /// to glStencilOp
  60. void setStencilOperations(GLenum stencFail, GLenum depthFail,
  61. GLenum depthPass);
  62. /// Enable or not blending. Equivalent to glEnable/glDisable(GL_BLEND)
  63. void enableBlend(Bool enable);
  64. /// Set blend equation. Equivalent to glBlendEquation
  65. void setBlendEquation(GLenum equation);
  66. /// Set the blend functions. Equivalent to glBlendFunc
  67. void setBlendFunctions(GLenum sfactor, GLenum dfactor);
  68. /// Set the blend color. Equivalent to glBlendColor
  69. void setBlendColor(F32 r, F32 g, F32 b, F32 a);
  70. /// Enable primitive restart
  71. void enablePrimitiveRestart(Bool enable);
  72. /// Set patch number of vertices
  73. void setPatchVertexCount(U32 count);
  74. /// Enable or not face culling. Equal to glEnable(GL_CULL_FASE)
  75. void enableCulling(Bool enable);
  76. /// Set the faces to cull. Works when culling is enabled. Equal to
  77. /// glCullFace(x)
  78. void setCullFace(GLenum mode);
  79. /// Set the polygon offset. Equal to glPolygonOffset() plus
  80. /// glEnable(GL_POLYGON_OFFSET_FILL)
  81. void setPolygonOffset(F32 factor, F32 units);
  82. /// Enable/disable polygon offset
  83. void enablePolygonOffset(Bool enable);
  84. /// Set polygon mode
  85. void setPolygonMode(GLenum face, GLenum mode);
  86. /// Enable/diable point size in vertex/geometry shaders.
  87. void enablePointSize(Bool enable);
  88. /// Bind many textures
  89. /// @param first The unit where the first texture will be bound.
  90. /// @param textures The array of textures.
  91. /// @param count The count of textures
  92. void bindTextures(U32 first, TextureHandle textures[], U32 count);
  93. /// @}
  94. /// @name Drawcalls
  95. /// @{
  96. void drawElements(GLenum mode, U8 indexSize,
  97. U32 count, U32 instanceCount = 1, U32 firstIndex = 0,
  98. U32 baseVertex = 0, U32 baseInstance = 0);
  99. void drawArrays(GLenum mode, U32 count, U32 instanceCount = 1,
  100. U32 first = 0, U32 baseInstance = 0);
  101. void drawElementsConditional(OcclusionQueryHandle& query,
  102. GLenum mode, U8 indexSize,
  103. U32 count, U32 instanceCount = 1, U32 firstIndex = 0,
  104. U32 baseVertex = 0, U32 baseInstance = 0);
  105. void drawArraysConditional(OcclusionQueryHandle& query,
  106. GLenum mode, U32 count, U32 instanceCount = 1,
  107. U32 first = 0, U32 baseInstance = 0);
  108. /// @}
  109. /// @name Other operations
  110. /// @{
  111. void copyTextureToBuffer(TextureHandle& from, BufferHandle& To);
  112. /// @}
  113. };
  114. /// @}
  115. } // end namespace anki
  116. #endif