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 COPENGL_H 8 #define COPENGL_H 9 10 #include <windows.h> 11 #include "gl_core_3_1.h" 12 #include "cgFunctions.h" 13 #include "CGLCG.h" 14 #include "../shaders/glsl.h" 15 16 #include "wglext.h" 17 #include "IS9xDisplayOutput.h" 18 19 enum current_ogl_shader_type { OGL_SHADER_NONE, OGL_SHADER_GLSL, OGL_SHADER_CG, OGL_SHADER_GLSL_OLD}; 20 21 class COpenGL : public IS9xDisplayOutput 22 { 23 private: 24 HDC hDC; 25 HGLRC hRC; 26 HWND hWnd; 27 GLuint drawTexture; 28 GLuint drawBuffer; 29 GLfloat vertices[8]; 30 GLfloat texcoords[8]; 31 unsigned char * noPboBuffer; 32 TCHAR currentShaderFile[MAX_PATH]; 33 34 int frameCount; 35 36 bool initDone; 37 bool fullscreen; 38 unsigned int outTextureWidth; 39 unsigned int outTextureHeight; 40 unsigned int afterRenderWidth, afterRenderHeight; 41 42 bool shaderFunctionsLoaded; 43 44 bool pboFunctionsLoaded; 45 46 CGcontext cgContext; 47 CGprogram cgVertexProgram, cgFragmentProgram; 48 current_ogl_shader_type shader_type; 49 bool cgAvailable; 50 51 CGLCG *cgShader; 52 GLSLShader *glslShader; 53 54 GLuint shaderProgram; 55 GLuint vertexShader; 56 GLuint fragmentShader; 57 58 PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; 59 60 bool SetShaders(const TCHAR *file); 61 void checkForCgError(const char *situation); 62 bool SetShadersCG(const TCHAR *file); 63 bool SetShadersGLSL(const TCHAR *glslFileName); 64 bool SetShadersGLSL_OLD(const TCHAR *glslFileName); 65 bool LoadShaderFunctions(); 66 bool LoadPBOFunctions(); 67 void CreateDrawSurface(unsigned int width, unsigned int height); 68 void DestroyDrawSurface(void); 69 bool ChangeDrawSurfaceSize(unsigned int width, unsigned int height); 70 void SetupVertices(); 71 bool ShaderAvailable(); 72 bool NPOTAvailable(); 73 74 public: 75 COpenGL(); 76 ~COpenGL(); 77 bool Initialize(HWND hWnd); 78 void DeInitialize(); 79 void Render(SSurface Src); 80 bool ChangeRenderSize(unsigned int newWidth, unsigned int newHeight); 81 bool ApplyDisplayChanges(void); 82 bool SetFullscreen(bool fullscreen); 83 void SetSnes9xColorFormat(void); 84 void EnumModes(std::vector<dMode> *modeVector); 85 void SetSwapInterval(int frames); GetActiveShader()86 GLSLShader *GetActiveShader() 87 { 88 return glslShader; 89 } 90 }; 91 92 93 #endif 94