1 /*****************************************************************************\
2      Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3                 This file is licensed under the Snes9x License.
4    For further information, consult the LICENSE file in the root directory.
5 \*****************************************************************************/
6 
7 #ifndef W9XDIRECT3D_H
8 #define W9XDIRECT3D_H
9 
10 #define MAX_SHADER_TEXTURES 8
11 
12 #include <d3d9.h>
13 #include <windows.h>
14 
15 #include "cgFunctions.h"
16 #include "CD3DCG.h"
17 
18 #include "render.h"
19 #include "wsnes9x.h"
20 #include "IS9xDisplayOutput.h"
21 
22 #define FVF_COORDS_TEX D3DFVF_XYZ | D3DFVF_TEX1
23 
24 typedef struct _VERTEX {
25 		float x, y, z;
26 		float tx, ty;
27 		float lutx, luty;
_VERTEX_VERTEX28 		_VERTEX() {}
_VERTEX_VERTEX29 		_VERTEX(float x,float y,float z,float tx,float ty,float lutx, float luty) {
30 			this->x=x;this->y=y;this->z=z;this->tx=tx;this->ty=ty;this->lutx=lutx;this->luty=luty;
31 		}
32 } VERTEX; //our custom vertex with a constuctor for easier assignment
33 
34 enum current_d3d_shader_type { D3D_SHADER_NONE, D3D_SHADER_CG };
35 
36 class CDirect3D: public IS9xDisplayOutput
37 {
38 private:
39 	bool                  init_done;					//has initialize been called?
40 	LPDIRECT3D9           pD3D;
41 	LPDIRECT3DDEVICE9     pDevice;
42 	LPDIRECT3DTEXTURE9    drawSurface;					//the texture used for all drawing operations
43 
44 	LPDIRECT3DVERTEXBUFFER9 vertexBuffer;
45 	D3DPRESENT_PARAMETERS dPresentParams;
46 	unsigned int filterScale;							//the current maximum filter scale (at least 2)
47 	unsigned int afterRenderWidth, afterRenderHeight;	//dimensions after filter has been applied
48 	unsigned int quadTextureSize;						//size of the texture (only multiples of 2)
49 	bool fullscreen;									//are we currently displaying in fullscreen mode
50 
51 	VERTEX vertexStream[4];								//the 4 vertices that make up our display rectangle
52 
53 	static const D3DVERTEXELEMENT9 vertexElems[4];
54 	LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
55 
56 	LPDIRECT3DTEXTURE9      rubyLUT[MAX_SHADER_TEXTURES];
57 	CGcontext cgContext;
58 	current_d3d_shader_type shader_type;
59 	bool cgAvailable;
60 
61 	CD3DCG *cgShader;
62 
63 	float shaderTimer;
64 	int shaderTimeStart;
65 	int shaderTimeElapsed;
66 	int frameCount;
67 
68 	bool BlankTexture(LPDIRECT3DTEXTURE9 texture);
69 	void CreateDrawSurface();
70 	void DestroyDrawSurface();
71 	bool ChangeDrawSurfaceSize(unsigned int scale);
72 	void SetViewport();
73 	void SetupVertices();
74 	bool ResetDevice();
75 	void SetFiltering();
76 	bool SetShader(const TCHAR *file);
77 	void checkForCgError(const char *situation);
78 	bool SetShaderCG(const TCHAR *file);
79 	void Clear();
80 
81 public:
82 	CDirect3D();
83 	~CDirect3D();
84 	bool Initialize(HWND hWnd);
85 	void DeInitialize();
86 	void Render(SSurface Src);
87 	bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight);
88 	bool ApplyDisplayChanges(void);
89 	bool SetFullscreen(bool fullscreen);
90 	void SetSnes9xColorFormat();
91 	void EnumModes(std::vector<dMode> *modeVector);
92 };
93 
94 #endif
95