Advertisement
Guest User

drawitem.h

a guest
May 6th, 2016
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.53 KB | None | 0 0
  1.  
  2. struct DrawItemKey
  3. {
  4.     typedef u64 Type;
  5.     Type key;
  6.     const DrawItem* item;
  7. };
  8.  
  9. class DrawItemSharedResources : NoCreate
  10. {
  11. public:
  12.     void Release();
  13. };
  14.  
  15. struct DrawItem
  16. {
  17.     void Release();
  18.     DrawItemKey::Type GetSortKey() const;
  19. };
  20.  
  21. void SortDrawItemKeys( DrawItemKey* io, DrawItemKey* buffer, u32 count );
  22. void SortDrawItemKeys( Scope& temp, DrawItemKey* io, u32 count );
  23. inline void SortDrawItemKeys( Scope& temp, rde::vector<DrawItemKey>& io ) { u32 count = io.size(); if(count) SortDrawItemKeys(temp, &io[0], count); }
  24.  
  25.  
  26. struct LinearDrawDesc
  27. {
  28.     PrimitiveType::Type primitive;
  29.     u32 primitiveCount;
  30.     u32 vbOffset; // - vbOffset is counting in the number-of-vertices from the start of the buffer, NOT in bytes
  31.     u8 stencilRef;
  32.     bool useStencilRef;
  33. };
  34. struct IndexedDrawDesc
  35. {
  36.     PrimitiveType::Type primitive;
  37.     u32 primitiveCount;
  38.     u32 vbOffset; // - vbOffset is counting in the number-of-vertices from the start of the buffer, NOT in bytes
  39.     u32 ibOffset; // - ibOffset is in number-of-indices, NOT in bytes
  40.     u8 stencilRef;
  41.     bool useStencilRef;
  42. };
  43.  
  44. struct DrawDesc //use one of the above structs instead - they'll be converted to this one
  45. {
  46.     DrawDesc( const LinearDrawDesc& o )
  47.         : type(internal::DrawCommand::Linear)
  48.         , primitive(o.primitive)
  49.         , primitiveCount(o.primitiveCount)
  50.         , vbOffset(o.vbOffset)
  51.         , stencilRef(o.stencilRef)
  52.         , useStencilRef(o.useStencilRef)
  53.     {}
  54.     DrawDesc( const IndexedDrawDesc& o )
  55.         : type(internal::DrawCommand::Indexed)
  56.         , primitive(o.primitive)
  57.         , primitiveCount(o.primitiveCount)
  58.         , vbOffset(o.vbOffset)
  59.         , ibOffset(o.ibOffset)
  60.         , stencilRef(o.stencilRef)
  61.         , useStencilRef(o.useStencilRef)
  62.     {}
  63.     u32 primitiveCount;
  64.     u32 vbOffset;
  65.     u32 ibOffset;
  66.     u8 stencilRef;
  67.     u8 useStencilRef;
  68.     u8 type;//internal::DrawCommand::Type
  69.     u8 primitive;//PrimitiveType::Type
  70. };
  71.  
  72. struct IndirectDrawDesc
  73. {
  74.     BufferId buffer;
  75.     u32 offset;//4 byte aligned
  76.     u8 primitive;//PrimitiveType::Type
  77.     u8 linear;//0=indexed draw, 1=linear draw
  78.     u8 stencilRef;
  79.     u8 useStencilRef;
  80.     u32 drawCount; // if >1, multi-draw
  81.     u32 stride; // for multi-draw only. Must be >= offset, 4 byte aligned
  82. };
  83.  
  84. struct AutoDrawDesc
  85. {
  86.     // input vertex data must be in stream[0], that buffer must have been created with the stream-out flag, and data must have been streamed into it already
  87.     // primitiveCount will be fetched from the buffer's stream-out counter
  88.     u8 primitive;//PrimitiveType::Type
  89.     u8 stencilRef;
  90.     u8 useStencilRef;
  91.     u8 _pad_;
  92. };
  93.  
  94. struct FlattenedDrawStates
  95. {
  96. ...
  97.     u8 blob[Size];
  98. };
  99.  
  100. class DrawItemWriter
  101. {
  102. public:
  103.     inline DrawItemWriter(){eiDEBUG( m_gpu = 0 );}
  104.     // Either pass a Scope allocator, or pass 'Persistent'.
  105.     // In the Persistent case: Each DrawItem must have it's Release function called, and
  106.     //                         the DrawItemSharedResources must have it's Release function called.
  107.     // In the Scope case: the DrawItems and DrawItemSharedResource will be released automatically by the supplied Scope. Do not call Release on them.
  108.     void Begin( GpuDevice& gpu, Scope& alloc );
  109.     void Begin( GpuDevice& gpu, Persistent_tag, DrawItemSharedResources* reuseExistingSharedData=0 );
  110.  
  111.     void BeginPass( u32 passIndex, const PassState* );
  112.     void BeginPass( const RenderPass& );
  113.  
  114.     void PreFlattenStates( FlattenedDrawStates& output, u32 stateGroupCount, const StateGroup*const* stateGroups );//If you're going to use the same state-group stack for multiple draws within a pass, this lets you pay the stack-flattening cost once.
  115.  
  116.     DrawItem* Add( const char* name, const DrawDesc&,         u32 stateGroupCount, const StateGroup*const* stateGroups, const DrawItemOptions& opt = DrawItemOptions() );
  117.     DrawItem* Add( const char* name, const DrawDesc&,         const FlattenedDrawStates&,                               const DrawItemOptions& opt = DrawItemOptions() );
  118.    
  119.     DrawItem* Add( const char* name, const IndirectDrawDesc&, u32 stateGroupCount, const StateGroup*const* stateGroups, const DrawItemOptions& opt = DrawItemOptions() );
  120.     DrawItem* Add( const char* name, const IndirectDrawDesc&, const FlattenedDrawStates&,                               const DrawItemOptions& opt = DrawItemOptions() );
  121.    
  122.     DrawItem* Add( const char* name, const AutoDrawDesc&,     u32 stateGroupCount, const StateGroup*const* stateGroups, const DrawItemOptions& opt = DrawItemOptions() );
  123.     DrawItem* Add( const char* name, const AutoDrawDesc&,     const FlattenedDrawStates&,                               const DrawItemOptions& opt = DrawItemOptions() );
  124.  
  125.     void EndPass();
  126.     DrawItemSharedResources* End();
  127.  
  128. private:
  129. ...
  130. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement