PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Device.hpp

https://bitbucket.org/ayufan/ayuine2b
C++ Header | 199 lines | 156 code | 17 blank | 26 comment | 7 complexity | ffa79c5aa43cfe77cf2215ec091c3b88 MD5 | raw file
  1. //------------------------------------//
  2. //
  3. // Device.hpp
  4. //
  5. // Author: ayufan (ayufan[at]o2.pl)
  6. // Project: ayuine2
  7. // Date: 2006-7-31
  8. //
  9. //------------------------------------//
  10. #pragma once
  11. namespace ayuine
  12. {
  13. //------------------------------------//
  14. // Device class
  15. class Device
  16. {
  17. // Structures
  18. private:
  19. template<typename Type>
  20. class AIU
  21. {
  22. // Fields
  23. public:
  24. Type Value;
  25. // Constructor
  26. public:
  27. AIU() {
  28. Value = nullptr;
  29. }
  30. AIU(Type value) {
  31. if(Value = value) {
  32. Value->AddRef();
  33. }
  34. }
  35. AIU(const AIU<Type> &value) {
  36. if(Value = value.Value) {
  37. Value->AddRef();
  38. }
  39. }
  40. // Destructor
  41. public:
  42. ~AIU() {
  43. if(Value) {
  44. Value->Release();
  45. Value = nullptr;
  46. }
  47. }
  48. // Operators
  49. public:
  50. operator Type () {
  51. return Value;
  52. }
  53. AIU<Type> &operator = (const AIU<Type> &value) {
  54. if(Value) {
  55. Value->Release();
  56. }
  57. if(Value = value.Value) {
  58. Value->AddRef();
  59. }
  60. return *this;
  61. }
  62. // Methods
  63. public:
  64. void reset(Type value = nullptr) {
  65. if(Value) {
  66. Value->Release();
  67. }
  68. if(Value = value) {
  69. Value->AddRef();
  70. }
  71. }
  72. };
  73. ValueType(Device, 0);
  74. // Device Fields
  75. private:
  76. List<DeviceObject> _deviceObjects;
  77. HWND _d3dWnd;
  78. LPDIRECT3D9 _d3d9;
  79. LPDIRECT3DDEVICE9 _d3dDev;
  80. D3DCAPS9 _d3dCaps;
  81. D3DPRESENT_PARAMETERS _d3dpp;
  82. D3DVIEWPORT9 _d3dViewport;
  83. LPDIRECT3DSURFACE9 _renderTarget;
  84. LPDIRECT3DSURFACE9 _depthTarget;
  85. LPDIRECT3DQUERY9 _query;
  86. LPDIRECT3DQUERY9 _occlusion;
  87. LPDIRECT3DTEXTURE9 _defaultTexture;
  88. D3DXIMAGE_INFO _defaultTextureInfo;
  89. // Cached State Fields
  90. private:
  91. mat4 _transform[2];
  92. mat4 _object[2];
  93. vec4 _color[2];
  94. TextureFilter _filter[16][2];
  95. TextureAddress _address[16][2];
  96. BlendMode _blendMode[2];
  97. TextureMode _textureMode[2];
  98. bool _winding[2];
  99. bool _depthTest[2], _depthWrite[2], _depthLE[2], _depthBias[2];
  100. f32 _depthScale[2];
  101. bool _cullMode[2];
  102. bool _fillMode[2];
  103. u32 _colorWrite[2];
  104. bool _alphaTest[2];
  105. u32 _alphaValue[2];
  106. bool _scissorTest[2];
  107. RECT _scissorRect[2];
  108. AIU<LPDIRECT3DVERTEXDECLARATION9> _decl[2];
  109. AIU<LPDIRECT3DVERTEXSHADER9> _vertexShader[2];
  110. AIU<LPDIRECT3DPIXELSHADER9> _pixelShader[2];
  111. AIU<LPDIRECT3DBASETEXTURE9> _textures[16][2];
  112. AIU<LPDIRECT3DINDEXBUFFER9> _indexBuffer[2];
  113. AIU<LPDIRECT3DVERTEXBUFFER9> _vertexBuffer[8][2];
  114. u32 _vertexOffset[8][2];
  115. u32 _vertexStride[8][2];
  116. vec4 _pixelConsts[256];
  117. vec4 _vertexConsts[256];
  118. u32 _pixelConstsDirty[2];
  119. u32 _vertexConstsDirty[2];
  120. // Device Capabilities
  121. public:
  122. // Constructor
  123. public:
  124. Device();
  125. // Destructor
  126. public:
  127. ~Device();
  128. // Properties
  129. public:
  130. LPDIRECT3DDEVICE9 d3ddev() {
  131. return _d3dDev;
  132. }
  133. // Methods
  134. public:
  135. AYUAPI bool check();
  136. AYUAPI void lost(bool theEnd);
  137. AYUAPI void reset(bool theBegin);
  138. AYUAPI bool swap(HWND destWnd);
  139. AYUAPI f32 width();
  140. AYUAPI f32 height();
  141. AYUAPI f32 aspect();
  142. // State Manager Methods
  143. public:
  144. AYUAPI void clear(bool target, bool depth, const vec4 &color = vec4(0, 0, 0, 1), f32 z = 1.0f, const Array<RECT> &rects = Array<RECT>());
  145. AYUAPI void viewport(const rect &r);
  146. AYUAPI void scissor(const rect *r);
  147. AYUAPI void transform(const mat4 &projection, const mat4 &view);
  148. AYUAPI void transform(const mat4 &transform);
  149. AYUAPI void object(const mat4 &object);
  150. AYUAPI void blendMode(BlendMode mode);
  151. AYUAPI void cullMode(bool cull);
  152. AYUAPI void depthMode(bool test, bool write, bool le = true);
  153. AYUAPI void depthBias(bool bias);
  154. AYUAPI void depthScale(f32 scale);
  155. AYUAPI void fillMode(bool fill);
  156. AYUAPI void colorWrite(bool rgb, bool a);
  157. AYUAPI void alphaTest(bool test, u32 value = 0x7f);
  158. AYUAPI void winding(bool reverse);
  159. AYUAPI void colorConst(const vec4 &color);
  160. AYUAPI void vertexConst(u32 i, const f32 *vectors, u32 count = 1);
  161. AYUAPI void vertexConst(u32 i, const vec4 &value);
  162. AYUAPI void pixelConst(u32 i, const f32 *vectors, u32 count = 1);
  163. AYUAPI void pixelConst(u32 i, const vec4 &value);
  164. AYUAPI void shaderConst(VertexShaderConst vertex, PixelShaderConst pixel, const f32 *vectors, u32 count = 1);
  165. AYUAPI void shaderConst(VertexShaderConst vertex, PixelShaderConst pixel, const vec4 &value);
  166. AYUAPI void resetStates();
  167. AYUAPI void updateStates();
  168. AYUAPI void beginOcclusion();
  169. AYUAPI void endOcclusion();
  170. AYUAPI bool flushOcclusion(u32 &result);
  171. // Friends
  172. friend class DeviceObject;
  173. friend class VertexType;
  174. friend class VertexBuffer;
  175. friend class IndexBuffer;
  176. friend class VertexShader;
  177. friend class PixelShader;
  178. friend class Texture;
  179. friend class TextureTarget;
  180. friend class CubeTarget;
  181. };
  182. };