JD2022-TU1/main/extern/Camcam/LIBS/Render/D3D_Class.h

193 lines
No EOL
6.4 KiB
C++

#ifdef __D3D
#include <d3dx9.h>
#include "TRACK.H"
#define MaxD3DTextures 2048
#define MaxD3DMaterials 16
#define MaxD3DLights 16
#define MaxD3DVertices 8192
#define MaxD3DIndices MaxD3DVertices*4
#define GL_TEXTURE_2D 1
#define GL_LIGHTING 2
#define _D3D_TEX(oglRef) ((IDirect3DTexture9*)(oglRef))
#define _D3D_TEX_PTR(oglRefPtr) ((IDirect3DTexture9**)(oglRefPtr))
#define _TO_D3DCOLOR(abgr) D3DCOLOR_ARGB((abgr >> 24) & 0xFF,(abgr)&0xFF, (abgr>>8)&0xFF, (abgr>>16)&0xFF);
class D3D_DI:public DrawInterface
{
public :
LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
D3DCAPS9 d3dcaps;
D3DPRESENT_PARAMETERS d3dpp;
LPDIRECT3DTEXTURE9 srTex, srTex2;
LPDIRECT3DSURFACE9 m_pDepthStencilTemp;
D3DMATERIAL9 d3dMat[MaxD3DMaterials];
D3DLIGHT9 d3dLight[MaxD3DLights];
struct Vertex
{
float _x, _y, _z;
float _nx, _ny, _nz;
D3DCOLOR _color;
float _u, _v, _w; // texture coordinates
static const DWORD FVF;
Vertex(float x, float y, float z, D3DCOLOR color, float nx, float ny, float nz, float u, float v, float w)
{
_x = x; _y = y; _z = z;
_color = color;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v; _w = w;
}
};
/*struct Vertex2
{
float _x, _y, _z;
float _nx, _ny, _nz;
D3DCOLOR _color;
float _u, _v, _w, _w2; // texture coordinates
static const DWORD FVF;
Vertex2(float x, float y, float z, D3DCOLOR color, float nx, float ny, float nz, float u, float v, float w, float w2)
{
_x = x; _y = y; _z = z;
_color = color;
_nx = nx; _ny = ny; _nz = nz;
_u = u; _v = v; _w = w; _w2 = w2;
}
};//*/
IDirect3DVertexBuffer9* m_pVertexBuffer;
u32 m_uVBStartIndex, m_uVBCount;
IDirect3DIndexBuffer9* m_pIndexBuffer;
u32 m_uIBStartIndex, m_uIBCount;
IDirect3DVertexBuffer9* Quad;
DWORD m_aTexStates[16]; // contains on/off states for all texture stages
D3D_DI()
{
}
virtual ~D3D_DI()
{
}
void Init();
// Used to emulate clear with potential color masking
void ClearColorWithQuad(u32 color);
bool IsTextureValid(unsigned int oglRef);
// For D3D 2D texture coord translation
void ModifyTextureTranslation(D3DXMATRIX* pMat);
// TODO: Optimize this
// Does a StretchRect equivalent (but flips it upside down)
void CopyTextureFromBackBuffer(LPDIRECT3DTEXTURE9 pDest, int xOffset, int yOffset, int x, int y, int width, int height, bool isLuminance = false);
void SafeCopyTextureFromBackBuffer(LPDIRECT3DTEXTURE9* ppDest, int xOffset, int yOffset, int x, int y, int width, int height, bool isLuminance = false);
// Sets the relevant texture stage ops
void EnableTextureOps();
void DisableTextureOps();
void PrintError(HRESULT);
void Begin(RECT *HdcRect);
void End();
void Flush();
void OnDeviceLost();
void OnDeviceReset();
void Perspective(float FocaleLenght);
void Holographic(Vector *pUP,float WindowWith);
void Ortho();
void Flip(s32 ShowMe);
void Clear(u32 Color);
void ClearZ();
void Matrix(MATRIX *MatrixToSet);
void RenderMesh(Mesh *pMyMesh,u32 Num, u32 Base);
void ReverseRenderMesh(Mesh *pMyMesh,u32 TextureSource,u32 Num, u32 Base);
void SetRS(RS *RenderMode,u32 TextureIndex);
void DrawQuad(u32 Color,float X, float Y,float Xsize, float Ysize,float TX,float TY,float TW,float TH);
void DrawCenteredQuad(u32 Color,float Xsize, float Ysize,float FX,float FY);
void SetCurrentColor(u32 Color) { CurrentColor = Color; };
u32 GetCurrentColor() { return CurrentColor;};
void ReadFrameBuffer(s32 X,s32 Y,s32 SX,s32 SY, MAP *dest);
/* Texture management */
u32 CreateTexture(MAP *pExternalReferenceRGBA,u32 ColorMode, bool forceCreation = false) ;
void CreateTexture(u32 IndexToCreate,u32 ColorMode) ;
u32 CreateLayerTexture(MAP *pExternalReferenceRGBA,u32 LayerIndex);
void DestroyLayerTexture(u32 TextureIndex);
void SetTextureColorMode(u32 Index,u32 ColorMode) ;
void UpdateTexture_BM_2_HW(u32 TextureIndex, bool isDynamic = true);
void UpdateTexture_HW_2_BM(u32 TextureIndex,u32 UpdateSoftBuffer,s32 SourceX,s32 SourceY);
void UpdateTexture_HW_2_BM(u32 TextureIndex,u32 UpdateSoftBuffer) {UpdateTexture_HW_2_BM(TextureIndex,UpdateSoftBuffer,0,0);};
void DestroyTexture(u32 TextureIndex);
void DrawQuad(u32 TextureIndex,s32 XMin,s32 XMax,s32 YMin,s32 YMax,RS *RenderMode = NULL);
void DrawQuadDistord(u32 TextureIndex,s32 XMin,s32 XMax,s32 YMin,s32 YMax,RS *RenderMode = NULL);
void DrawLine(u32 Color,Vector *A,Vector *B, int Lenght = 0);
void ToggleTextures(bool);
void Setexture(u32 TextureIndex,float *UVMatrix = NULL);
void SetFog(u32 OnOff,float Near , float far , u32 Color);
void BeginTextureTarget(u32 TextureIndex,u32 SaveFrontBuffer = 0);
void EndTextureTarget(u32 TextureIndex,u32 bUpdateSoftBuffer);
void SetViewport(s32 X,s32 Y,s32 SX,s32 SY);
void SetClipping(s32 X,s32 Y,s32 SX,s32 SY);
u32 GetTexFreeIndex();
void AfterEffect(u32 ulType,u32 Color,float Factor1,float Factor2,float Factor3 = 0.0f,float Factor4 = 0.0f,float Factor5 = 0.0f);
void LayerOperation(u32 ulType,u32 SlotIndex,u32 Color,float Factor1,float Factor2) ;
void ValidateLayer(u32 Index);
/* Text */
void DrawText(unsigned char *Txt,float X, float Y, float FX, float FY , u32 ColorRGBA , u32 DrawModeShadow = 1);
void GetTextSize(unsigned char *Txt,s32 *DX,s32 *DY, SIZE *CharBounds = NULL);
void DrawTextCentered(unsigned char *pTEXT,u32 Color);
void RenderText(unsigned char *Txt,float X, float Y, float FX, float FY , u32 ColorRGBA, MAP *fontMap, int TextureIdx, SIZE *CharPos, SIZE *CharBounds, u32 optionMask, int blendingMode = -1);
/* Win32 */
void Destroy(); // Destroy
void AdaptTOWindow(HWND hWnd);
void ChangeMode(HWND Mother, bool UseGDI);
void SetResolution(u32 SX,u32 SY);
void Blitte();
/* Particules */
void DrawParticules(void *particuleList, int nbParticules, u32 TextureIndex, SIZE grid,RS *RenderState, MATRIX Orientation);
/* Fur */
void DrawFur(void *fur, u32 TextureIndex,RS *RenderState, MATRIX Orientation, u32 debug);
/* Picking */
/* Matrix Overloadd */
/* 0 = Projection , 1 = Model , 2 = Texture */
void GetMatrix(u32 Mode,float *pDest);
void SetMatrix(u32 Mode,float *pDest);
u32 GetDriverType() {return 1;}; // "opengl" = 0 , 'D3D' = 1
};
#endif