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 CGGLCG_H
8 #define CGGLCG_H
9 
10 #include <windows.h>
11 #include "gl_core_3_1.h"
12 #include "cgFunctions.h"
13 #include "CCGShader.h"
14 #include <vector>
15 #include <deque>
16 #include "image_functions.h"
17 
18 typedef struct _xySize {
19 	double x;
20 	double y;
21 } xySize;
22 
23 class CGLCG
24 {
25 private:
26 	typedef struct _shaderPass {
27 		cgScaleParams scaleParams;
28 		bool linearFilter;
29         unsigned frameCounterMod;
30         bool floatFbo;
31 		CGprogram cgVertexProgram, cgFragmentProgram;
32 		GLuint tex;
33 		GLuint fbo;
34 		xySize outputSize;
35 		xySize textureSize;
36 		GLfloat	texcoords[8];
_shaderPass_shaderPass37 		_shaderPass()  {cgVertexProgram=NULL;
38 					    cgFragmentProgram=NULL;
39 						fbo=NULL;
40 						tex=NULL;}
41 	} shaderPass;
42 	typedef struct _prevPass {
43 		GLuint tex;
44 		xySize videoSize;
45 		xySize textureSize;
46 		GLfloat	texCoords[8];
_prevPass_prevPass47 		_prevPass() {tex=0;}
48 	} prevPass;
49 	typedef struct _lookupTexture {
50 		char id[PATH_MAX];
51 		GLuint tex;
_lookupTexture_lookupTexture52 		_lookupTexture() {tex=NULL;}
53 	} lookupTexture;
54 
55 	typedef std::vector<shaderPass> glPassVector;
56 	typedef std::vector<lookupTexture> glLutVector;
57 	typedef std::deque<prevPass> glPrevDeque;
58 	typedef std::vector<CGparameter> glAttribParams;
59 	glPassVector shaderPasses;
60 	glLutVector lookupTextures;
61 	glPrevDeque prevPasses;
62 	glAttribParams cgAttribParams;
63 
64 	bool fboFunctionsLoaded;
65 	bool shaderLoaded;
66 	bool LoadFBOFunctions();
67 	void checkForCgError(const char *situation);
68 	void setTexCoords(int pass,xySize inputSize,xySize textureSize,bool topdown=false);
69 	void setShaderVars(int pass);
70 	void resetAttribParams();
71 
72 	CGcontext cgContext;
73 	unsigned int frameCnt;
74 	static const GLfloat lut_coords[8];
75 
76 
77 public:
78 	CGLCG(CGcontext cgContext);
79 	~CGLCG(void);
80 
81 	bool LoadShader(const TCHAR *shaderFile);
82 	void Render(GLuint &origTex, xySize textureSize, xySize inputSize, xySize viewportSize, xySize windowSize);
83 	void ClearPasses();
84 };
85 
86 #endif
87