Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cDXGPUStream.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cDXGPUStream_H
8 #define _INC_cDXGPUStream_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cDXBase.h"
14 
15 #ifdef USE_DX9
16 #include "cDXBuffer.h"
18 
19 namespace Gray3D
20 {
21 
22  class GRAY3D_LINK cDXGPUQuad : public cDXBase // typically a cSingleton
23  {
27 
28  typedef cDXBase SUPER_t;
29  static const int k_QuadIncrement = 4 * 1024;
30 
31  public:
32  cDXGPUQuad() noexcept
33  : m_CurQuadNum(0)
34  {
35  }
36  HRESULT SetQuadIndices(int numberOfQuads);
37 
38  virtual HRESULT OnLostDeviceX()
39  {
40  m_pQuadIndices.ReleasePtr();
41  m_CurQuadNum = 0;
42  return SUPER_t::OnLostDeviceX();
43  }
44 
45  public:
46  cIUnkPtr<IDirect3DIndexBuffer9> m_pQuadIndices;
47  int m_CurQuadNum;
48  };
49 
50  class GRAY3D_LINK cDXGPUIndex : public cDXBase // typically a cSingleton
51  {
56  typedef cDXBase SUPER_t;
57  enum
58  {
59  DYN_INDICES_BUFFER_SIZE = (16384 * 2 * 2),
60  };
61  public:
62  cDXGPUIndex() noexcept
63  : m_FirstIdx(-1)
64  , m_CurIdxBufLen(0)
65  {
66  }
67 
68  // SetIndices to dynamic index stream
69  // Call this as initial setup before rendering groups of primitives with dynamic indices
70  HRESULT SetIndices();
71 
72  // Prepare for writing the indices. Returns pointer to first index - indices is 16-bit
73  // expects number of indices to write. This number should be the actual number
74  // of indices that would be filled/used
75  // Buffer returned is WRITE-ONLY - don't do stuff that will read back from it.
76  // It will work, but will slow things down a lot
77  WORD* LockIndices(int numIdx);
78 
79  // Signal for finish writing, readying for rendering
80  // returns the "physical" index of first index - you should offset DrawIndexedPrimitive by this amount
81  // (StartIndex)
82  int UnlockIndices();
83 
84  virtual HRESULT OnResetDeviceX();
85  virtual HRESULT OnLostDeviceX()
86  {
87  m_pDynIndices.ReleasePtr();
88  return SUPER_t::OnLostDeviceX();
89  }
90  public:
91  cIUnkPtr<IDirect3DIndexBuffer9> m_pDynIndices; // TODO: Merge with cDXBufferIndexT
92  int m_FirstIdx;
93  size_t m_CurIdxBufLen; // size of m_pDynIndices
94  };
95 
96  class GRAY3D_LINK cDXGPUVert : public cDXBase // typically a cSingleton
97  {
102  typedef cDXBase SUPER_t;
103  // maximum values for single dynamic vertex and index lock/batch
104  // if you require larger (unlikely, as this data goes thru CPU), break data into these smaller batches
105  enum
106  {
107  DYN_VERTICES_BUFFER_SIZE = (16384 * 32),
108  };
109  public:
110  cDXGPUVert() noexcept
111  : m_FirstVtx(-1)
112  , m_CurVtxBufLen(0)
113  {
114  }
115 
116  // SetStreamSource to dynamic vertex stream.
117  // Call this as initial setup before rendering groups of primitives with dynamic vertices
118  HRESULT SetVertStreamSource(int streamNumber, size_t nVertStride);
119 
120  // Prepare for writing the vertices. Returns pointer to first vertex
121  // expects number of vertices to write and stride. Vertex number should be the actual number
122  // of vertices that would be filled/used
123  // Buffer returned is WRITE-ONLY - don't do stuff that will read back from it.
124  // It will work, but will slow things down a lot
125  void* LockVertices(int numVtx, size_t nVertStride);
126 
127  // Signal for finish writing, readying for rendering
128  // returns the "physical" index of first vertex - you should offset Draw(Indexed)Primitive by this amount
129  // (StartVertex or BaseVertexIndex)
130  int UnlockVertices();
131 
132  virtual HRESULT OnResetDeviceX();
133  virtual HRESULT OnLostDeviceX()
134  {
135  m_pDynVertices.ReleasePtr();
136  return SUPER_t::OnLostDeviceX();
137  }
138 
139  public:
140  cIUnkPtr<IDirect3DVertexBuffer9> m_pDynVertices; // TODO: Merge with cDXBufferVertexT
141  UINT m_FirstVtx;
142  size_t m_CurVtxBufLen; // size of m_pDynVertices
143  };
144 }
145 #endif // USE_DX9
146 #endif
#define GRAY3D_LINK
Definition: Gray3D.h:15
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: Gray3D.cpp:12