d07c171f |
1 | /* |
2 | Copyright (C) 2003 Rice1964 |
3 | |
4 | This program is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU General Public License |
6 | as published by the Free Software Foundation; either version 2 |
7 | of the License, or (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | */ |
18 | |
19 | #include "osal_opengl.h" |
20 | |
21 | #define M64P_PLUGIN_PROTOTYPES 1 |
22 | #include "m64p_plugin.h" |
23 | #include "Config.h" |
24 | #include "Debugger.h" |
25 | #if SDL_VIDEO_OPENGL |
26 | #include "OGLExtensions.h" |
27 | #endif |
28 | #include "OGLDebug.h" |
29 | #include "OGLGraphicsContext.h" |
30 | #include "TextureManager.h" |
31 | #include "Video.h" |
32 | #include "version.h" |
33 | #ifdef HAVE_GLES |
34 | #include "eglport.h" |
35 | #endif |
36 | |
37 | COGLGraphicsContext::COGLGraphicsContext() : |
38 | m_bSupportMultiTexture(false), |
39 | m_bSupportTextureEnvCombine(false), |
40 | m_bSupportSeparateSpecularColor(false), |
41 | m_bSupportSecondColor(false), |
42 | m_bSupportFogCoord(false), |
43 | m_bSupportTextureObject(false), |
44 | m_bSupportRescaleNormal(false), |
45 | m_bSupportLODBias(false), |
46 | m_bSupportTextureMirrorRepeat(false), |
47 | m_bSupportTextureLOD(false), |
48 | m_bSupportNVRegisterCombiner(false), |
49 | m_bSupportBlendColor(false), |
50 | m_bSupportBlendSubtract(false), |
51 | m_bSupportNVTextureEnvCombine4(false), |
52 | m_pVendorStr(NULL), |
53 | m_pRenderStr(NULL), |
54 | m_pExtensionStr(NULL), |
55 | m_pVersionStr(NULL) |
56 | { |
57 | } |
58 | |
59 | |
60 | COGLGraphicsContext::~COGLGraphicsContext() |
61 | { |
62 | } |
63 | |
64 | bool COGLGraphicsContext::Initialize(uint32 dwWidth, uint32 dwHeight, BOOL bWindowed ) |
65 | { |
66 | DebugMessage(M64MSG_INFO, "Initializing OpenGL Device Context."); |
67 | Lock(); |
68 | #ifdef HAVE_GLES |
69 | /* dwWidth = 800; |
70 | dwHeight = 480;*/ |
71 | #endif |
72 | CGraphicsContext::Get()->m_supportTextureMirror = false; |
73 | CGraphicsContext::Initialize(dwWidth, dwHeight, bWindowed ); |
74 | |
75 | if( bWindowed ) |
76 | { |
77 | windowSetting.statusBarHeightToUse = windowSetting.statusBarHeight; |
78 | windowSetting.toolbarHeightToUse = windowSetting.toolbarHeight; |
79 | } |
80 | else |
81 | { |
82 | windowSetting.statusBarHeightToUse = 0; |
83 | windowSetting.toolbarHeightToUse = 0; |
84 | } |
85 | |
86 | int depthBufferDepth = options.OpenglDepthBufferSetting; |
87 | int colorBufferDepth = 32; |
88 | int bVerticalSync = windowSetting.bVerticalSync; |
89 | if( options.colorQuality == TEXTURE_FMT_A4R4G4B4 ) colorBufferDepth = 16; |
90 | |
91 | // init sdl & gl |
92 | DebugMessage(M64MSG_VERBOSE, "Initializing video subsystem..."); |
93 | #ifdef HAVE_GLES |
94 | // init sdl & ourself |
95 | if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) |
96 | return false; |
97 | #else |
98 | if (CoreVideo_Init() != M64ERR_SUCCESS) |
99 | return false; |
100 | #endif |
101 | |
102 | /* hard-coded attribute values */ |
103 | const int iDOUBLEBUFFER = 1; |
104 | |
105 | #ifdef HAVE_GLES |
106 | SDL_SetVideoMode(800, 480, 0, (bWindowed)?0:SDL_FULLSCREEN); |
107 | SDL_ShowCursor(SDL_DISABLE); |
108 | EGL_Open(800, 480); |
109 | #else |
110 | /* set opengl attributes */ |
111 | CoreVideo_GL_SetAttribute(M64P_GL_DOUBLEBUFFER, iDOUBLEBUFFER); |
112 | CoreVideo_GL_SetAttribute(M64P_GL_SWAP_CONTROL, bVerticalSync); |
113 | CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, colorBufferDepth); |
114 | CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, depthBufferDepth); |
115 | |
116 | /* set multisampling */ |
117 | if (options.multiSampling > 0) |
118 | { |
119 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLEBUFFERS, 1); |
120 | if (options.multiSampling <= 2) |
121 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 2); |
122 | else if (options.multiSampling <= 4) |
123 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 4); |
124 | else if (options.multiSampling <= 8) |
125 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 8); |
126 | else |
127 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 16); |
128 | } |
129 | |
130 | /* Set the video mode */ |
131 | m64p_video_mode ScreenMode = bWindowed ? M64VIDEO_WINDOWED : M64VIDEO_FULLSCREEN; |
132 | m64p_video_flags flags = M64VIDEOFLAG_SUPPORT_RESIZING; |
133 | if (CoreVideo_SetVideoMode(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, colorBufferDepth, ScreenMode, flags) != M64ERR_SUCCESS) |
134 | { |
135 | DebugMessage(M64MSG_ERROR, "Failed to set %i-bit video mode: %ix%i", colorBufferDepth, (int)windowSetting.uDisplayWidth, (int)windowSetting.uDisplayHeight); |
136 | CoreVideo_Quit(); |
137 | return false; |
138 | } |
139 | |
140 | /* check that our opengl attributes were properly set */ |
141 | int iActual; |
142 | if (CoreVideo_GL_GetAttribute(M64P_GL_DOUBLEBUFFER, &iActual) == M64ERR_SUCCESS) |
143 | if (iActual != iDOUBLEBUFFER) |
144 | DebugMessage(M64MSG_WARNING, "Failed to set GL_DOUBLEBUFFER to %i. (it's %i)", iDOUBLEBUFFER, iActual); |
145 | if (CoreVideo_GL_GetAttribute(M64P_GL_SWAP_CONTROL, &iActual) == M64ERR_SUCCESS) |
146 | if (iActual != bVerticalSync) |
147 | DebugMessage(M64MSG_WARNING, "Failed to set GL_SWAP_CONTROL to %i. (it's %i)", bVerticalSync, iActual); |
148 | if (CoreVideo_GL_GetAttribute(M64P_GL_BUFFER_SIZE, &iActual) == M64ERR_SUCCESS) |
149 | if (iActual != colorBufferDepth) |
150 | DebugMessage(M64MSG_WARNING, "Failed to set GL_BUFFER_SIZE to %i. (it's %i)", colorBufferDepth, iActual); |
151 | if (CoreVideo_GL_GetAttribute(M64P_GL_DEPTH_SIZE, &iActual) == M64ERR_SUCCESS) |
152 | if (iActual != depthBufferDepth) |
153 | DebugMessage(M64MSG_WARNING, "Failed to set GL_DEPTH_SIZE to %i. (it's %i)", depthBufferDepth, iActual); |
154 | #endif |
155 | #if SDL_VIDEO_OPENGL |
156 | /* Get function pointers to OpenGL extensions (blame Microsoft Windows for this) */ |
157 | OGLExtensions_Init(); |
158 | #endif |
159 | |
160 | char caption[500]; |
161 | sprintf(caption, "%s v%i.%i.%i", PLUGIN_NAME, VERSION_PRINTF_SPLIT(PLUGIN_VERSION)); |
162 | CoreVideo_SetCaption(caption); |
163 | SetWindowMode(); |
164 | |
165 | InitState(); |
166 | InitOGLExtension(); |
167 | sprintf(m_strDeviceStats, "%.60s - %.128s : %.60s", m_pVendorStr, m_pRenderStr, m_pVersionStr); |
168 | TRACE0(m_strDeviceStats); |
169 | DebugMessage(M64MSG_INFO, "Using OpenGL: %s", m_strDeviceStats); |
170 | |
171 | Unlock(); |
172 | |
173 | Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); // Clear buffers |
174 | UpdateFrame(); |
175 | Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); |
176 | UpdateFrame(); |
177 | |
178 | m_bReady = true; |
179 | status.isVertexShaderEnabled = false; |
180 | |
181 | return true; |
182 | } |
183 | |
184 | bool COGLGraphicsContext::ResizeInitialize(uint32 dwWidth, uint32 dwHeight, BOOL bWindowed ) |
185 | { |
186 | #ifndef HAVE_GLES |
187 | Lock(); |
188 | |
189 | CGraphicsContext::Initialize(dwWidth, dwHeight, bWindowed ); |
190 | |
191 | int depthBufferDepth = options.OpenglDepthBufferSetting; |
192 | int colorBufferDepth = 32; |
193 | int bVerticalSync = windowSetting.bVerticalSync; |
194 | if( options.colorQuality == TEXTURE_FMT_A4R4G4B4 ) colorBufferDepth = 16; |
195 | |
196 | /* hard-coded attribute values */ |
197 | const int iDOUBLEBUFFER = 1; |
198 | |
199 | /* set opengl attributes */ |
200 | CoreVideo_GL_SetAttribute(M64P_GL_DOUBLEBUFFER, iDOUBLEBUFFER); |
201 | CoreVideo_GL_SetAttribute(M64P_GL_SWAP_CONTROL, bVerticalSync); |
202 | CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, colorBufferDepth); |
203 | CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, depthBufferDepth); |
204 | |
205 | /* set multisampling */ |
206 | if (options.multiSampling > 0) |
207 | { |
208 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLEBUFFERS, 1); |
209 | if (options.multiSampling <= 2) |
210 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 2); |
211 | else if (options.multiSampling <= 4) |
212 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 4); |
213 | else if (options.multiSampling <= 8) |
214 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 8); |
215 | else |
216 | CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 16); |
217 | } |
218 | |
219 | /* Call Mupen64plus core Video Extension to resize the window, which will create a new OpenGL Context under SDL */ |
220 | if (CoreVideo_ResizeWindow(windowSetting.uDisplayWidth, windowSetting.uDisplayHeight) != M64ERR_SUCCESS) |
221 | { |
222 | DebugMessage(M64MSG_ERROR, "Failed to set %i-bit video mode: %ix%i", colorBufferDepth, (int)windowSetting.uDisplayWidth, (int)windowSetting.uDisplayHeight); |
223 | CoreVideo_Quit(); |
224 | return false; |
225 | } |
226 | |
227 | InitState(); |
228 | Unlock(); |
229 | |
230 | Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); // Clear buffers |
231 | UpdateFrame(); |
232 | Clear(CLEAR_COLOR_AND_DEPTH_BUFFER); |
233 | UpdateFrame(); |
234 | #endif |
235 | return true; |
236 | } |
237 | |
238 | void COGLGraphicsContext::InitState(void) |
239 | { |
240 | m_pRenderStr = glGetString(GL_RENDERER); |
241 | m_pExtensionStr = glGetString(GL_EXTENSIONS); |
242 | m_pVersionStr = glGetString(GL_VERSION); |
243 | m_pVendorStr = glGetString(GL_VENDOR); |
244 | glMatrixMode(GL_PROJECTION); |
245 | OPENGL_CHECK_ERRORS; |
246 | glLoadIdentity(); |
247 | OPENGL_CHECK_ERRORS; |
248 | |
249 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
250 | OPENGL_CHECK_ERRORS; |
251 | glClearDepth(1.0f); |
252 | OPENGL_CHECK_ERRORS; |
253 | |
254 | #if SDL_VIDEO_OPENGL |
255 | glShadeModel(GL_SMOOTH); |
256 | OPENGL_CHECK_ERRORS; |
257 | |
258 | //position viewer |
259 | //glMatrixMode(GL_MODELVIEW); |
260 | //glLoadIdentity(); |
261 | |
262 | glDisable(GL_ALPHA_TEST); |
263 | OPENGL_CHECK_ERRORS; |
264 | #endif |
265 | |
266 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
267 | OPENGL_CHECK_ERRORS; |
268 | glDisable(GL_BLEND); |
269 | OPENGL_CHECK_ERRORS; |
270 | |
271 | glFrontFace(GL_CCW); |
272 | OPENGL_CHECK_ERRORS; |
273 | glDisable(GL_CULL_FACE); |
274 | OPENGL_CHECK_ERRORS; |
275 | #if SDL_VIDEO_OPENGL |
276 | glDisable(GL_NORMALIZE); |
277 | OPENGL_CHECK_ERRORS; |
278 | #endif |
279 | |
280 | glDepthFunc(GL_LEQUAL); |
281 | OPENGL_CHECK_ERRORS; |
282 | glEnable(GL_DEPTH_TEST); |
283 | OPENGL_CHECK_ERRORS; |
284 | |
285 | #if SDL_VIDEO_OPENGL |
286 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
287 | OPENGL_CHECK_ERRORS; |
288 | #endif |
289 | |
290 | glEnable(GL_BLEND); |
291 | OPENGL_CHECK_ERRORS; |
292 | #if SDL_VIDEO_OPENGL |
293 | glEnable(GL_ALPHA_TEST); |
294 | OPENGL_CHECK_ERRORS; |
295 | |
296 | glMatrixMode(GL_PROJECTION); |
297 | OPENGL_CHECK_ERRORS; |
298 | glLoadIdentity(); |
299 | OPENGL_CHECK_ERRORS; |
300 | |
301 | glDepthRange(-1, 1); |
302 | |
303 | #elif SDL_VIDEO_OPENGL_ES2 |
2f75cc30 |
304 | glDepthRangef(-1.0f, 1.0f); |
d07c171f |
305 | #endif |
306 | OPENGL_CHECK_ERRORS; |
307 | } |
308 | |
309 | void COGLGraphicsContext::InitOGLExtension(void) |
310 | { |
311 | // important extension features, it is very bad not to have these feature |
312 | #ifdef HAVE_GLES |
313 | m_bSupportMultiTexture = true; |
314 | m_bSupportTextureEnvCombine = true; |
315 | m_bSupportSeparateSpecularColor = true; |
2f75cc30 |
316 | m_bSupportSecondColor = false; |
d07c171f |
317 | m_bSupportFogCoord = false; |
318 | m_bSupportTextureObject = false; |
319 | m_bSupportRescaleNormal = true; |
320 | m_bSupportLODBias = false; |
321 | m_bSupportAnisotropicFiltering = true; |
322 | #else |
323 | m_bSupportMultiTexture = IsExtensionSupported(OSAL_GL_ARB_MULTITEXTURE); |
324 | m_bSupportTextureEnvCombine = IsExtensionSupported("GL_EXT_texture_env_combine"); |
325 | |
326 | m_bSupportSeparateSpecularColor = IsExtensionSupported("GL_EXT_separate_specular_color"); |
327 | m_bSupportSecondColor = IsExtensionSupported("GL_EXT_secondary_color"); |
328 | m_bSupportFogCoord = IsExtensionSupported("GL_EXT_fog_coord"); |
329 | m_bSupportTextureObject = IsExtensionSupported("GL_EXT_texture_object"); |
330 | |
331 | // Optional extension features |
332 | m_bSupportRescaleNormal = IsExtensionSupported("GL_EXT_rescale_normal"); |
333 | m_bSupportLODBias = IsExtensionSupported("GL_EXT_texture_lod_bias"); |
334 | m_bSupportAnisotropicFiltering = IsExtensionSupported("GL_EXT_texture_filter_anisotropic"); |
335 | #endif |
336 | // Compute maxAnisotropicFiltering |
337 | m_maxAnisotropicFiltering = 0; |
338 | |
339 | if( m_bSupportAnisotropicFiltering |
340 | && (options.anisotropicFiltering == 2 |
341 | || options.anisotropicFiltering == 4 |
342 | || options.anisotropicFiltering == 8 |
343 | || options.anisotropicFiltering == 16)) |
344 | { |
345 | //Get the max value of aniso that the graphic card support |
346 | glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_maxAnisotropicFiltering); |
347 | OPENGL_CHECK_ERRORS; |
348 | |
349 | // If user want more aniso than hardware can do |
350 | if(options.anisotropicFiltering > (uint32) m_maxAnisotropicFiltering) |
351 | { |
352 | DebugMessage(M64MSG_INFO, "A value of '%i' is set for AnisotropicFiltering option but the hardware has a maximum value of '%i' so this will be used", options.anisotropicFiltering, m_maxAnisotropicFiltering); |
353 | } |
354 | |
355 | //check if user want less anisotropy than hardware can do |
356 | if((uint32) m_maxAnisotropicFiltering > options.anisotropicFiltering) |
357 | m_maxAnisotropicFiltering = options.anisotropicFiltering; |
358 | } |
359 | |
360 | // Nvidia only extension features (optional) |
361 | m_bSupportNVRegisterCombiner = IsExtensionSupported("GL_NV_register_combiners"); |
362 | #ifdef HAVE_GLES |
363 | m_bSupportTextureMirrorRepeat = true; |
364 | #else |
365 | m_bSupportTextureMirrorRepeat = IsExtensionSupported("GL_IBM_texture_mirrored_repeat") || IsExtensionSupported("ARB_texture_mirrored_repeat"); |
366 | #endif |
367 | m_supportTextureMirror = m_bSupportTextureMirrorRepeat; |
368 | m_bSupportTextureLOD = IsExtensionSupported("GL_EXT_texture_lod"); |
369 | #ifdef HAVE_GLES |
370 | m_bSupportBlendColor = true; |
371 | m_bSupportBlendSubtract = true; |
372 | #else |
373 | m_bSupportBlendColor = IsExtensionSupported("GL_EXT_blend_color"); |
374 | m_bSupportBlendSubtract = IsExtensionSupported("GL_EXT_blend_subtract"); |
375 | #endif |
376 | m_bSupportNVTextureEnvCombine4 = IsExtensionSupported("GL_NV_texture_env_combine4"); |
377 | |
378 | } |
379 | |
380 | bool COGLGraphicsContext::IsExtensionSupported(const char* pExtName) |
381 | { |
382 | if (strstr((const char*)m_pExtensionStr, pExtName) != NULL) |
383 | { |
384 | DebugMessage(M64MSG_VERBOSE, "OpenGL Extension '%s' is supported.", pExtName); |
385 | return true; |
386 | } |
387 | else |
388 | { |
389 | DebugMessage(M64MSG_VERBOSE, "OpenGL Extension '%s' is NOT supported.", pExtName); |
390 | return false; |
391 | } |
392 | } |
393 | |
394 | bool COGLGraphicsContext::IsWglExtensionSupported(const char* pExtName) |
395 | { |
396 | if( m_pWglExtensionStr == NULL ) |
397 | return false; |
398 | |
399 | if( strstr((const char*)m_pWglExtensionStr, pExtName) != NULL ) |
400 | return true; |
401 | else |
402 | return false; |
403 | } |
404 | |
405 | |
406 | void COGLGraphicsContext::CleanUp() |
407 | { |
408 | #ifdef HAVE_GLES |
409 | EGL_Close(); |
410 | SDL_ShowCursor(SDL_ENABLE); |
411 | SDL_QuitSubSystem(SDL_INIT_VIDEO); |
412 | #else |
413 | CoreVideo_Quit(); |
414 | #endif |
415 | m_bReady = false; |
416 | } |
417 | |
418 | |
419 | void COGLGraphicsContext::Clear(ClearFlag dwFlags, uint32 color, float depth) |
420 | { |
421 | uint32 flag=0; |
422 | if( dwFlags&CLEAR_COLOR_BUFFER ) flag |= GL_COLOR_BUFFER_BIT; |
423 | if( dwFlags&CLEAR_DEPTH_BUFFER ) flag |= GL_DEPTH_BUFFER_BIT; |
424 | |
425 | float r = ((color>>16)&0xFF)/255.0f; |
426 | float g = ((color>> 8)&0xFF)/255.0f; |
427 | float b = ((color )&0xFF)/255.0f; |
428 | float a = ((color>>24)&0xFF)/255.0f; |
429 | glClearColor(r, g, b, a); |
430 | OPENGL_CHECK_ERRORS; |
431 | glClearDepth(depth); |
432 | OPENGL_CHECK_ERRORS; |
433 | glClear(flag); //Clear color buffer and depth buffer |
434 | OPENGL_CHECK_ERRORS; |
435 | } |
436 | |
437 | void COGLGraphicsContext::UpdateFrame(bool swaponly) |
438 | { |
439 | status.gFrameCount++; |
440 | |
441 | glFlush(); |
442 | OPENGL_CHECK_ERRORS; |
443 | //glFinish(); |
444 | //wglSwapIntervalEXT(0); |
445 | |
446 | /* |
447 | if (debuggerPauseCount == countToPause) |
448 | { |
449 | static int iShotNum = 0; |
450 | // get width, height, allocate buffer to store image |
451 | int width = windowSetting.uDisplayWidth; |
452 | int height = windowSetting.uDisplayHeight; |
453 | printf("Saving debug images: width=%i height=%i\n", width, height); |
454 | short *buffer = (short *) malloc(((width+3)&~3)*(height+1)*4); |
455 | glReadBuffer( GL_FRONT ); |
456 | // set up a BMGImage struct |
457 | struct BMGImageStruct img; |
458 | memset(&img, 0, sizeof(BMGImageStruct)); |
459 | InitBMGImage(&img); |
460 | img.bits = (unsigned char *) buffer; |
461 | img.bits_per_pixel = 32; |
462 | img.height = height; |
463 | img.width = width; |
464 | img.scan_width = width * 4; |
465 | // store the RGB color image |
466 | char chFilename[64]; |
467 | sprintf(chFilename, "dbg_rgb_%03i.png", iShotNum); |
468 | glReadPixels(0,0,width,height, GL_BGRA, GL_UNSIGNED_BYTE, buffer); |
469 | WritePNG(chFilename, img); |
470 | // store the Z buffer |
471 | sprintf(chFilename, "dbg_Z_%03i.png", iShotNum); |
472 | glReadPixels(0,0,width,height, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, buffer); |
473 | //img.bits_per_pixel = 16; |
474 | //img.scan_width = width * 2; |
475 | WritePNG(chFilename, img); |
476 | // dump a subset of the Z data |
477 | for (int y = 0; y < 480; y += 16) |
478 | { |
479 | for (int x = 0; x < 640; x+= 16) |
480 | printf("%4hx ", buffer[y*640 + x]); |
481 | printf("\n"); |
482 | } |
483 | printf("\n"); |
484 | // free memory and get out of here |
485 | free(buffer); |
486 | iShotNum++; |
487 | } |
488 | */ |
489 | |
490 | |
491 | // if emulator defined a render callback function, call it before buffer swap |
492 | if(renderCallback) |
493 | (*renderCallback)(status.bScreenIsDrawn); |
494 | #ifdef HAVE_GLES |
495 | EGL_SwapBuffers(); |
496 | #else |
497 | CoreVideo_GL_SwapBuffers(); |
498 | #endif |
499 | |
500 | /*if(options.bShowFPS) |
501 | { |
502 | static unsigned int lastTick=0; |
503 | static int frames=0; |
504 | unsigned int nowTick = SDL_GetTicks(); |
505 | frames++; |
506 | if(lastTick + 5000 <= nowTick) |
507 | { |
508 | char caption[200]; |
509 | sprintf(caption, "%s v%i.%i.%i - %.3f VI/S", PLUGIN_NAME, VERSION_PRINTF_SPLIT(PLUGIN_VERSION), frames/5.0); |
510 | CoreVideo_SetCaption(caption); |
511 | frames = 0; |
512 | lastTick = nowTick; |
513 | } |
514 | }*/ |
515 | |
516 | glDepthMask(GL_TRUE); |
517 | OPENGL_CHECK_ERRORS; |
518 | glClearDepth(1.0f); |
519 | OPENGL_CHECK_ERRORS; |
520 | if( !g_curRomInfo.bForceScreenClear ) |
521 | { |
522 | glClear(GL_DEPTH_BUFFER_BIT); |
523 | OPENGL_CHECK_ERRORS; |
524 | } |
525 | else |
526 | needCleanScene = true; |
527 | |
528 | status.bScreenIsDrawn = false; |
529 | } |
530 | |
531 | bool COGLGraphicsContext::SetFullscreenMode() |
532 | { |
533 | windowSetting.statusBarHeightToUse = 0; |
534 | windowSetting.toolbarHeightToUse = 0; |
535 | return true; |
536 | } |
537 | |
538 | bool COGLGraphicsContext::SetWindowMode() |
539 | { |
540 | windowSetting.statusBarHeightToUse = windowSetting.statusBarHeight; |
541 | windowSetting.toolbarHeightToUse = windowSetting.toolbarHeight; |
542 | return true; |
543 | } |
544 | int COGLGraphicsContext::ToggleFullscreen() |
545 | { |
546 | #ifndef HAVE_GLES |
547 | if (CoreVideo_ToggleFullScreen() == M64ERR_SUCCESS) |
548 | { |
549 | m_bWindowed = !m_bWindowed; |
550 | if(m_bWindowed) |
551 | SetWindowMode(); |
552 | else |
553 | SetFullscreenMode(); |
554 | } |
555 | #endif |
556 | return m_bWindowed?0:1; |
557 | } |
558 | |
559 | // This is a static function, will be called when the plugin DLL is initialized |
560 | void COGLGraphicsContext::InitDeviceParameters() |
561 | { |
562 | status.isVertexShaderEnabled = false; // Disable it for now |
563 | } |
564 | |
565 | // Get methods |
566 | bool COGLGraphicsContext::IsSupportAnisotropicFiltering() |
567 | { |
568 | return m_bSupportAnisotropicFiltering; |
569 | } |
570 | |
571 | int COGLGraphicsContext::getMaxAnisotropicFiltering() |
572 | { |
573 | return m_maxAnisotropicFiltering; |
574 | } |