[go: up one dir, main page]

Menu

[r221]: / Headers / gfx / RendererDX.h  Maximize  Restore  History

Download this file

270 lines (199 with data), 9.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// File name: RendererDX.h
// Des: in file interface asli kar ba ghesmat Renderer ba D3D hast. Bayad tamam saye
// khodemono bokonim ta az D3DX estefade nakonim.
// Date: 13/5/1385
// Programmer: Ali Akbar Mohamadi(Kochol)
#ifdef WIN32
#ifndef RENDERERDX_H
#define RENDERERDX_H
#include "../../include/gfx/renderer.h"
#include "../../include/kgedef.h"
#include "LightDX.h"
#include <d3d9.h>
#include <vector>
#define RGB16BIT(r,g,b) ((b) + ((g) << 5) + ((r) << 11)) // change 24 bit to 16 bit
#define RGB32BIT(a,r,g,b) ((b) + ((g) << 8) + ((r) << 16) + ((a) << 24))
namespace kge
{
namespace gfx
{
static char* ShaderVersionName[] = {
"vs_1_1",
"vs_2_0",
"vs_3_0",
"ps_1_1",
"ps_1_4",
"ps_2_0",
"ps_3_0"
};
class RendererDX: public Renderer
{
friend class LightDX;
public:
// Constructor
RendererDX();
// Destructor
~RendererDX();
// Init
bool Init(Device* device, int Width, int Height, int bits, bool UseStencil,
bool Fullscreen,bool Antialiasing);
//! Init
bool Init(void* hwnd, Device* device, int Width, int Height , int Bits,
bool UseStencil, bool Fullscreen,bool Antialiasing);
// Pak kardane pixel ha va buffer ha.
bool Clear(bool Pixel, bool Zbuffer, bool Stencil);
// Creates a renderable texture to use it as a render target
virtual bool CreateRenderableTexture(Texture** ppOutTexture, int width, int height, TextureFormat tf, bool CreateDepthStencilBuffer = true, bool AntiAliasing = false);
//! Begin rendering
bool BeginRendering(bool Pixel, bool Zbuffer, bool Stencil);
// Payane render
void EndRendering();
// Set kardane Range pas zamine
void SetClearColor(Colorf ClearColor);
// Keshidane mosal las ha dar safhe be sorate listi az mosal las ha.
void DrawTriangleList(const Vertex3* Vertices, u32 VCount,
const u16 *Indis, u32 ICount);
//! Sets the vertex buffer for multi streaming
void SetVertexBuffer(HardwareBuffer* pBuffer, int stage);
//! Sets the index buffer for rendering
void SetIndexBuffer(HardwareBuffer* pBuffer);
// Set the render able target where renderer will render there.
void SetRenderTarget(int RenderNumber, Texture* RenderTarget);
// Set kardane dorbin.
void SetViewLookatLH(math::Vector &Pos, math::Vector &Lookat, math::Vector &UpDir);
// Set kardane dorbin.
void SetViewLookatRH(math::Vector &Pos, math::Vector &Lookat, math::Vector &UpDir);
// Matrixe Projection ro set mikone Be sorate Chap Dast.
void SetPerspectiveLH(float Fov, float Near, float Far);
// Matrixe Projection ro set mikone Be sorate Rast Dast.
void SetPerspectiveRH(float Fov, float Near, float Far);
// Matrix haye asli dorbin va ajsam ra taghir midahad
void SetTransForm(math::Matrix *mat, TransformMode TM);
// Matrix haye asli dorbin va ajsam ra bar migardone.
math::Matrix GetTransForm(TransformMode TM);
// Keshidane mosal las ha dar safhe be sorate listi az mosal las ha.
void DrawTriangleList(const Vertex3C* Vertices, u32 VCount,
const u16 *Indis, u32 ICount);
// Listi az khat ha ro mikeshe.
void DrawLineList(Vertex3C *Vertices, u32 VCount, u16 *Indices, u32 ICount);
// This function is for Texture Manager for adding textures use SceneManager AddTexture function instead.
bool AddTexture(Texture** ppOutTexture, u32 Handle, char* FileName,
char* Name, void* ExtraParam);
// Keshidane mosal las ha dar safhe be sorate listi az mosal las ha.
void DrawTriangleList(const Vertex3T* Vertices, u32 VCount,
const u16 *Indis, u32 ICount);
// Set a texture
void SetTexture(Texture* pTex, int index);
// Keshidane mosal las ha dar safhe be sorate listi az mosal las ha.
void DrawTriangleList(const Vertex3TN* Vertices, u32 VCount,
const u16 *Indis, u32 ICount);
// Draw an indexed or non indexed triabgle from arrays.
void DrawTriangleList(const Vertex3TTN* Vertices, u32 VCount,
const u16 *Indis, u32 ICount);
// Enable kardane khsiyat haye render.
void Enable(RenderFlags RF);
// Disable kardane khsiyat haye render.
void Disable ( RenderFlags RF );
// Set kardane kamele ya matrial besorate automatic.
void SetMaterial(Material *pMaterial);
// Set kardane keyfiyat texture ha va address mode ha.
void SetTextureParams(TextureParams Params, int TextureStage = 0);
// Baraye fahmidane inke aya cart graphic az on ghabelilat ha poshti bani mikone ya na.
bool CanDo ( GraphicCardCaps Item );
// Tanzimate stencil buffer baraye effect haye mokhtalef.
void SetStencilBuffer(kge::efx::EffectType ET, u8 State);
// Create font
void AddFont( kge::gui::Font** ppOut, const char* strFontName, ul32 dwHeight );
// Create a vertex buffer and store it on video memory.
HardwareBuffer* CreateVertexBuffer( void* Vertices, u32 VCount,
VertexType eVType ,
bool isDynamic);
// Create a vertex buffer from custom vertex type and store it on video memory.
HardwareBuffer* CreateVertexBuffer( void* Vertices, u32 VCount,
u32 Stride,
bool isDynamic);
// Creates an Index buffer on video memory
HardwareBuffer* CreateIndexBuffer( void* Indices, u32 ICount,
IndexBufferType eIndexBufferType ,
bool isDynamic);
// Draw a vertex buffer
void DrawTriangleList(HardwareBuffer* VB, HardwareBuffer* IB, u32 VCount, u32 ICount,
VertexType eVType = EVT_V3TN );
// Draw a vertex buffer
virtual void DrawTriangleList(u32 VCount, u32 ICount,
VertexDec* CV );
// Load a vertex shader from a file then compile it and return the created vertex shader
virtual Shader* CreateVertexShaderFromFile(char* VertexFileName, char* VertexMain,
ShaderVersion eVVersion);
// Load a vertex shader from a string then compile it and return the created vertex shader
virtual Shader* CreateVertexShaderFromString(char* VertexCode, char* VertexMain,
ShaderVersion eVVersion);
// Load a pixel shader from a file then compile it and return the created pixel shader
virtual Shader* CreatePixelShaderFromFile(char* PixelFileName, char* PixelMain,
ShaderVersion ePVersion);
// Load a pixel shader from a string then compile it and return the created pixel shader
virtual Shader* CreatePixelShaderFromString(char* PixelCode, char* PixelMain,
ShaderVersion ePVersion);
// Returns the renderer type (DirectX or OpenGL)
virtual RendererAPI GetRendererType() { return ERA_DirectX; }
// set the fog setings
bool SetFog(FogType mode,Colorf FogColor ,float expDensity=0,float linearStart= 0,float linearEnd = 1000000);
//set video mode
bool SetVideoMode( int Width, int Height , int Bits,
bool UseStencil = false, bool Fullscreen = false,int MultiSample = 0,bool VSync = false);
// Sets the rendering view port.
virtual void SetViewPort(core::RectI viewport);
//! Returns the direct 3d device.
void* GetDirect3dDevice();
//! Create a custom vertex type and put it in pOut parameter.
void CreateCustomVertexType(CustomVertexElement *pVertexInfoArray, CustomVertex* pOut);
//! Sets the vertex declaration
void SetVertexDec(VertexDec* pVD);
protected:
LPDIRECT3DDEVICE9 m_pd3dDevice;
D3DPRESENT_PARAMETERS m_d3dpp;
D3DFORMAT m_DSFMT; // depth and Stencil Buffer
D3DMULTISAMPLE_TYPE m_msType; // Multi sample type
kge::ul32 msQuality;
D3DCAPS9 m_d3dCaps; // D3D Caps
LPDIRECT3DSURFACE9 m_pBackBufferSurface, // Back buffer surface
m_pBackBufferZSurface;
IDirect3DVertexDeclaration9 * m_pV2, // Vertex2.
* m_pV3, // Vertex3.
* m_pV3C, // Vertex3 + Color.
* m_pV3T, // Vertex3 + Texture cord.
* m_pV3TN, // Vertex3 + Texture cord + Normal vector.
* m_pV3TTN, // Vertex3 + two Texture cord + Normal vector.
* m_pV3TNC, // Vertex3 + Texture cord + Normal vector + Color.
* m_pP0NT1BT2; // Vertex3 + Normal vector + Texture cord + Tangent + Binormal in multi stream mode.
kge::ul32 m_Behavior; // Device Behavior
D3DCOLOR m_ClearColor; // Clear Color
kge::u32 m_TextCount; // The count of textures
std::vector<char*> m_vTextureNames;// Texture names Array.
std::vector<LPDIRECT3DTEXTURE9> m_vTextures; // Textures Array.
std::vector<IDirect3DVertexBuffer9*> m_vVBuffers; // Vertex buffers array.
std::vector<IDirect3DIndexBuffer9*> m_vIBuffers; // Index buffers array.
bool m_bDeviceLost; // Device Lost.
int m_iAASurface;
Texture* m_pAATexture;
// C a m e r a M a t r i x e s
D3DMATRIX m_mProj, // Projection Matrix.
m_mView, // View Matrix.
m_mWorld, // World matrix.
m_m2D; // 2D Projection Matrix.
void CheckStencil(bool Antialiasing);
bool CheckStencilFMT();
bool CheckDevice(D3DCAPS9 *pCaps, DWORD dwBehavior);
// bad az Init ba seda zadan in tabe maghadir avalie engine set mishan.
bool AfterInit();
// Check for devil errors.
void CheckDevilErrors( char* TextureName );
// Precalculate the graphics card capacities.
virtual void InitGCC();
// Reset the direct3d device.
virtual bool ResetDevice();
}; // RendererDX
} // gfx
} // kge
#endif // RENDERERDX_H
#endif // WIN32