summaryrefslogtreecommitdiffhomepage
path: root/Magic2/VideoDX9.h
blob: a9e0d6f60db87c74df86c2796ad8f2f902ddc1e9 (plain)
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
/*  Project nGenEx
	Destroyer Studios LLC
	Copyright © 1997-2004. All Rights Reserved.

	SUBSYSTEM:    nGenEx.lib
	FILE:         VideoDX9.h
	AUTHOR:       John DiCamillo


	OVERVIEW
	========
	Direct3D and Direct3D Video classes for DirectX 7 
*/

#ifndef VideoDX9_h
#define VideoDX9_h

#include "Video.h"
#include "VideoSettings.h"
#include "List.h"

// +--------------------------------------------------------------------+

class  VideoDX9;
class  VideoDX9Enum;
class  VideoDX9VertexBuffer;
class  VideoDX9IndexBuffer;
struct VideoDX9ScreenVertex;
class  Surface;
class  Segment;

struct VideoDX9ScreenVertex;
struct VideoDX9SolidVertex;
struct VideoDX9LuminousVertex;
struct VideoDX9LineVertex;


// +--------------------------------------------------------------------+

class VideoDX9 : public Video
{
public:
	VideoDX9(const HWND& window, VideoSettings* vs);
	virtual ~VideoDX9();

	virtual const VideoSettings* 
	GetVideoSettings() const { return &video_settings; }
	virtual bool   SetVideoSettings(const VideoSettings* vs);

	virtual bool   SetBackgroundColor(Color c);
	virtual bool   SetGammaLevel(int g);
	virtual bool   SetObjTransform(const Matrix& o, const Point& l);

	virtual bool   SetupParams();
	virtual bool   Reset(const VideoSettings* vs);

	virtual bool   StartFrame();
	virtual bool   EndFrame();

	virtual int    Width()     const { return width;   }
	virtual int    Height()    const { return height;  }
	virtual int    Depth()     const { return bpp;     }

	virtual void   RecoverSurfaces();

	virtual bool   ClearAll();
	virtual bool   ClearDepthBuffer();
	virtual bool   Present();
	virtual bool   Pause();
	virtual bool   Resume();

	virtual IDirect3D9*        Direct3D()     const { return d3d; }
	virtual IDirect3DDevice9*  D3DDevice()    const { return d3ddevice; }
	static  IDirect3DDevice9*  GetD3DDevice9();

	virtual bool   IsModeSupported(int width, int height, int bpp) const;
	virtual bool   IsHardware()               const { return true;   }
	virtual int    ZDepth()                   const { return zdepth; }
	virtual DWORD  VidMemFree()               const;
	virtual int    D3DLevel()                 const { return 9;      }
	virtual int    MaxTexSize()               const;
	virtual int    MaxTexAspect()             const;
	virtual int    GammaLevel()               const { return gamma;  }

	virtual bool   Capture(Bitmap& bmp);
	virtual bool   GetWindowRect(Rect& r);
	virtual bool   SetWindowRect(const Rect& r);
	virtual bool   SetViewport(int x, int y, int w, int h);
	virtual bool   SetCamera(const Camera* cam);
	virtual bool   SetEnvironment(Bitmap** faces);
	virtual bool   SetAmbient(Color c);
	virtual bool   SetLights(const List<Light>& lights);
	virtual bool   SetProjection(float fov, 
	float znear=1.0f, 
	float zfar=1.0e6f, 
	DWORD type=PROJECTION_PERSPECTIVE);
	virtual bool   SetRenderState(RENDER_STATE state, DWORD value);
	virtual bool   SetBlendType(int blend_type);

	virtual bool   DrawPolys(int npolys, Poly* p);
	virtual bool   DrawScreenPolys(int npolys, Poly* p, int blend=0);
	virtual bool   DrawSolid(Solid* s, DWORD blend_modes=0xf);
	virtual bool   DrawShadow(Solid* s, int nverts, Vec3* verts, bool vis=false);
	virtual bool   DrawLines(int nlines, Vec3* v, Color c, int blend=0);
	virtual bool   DrawScreenLines(int nlines, float* v, Color c, int blend=0);
	virtual bool   DrawPoints(VertexSet* v);
	virtual bool   DrawPolyOutline(Poly* p);
	virtual bool   UseMaterial(Material* m);

	virtual bool   UseXFont(const char* name, int size, bool b, bool i);
	virtual bool   DrawText(const char* text, int count, const Rect& rect,
	DWORD format, Color c);

	virtual void   PreloadTexture(Bitmap* bmp);
	virtual void   PreloadSurface(Surface* s);
	virtual void   InvalidateCache();

	static  void   CreateD3DMatrix(D3DMATRIX& result, const Matrix& m, const Point& p);
	static  void   CreateD3DMatrix(D3DMATRIX& result, const Matrix& m, const Vec3&  v);
	static  void   CreateD3DMaterial(D3DMATERIAL9& result, const Material& mtl);

private:
	bool           CreateBuffers();
	bool           DestroyBuffers();
	bool           PopulateScreenVerts(VertexSet* vset);
	bool           PrepareSurface(Surface* s);
	bool           DrawSegment(Segment* s);

	int            PrepareMaterial(Material* m);
	bool           SetupPass(int n);

	HWND                    hwnd;
	int                     width;
	int                     height;
	int                     bpp;
	int                     gamma;
	int                     zdepth;
	Color                   background;

	VideoDX9Enum*           dx9enum;
	VideoSettings           video_settings;

	IDirect3D9*             d3d;
	IDirect3DDevice9*       d3ddevice;
	D3DPRESENT_PARAMETERS   d3dparams;
	D3DSURFACE_DESC         back_buffer_desc;
	bool                    device_lost;

	BYTE*                   surface;

	DWORD                   texture_format[3];
	D3DGAMMARAMP            gamma_ramp;
	double                  fade;

	Rect                    rect;

	IDirect3DVertexDeclaration9*  vertex_declaration;
	ID3DXEffect*                  magic_fx;
	BYTE*                         magic_fx_code;
	int                           magic_fx_code_len;

	IDirect3DTexture9*      current_texture;
	int                     current_blend_state;
	int                     scene_active;
	DWORD                   render_state[RENDER_STATE_MAX];
	Material*               use_material;

	Material*               segment_material;
	int                     strategy;
	int                     passes;

	ID3DXFont*              d3dx_font;
	char                    font_name[64];
	int                     font_size;
	bool                    font_bold;
	bool                    font_ital;

	Color                   ambient;
	int                     nlights;

	int                     first_vert;
	int                     num_verts;

	VideoDX9VertexBuffer*   screen_vbuf;
	VideoDX9IndexBuffer*    screen_ibuf;
	VideoDX9ScreenVertex*   font_verts;
	WORD*                   font_indices;
	int                     font_nverts;

	VideoDX9ScreenVertex*   screen_line_verts;
	VideoDX9LineVertex*     line_verts;
};

#endif VideoDX9_h