| 1 | /* |
| 2 | * Glide64 - Glide video plugin for Nintendo 64 emulators. |
| 3 | * Copyright (c) 2002 Dave2001 |
| 4 | * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef MAIN_H |
| 22 | #define MAIN_H |
| 23 | |
| 24 | #include <m64p_types.h> |
| 25 | |
| 26 | #define LOG(...) // WriteLog(M64MSG_VERBOSE, __VA_ARGS__) |
| 27 | #define LOGINFO(...) WriteLog(M64MSG_INFO, __VA_ARGS__) |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | void WriteLog(m64p_msg_level level, const char *msg, ...); |
| 32 | #ifdef __cplusplus |
| 33 | } |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | #ifndef _WIN32 |
| 38 | //#define VPDEBUG |
| 39 | #endif |
| 40 | #ifdef VPDEBUG |
| 41 | void dump_tex(int id); |
| 42 | void dump_start(); |
| 43 | void dump_stop(); |
| 44 | extern int dumping; |
| 45 | #endif |
| 46 | |
| 47 | #define zscale 1.0f |
| 48 | |
| 49 | typedef struct _wrapper_config |
| 50 | { |
| 51 | int res; |
| 52 | int fbo; |
| 53 | int anisofilter; |
| 54 | int vram_size; |
| 55 | } wrapper_config; |
| 56 | extern wrapper_config config; |
| 57 | |
| 58 | |
| 59 | // VP added this utility function |
| 60 | // returns the bytes per pixel of a given GR texture format |
| 61 | int grTexFormatSize(int fmt); |
| 62 | |
| 63 | extern int packed_pixels_support; |
| 64 | extern int ati_sucks; |
| 65 | extern float largest_supported_anisotropy; |
| 66 | |
| 67 | extern int default_texture; // the infamous "32*1024*1024" is now configurable |
| 68 | extern int depth_texture; |
| 69 | void set_depth_shader(); |
| 70 | void set_bw_shader(); |
| 71 | extern float invtex[2]; |
| 72 | extern int buffer_cleared; // mark that the buffer has been cleared, used to check if we need to reload the texture buffer content |
| 73 | |
| 74 | #ifdef _WIN32 |
| 75 | #include <windows.h> |
| 76 | extern "C" { |
| 77 | #include <SDL_opengl.h> |
| 78 | extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; |
| 79 | extern PFNGLATTACHOBJECTARBPROC glAttachObjectARB; |
| 80 | extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; |
| 81 | extern PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT; |
| 82 | extern PFNGLBLENDFUNCSEPARATEEXTPROC glBlendFuncSeparateEXT; |
| 83 | extern PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; |
| 84 | extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; |
| 85 | extern PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; |
| 86 | extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; |
| 87 | extern PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT; |
| 88 | extern PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT; |
| 89 | extern PFNGLFOGCOORDFEXTPROC glFogCoordfEXT; |
| 90 | extern PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT; |
| 91 | extern PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT; |
| 92 | extern PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT; |
| 93 | extern PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT; |
| 94 | extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; |
| 95 | extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; |
| 96 | extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; |
| 97 | extern PFNGLLINKPROGRAMARBPROC glLinkProgramARB; |
| 98 | extern PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB; |
| 99 | extern PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT; |
| 100 | extern PFNGLSECONDARYCOLOR3FPROC glSecondaryColor3f; |
| 101 | extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; |
| 102 | extern PFNGLUNIFORM1FARBPROC glUniform1fARB; |
| 103 | extern PFNGLUNIFORM1IARBPROC glUniform1iARB; |
| 104 | extern PFNGLUNIFORM4FARBPROC glUniform4fARB; |
| 105 | extern PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; |
| 106 | typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); |
| 107 | } |
| 108 | #else |
| 109 | #include <stdio.h> |
| 110 | //#define printf(...) |
| 111 | #define GL_GLEXT_PROTOTYPES |
| 112 | #include <SDL_opengles2.h> |
| 113 | #endif // _WIN32 |
| 114 | #include "glide.h" |
| 115 | #include "glState.cpp" |
| 116 | |
| 117 | void display_warning(const unsigned char *text, ...); |
| 118 | void display_warning(const char *text, ...); |
| 119 | void init_geometry(); |
| 120 | void init_textures(); |
| 121 | void init_combiner(); |
| 122 | void free_textures(); |
| 123 | void updateCombiner(int i); |
| 124 | void updateCombinera(int i); |
| 125 | void remove_tex(unsigned int idmin, unsigned int idmax); |
| 126 | void add_tex(unsigned int id); |
| 127 | |
| 128 | #ifdef _WIN32 |
| 129 | extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB; |
| 130 | extern PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB; |
| 131 | extern PFNGLBLENDFUNCSEPARATEEXTPROC glBlendFuncSeparateEXT; |
| 132 | extern PFNGLFOGCOORDFPROC glFogCoordfEXT; |
| 133 | |
| 134 | extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; |
| 135 | extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; |
| 136 | extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; |
| 137 | extern PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; |
| 138 | extern PFNGLATTACHOBJECTARBPROC glAttachObjectARB; |
| 139 | extern PFNGLLINKPROGRAMARBPROC glLinkProgramARB; |
| 140 | extern PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; |
| 141 | extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; |
| 142 | extern PFNGLUNIFORM1IARBPROC glUniform1iARB; |
| 143 | extern PFNGLUNIFORM4IARBPROC glUniform4iARB; |
| 144 | extern PFNGLUNIFORM4FARBPROC glUniform4fARB; |
| 145 | extern PFNGLUNIFORM1FARBPROC glUniform1fARB; |
| 146 | extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; |
| 147 | extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; |
| 148 | extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; |
| 149 | extern PFNGLSECONDARYCOLOR3FPROC glSecondaryColor3f; |
| 150 | #endif |
| 151 | void check_compile(GLuint shader); |
| 152 | void check_link(GLuint program); |
| 153 | void vbo_enable(); |
| 154 | void vbo_disable(); |
| 155 | |
| 156 | //Vertex Attribute Locations |
| 157 | #define POSITION_ATTR 0 |
| 158 | #define COLOUR_ATTR 1 |
| 159 | #define TEXCOORD_0_ATTR 2 |
| 160 | #define TEXCOORD_1_ATTR 3 |
| 161 | #define FOG_ATTR 4 |
| 162 | |
| 163 | extern int w_buffer_mode; |
| 164 | extern int nbTextureUnits; |
| 165 | extern int width, height, widtho, heighto; |
| 166 | extern int tex0_width, tex0_height, tex1_width, tex1_height; |
| 167 | extern float texture_env_color[4]; |
| 168 | extern int fog_enabled; |
| 169 | extern float lambda; |
| 170 | extern int need_lambda[2]; |
| 171 | extern float lambda_color[2][4]; |
| 172 | extern int inverted_culling; |
| 173 | extern int culling_mode; |
| 174 | extern int render_to_texture; |
| 175 | extern int lfb_color_fmt; |
| 176 | extern int need_to_compile; |
| 177 | extern int blackandwhite0; |
| 178 | extern int blackandwhite1; |
| 179 | extern int TMU_SIZE; |
| 180 | |
| 181 | extern int blend_func_separate_support; |
| 182 | extern int fog_coord_support; |
| 183 | //extern int pbuffer_support; |
| 184 | extern int glsl_support; |
| 185 | extern unsigned int pBufferAddress; |
| 186 | extern int viewport_width, viewport_height, viewport_offset, nvidia_viewport_hack; |
| 187 | extern int UMAmode; |
| 188 | |
| 189 | void grChromaRangeExt(GrColor_t color0, GrColor_t color1, FxU32 mode); |
| 190 | void grChromaRangeModeExt(GrChromakeyMode_t mode); |
| 191 | void grTexChromaRangeExt(GrChipID_t tmu, GrColor_t color0, GrColor_t color1, GrTexChromakeyMode_t mode); |
| 192 | void grTexChromaModeExt(GrChipID_t tmu, GrChromakeyMode_t mode); |
| 193 | void updateTexture(); |
| 194 | void reloadTexture(); |
| 195 | void free_combiners(); |
| 196 | void compile_shader(); |
| 197 | void set_lambda(); |
| 198 | void set_copy_shader(); |
| 199 | void disable_textureSizes(); |
| 200 | |
| 201 | // config functions |
| 202 | |
| 203 | //FX_ENTRY void FX_CALL grConfigWrapperExt(HINSTANCE instance, HWND hwnd); |
| 204 | FX_ENTRY void FX_CALL grConfigWrapperExt(FxI32, FxI32, FxBool, FxBool); |
| 205 | FX_ENTRY GrScreenResolution_t FX_CALL grWrapperFullScreenResolutionExt(FxU32*, FxU32*); |
| 206 | FX_ENTRY char ** FX_CALL grQueryResolutionsExt(FxI32*); |
| 207 | FX_ENTRY FxBool FX_CALL grKeyPressedExt(FxU32 key); |
| 208 | FX_ENTRY void FX_CALL grGetGammaTableExt(FxU32, FxU32*, FxU32*, FxU32*); |
| 209 | |
| 210 | int getFullScreenWidth(); |
| 211 | int getFullScreenHeight(); |
| 212 | |
| 213 | // ZIGGY framebuffer copy extension |
| 214 | // allow to copy the depth or color buffer from back/front to front/back |
| 215 | #define GR_FBCOPY_MODE_DEPTH 0 |
| 216 | #define GR_FBCOPY_MODE_COLOR 1 |
| 217 | #define GR_FBCOPY_BUFFER_BACK 0 |
| 218 | #define GR_FBCOPY_BUFFER_FRONT 1 |
| 219 | FX_ENTRY void FX_CALL grFramebufferCopyExt(int x, int y, int w, int h, |
| 220 | int buffer_from, int buffer_to, int mode); |
| 221 | |
| 222 | |
| 223 | // COMBINE extension |
| 224 | |
| 225 | typedef FxU32 GrCCUColor_t; |
| 226 | typedef FxU32 GrACUColor_t; |
| 227 | typedef FxU32 GrTCCUColor_t; |
| 228 | typedef FxU32 GrTACUColor_t; |
| 229 | |
| 230 | typedef FxU32 GrCombineMode_t; |
| 231 | #define GR_FUNC_MODE_ZERO 0x00 |
| 232 | #define GR_FUNC_MODE_X 0x01 |
| 233 | #define GR_FUNC_MODE_ONE_MINUS_X 0x02 |
| 234 | #define GR_FUNC_MODE_NEGATIVE_X 0x03 |
| 235 | #define GR_FUNC_MODE_X_MINUS_HALF 0x04 |
| 236 | |
| 237 | #define GR_CMBX_ZERO 0x00 |
| 238 | #define GR_CMBX_TEXTURE_ALPHA 0x01 |
| 239 | #define GR_CMBX_ALOCAL 0x02 |
| 240 | #define GR_CMBX_AOTHER 0x03 |
| 241 | #define GR_CMBX_B 0x04 |
| 242 | #define GR_CMBX_CONSTANT_ALPHA 0x05 |
| 243 | #define GR_CMBX_CONSTANT_COLOR 0x06 |
| 244 | #define GR_CMBX_DETAIL_FACTOR 0x07 |
| 245 | #define GR_CMBX_ITALPHA 0x08 |
| 246 | #define GR_CMBX_ITRGB 0x09 |
| 247 | #define GR_CMBX_LOCAL_TEXTURE_ALPHA 0x0a |
| 248 | #define GR_CMBX_LOCAL_TEXTURE_RGB 0x0b |
| 249 | #define GR_CMBX_LOD_FRAC 0x0c |
| 250 | #define GR_CMBX_OTHER_TEXTURE_ALPHA 0x0d |
| 251 | #define GR_CMBX_OTHER_TEXTURE_RGB 0x0e |
| 252 | #define GR_CMBX_TEXTURE_RGB 0x0f |
| 253 | #define GR_CMBX_TMU_CALPHA 0x10 |
| 254 | #define GR_CMBX_TMU_CCOLOR 0x11 |
| 255 | |
| 256 | |
| 257 | FX_ENTRY void FX_CALL |
| 258 | grColorCombineExt(GrCCUColor_t a, GrCombineMode_t a_mode, |
| 259 | GrCCUColor_t b, GrCombineMode_t b_mode, |
| 260 | GrCCUColor_t c, FxBool c_invert, |
| 261 | GrCCUColor_t d, FxBool d_invert, |
| 262 | FxU32 shift, FxBool invert); |
| 263 | |
| 264 | FX_ENTRY void FX_CALL |
| 265 | grAlphaCombineExt(GrACUColor_t a, GrCombineMode_t a_mode, |
| 266 | GrACUColor_t b, GrCombineMode_t b_mode, |
| 267 | GrACUColor_t c, FxBool c_invert, |
| 268 | GrACUColor_t d, FxBool d_invert, |
| 269 | FxU32 shift, FxBool invert); |
| 270 | |
| 271 | FX_ENTRY void FX_CALL |
| 272 | grTexColorCombineExt(GrChipID_t tmu, |
| 273 | GrTCCUColor_t a, GrCombineMode_t a_mode, |
| 274 | GrTCCUColor_t b, GrCombineMode_t b_mode, |
| 275 | GrTCCUColor_t c, FxBool c_invert, |
| 276 | GrTCCUColor_t d, FxBool d_invert, |
| 277 | FxU32 shift, FxBool invert); |
| 278 | |
| 279 | FX_ENTRY void FX_CALL |
| 280 | grTexAlphaCombineExt(GrChipID_t tmu, |
| 281 | GrTACUColor_t a, GrCombineMode_t a_mode, |
| 282 | GrTACUColor_t b, GrCombineMode_t b_mode, |
| 283 | GrTACUColor_t c, FxBool c_invert, |
| 284 | GrTACUColor_t d, FxBool d_invert, |
| 285 | FxU32 shift, FxBool invert); |
| 286 | |
| 287 | FX_ENTRY void FX_CALL |
| 288 | grConstantColorValueExt(GrChipID_t tmu, |
| 289 | GrColor_t value); |
| 290 | |
| 291 | #define CHECK_FRAMEBUFFER_STATUS() \ |
| 292 | {\ |
| 293 | GLenum status; \ |
| 294 | status = glCheckFramebufferStatus(GL_FRAMEBUFFER); \ |
| 295 | /*display_warning("%x\n", status);*/\ |
| 296 | switch(status) { \ |
| 297 | case GL_FRAMEBUFFER_COMPLETE: \ |
| 298 | /*display_warning("framebuffer complete!\n");*/\ |
| 299 | break; \ |
| 300 | case GL_FRAMEBUFFER_UNSUPPORTED: \ |
| 301 | display_warning("framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");\ |
| 302 | /* you gotta choose different formats */ \ |
| 303 | /*assert(0);*/ \ |
| 304 | break; \ |
| 305 | case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: \ |
| 306 | display_warning("framebuffer INCOMPLETE_ATTACHMENT\n");\ |
| 307 | break; \ |
| 308 | case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: \ |
| 309 | display_warning("framebuffer FRAMEBUFFER_MISSING_ATTACHMENT\n");\ |
| 310 | break; \ |
| 311 | case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: \ |
| 312 | display_warning("framebuffer FRAMEBUFFER_DIMENSIONS\n");\ |
| 313 | break; \ |
| 314 | default: \ |
| 315 | break; \ |
| 316 | /* programming error; will fail on all hardware */ \ |
| 317 | /*assert(0);*/ \ |
| 318 | }\ |
| 319 | } |
| 320 | |
| 321 | #ifdef VPDEBUG |
| 322 | #define LOGGING |
| 323 | #endif |
| 324 | |
| 325 | #ifdef LOGGING |
| 326 | void OPEN_LOG(); |
| 327 | void CLOSE_LOG(); |
| 328 | //void LOG(const char *text, ...); |
| 329 | #else // LOGGING |
| 330 | #define OPEN_LOG() |
| 331 | #define CLOSE_LOG() |
| 332 | //#define LOG |
| 333 | #endif // LOGGING |
| 334 | |
| 335 | #endif |