trunk/src/osd/sdl/drawogl.c
| r243778 | r243779 | |
| 27 | 27 | // standard SDL headers |
| 28 | 28 | #define TOBEMIGRATED 1 |
| 29 | 29 | #include "sdlinc.h" |
| 30 | | #else |
| 31 | | #define SDLMAME_SDL2 1 |
| 32 | | #include "GL/gl.h" |
| 33 | | #include "GL/glext.h" |
| 34 | | #include "GL/wglext.h" |
| 35 | | |
| 36 | | typedef HGLRC SDL_GLContext; |
| 37 | 30 | #endif |
| 38 | 31 | |
| 39 | 32 | // OpenGL headers |
| 40 | | #ifndef OSD_WINDOWS |
| 41 | 33 | #include "osd_opengl.h" |
| 34 | |
| 35 | #ifdef OSD_WINDOWS |
| 36 | #define SDLMAME_SDL2 1 |
| 37 | #ifndef USE_DISPATCH_GL |
| 38 | #include "GL/wglext.h" |
| 42 | 39 | #endif |
| 40 | #endif |
| 41 | |
| 43 | 42 | #include "modules/lib/osdlib.h" |
| 43 | #include "modules/lib/osdobj_common.h" |
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | #include "gl_shader_tool.h" |
| r243778 | r243779 | |
| 193 | 193 | // TYPES |
| 194 | 194 | //============================================================ |
| 195 | 195 | |
| 196 | #if (SDLMAME_SDL2) |
| 197 | |
| 198 | #ifdef OSD_WINDOWS |
| 199 | class win_gl_context : public osd_gl_context |
| 200 | { |
| 201 | public: |
| 202 | win_gl_context(HWND window) : osd_gl_context(), m_context(0), m_window(NULL), m_hdc(0) |
| 203 | { |
| 204 | m_error[0] = 0; |
| 205 | |
| 206 | this->wglGetProcAddress = (PROC WINAPI (*)(LPCSTR lpszProc)) GetProcAddress(m_module, "wglGetProcAddress"); |
| 207 | this->wglCreateContext = (HGLRC WINAPI (*)(HDC hdc)) GetProcAddress(m_module, "wglCreateContext"); |
| 208 | this->wglDeleteContext = (BOOL WINAPI (*)(HGLRC hglrc)) GetProcAddress(m_module, "wglDeleteContext"); |
| 209 | this->wglMakeCurrent = (BOOL WINAPI (*)(HDC hdc, HGLRC hglrc)) GetProcAddress(m_module, "wglMakeCurrent"); |
| 210 | |
| 211 | m_hdc = GetDC(window); |
| 212 | if (!setupPixelFormat(m_hdc)) |
| 213 | { |
| 214 | m_context = wglCreateContext(m_hdc); |
| 215 | if (!m_context) |
| 216 | { |
| 217 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, m_error, 255, NULL); |
| 218 | return; |
| 219 | } |
| 220 | wglMakeCurrent(m_hdc, m_context); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | virtual ~win_gl_context() |
| 225 | { |
| 226 | wglDeleteContext(m_context); |
| 227 | ReleaseDC(m_window, m_hdc); |
| 228 | } |
| 229 | |
| 230 | virtual void MakeCurrent() |
| 231 | { |
| 232 | wglMakeCurrent(m_hdc, m_context); |
| 233 | } |
| 234 | |
| 235 | virtual const char *LastErrorMsg() |
| 236 | { |
| 237 | if (m_error[0] == 0) |
| 238 | return NULL; |
| 239 | else |
| 240 | return m_error; |
| 241 | } |
| 242 | |
| 243 | virtual void *getProcAddress(const char *proc) |
| 244 | { |
| 245 | void *ret = (void *) GetProcAddress(m_module, proc); |
| 246 | if (ret == NULL) |
| 247 | ret = (void *) wglGetProcAddress(proc); |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | virtual int SetSwapInterval(const int swap) |
| 252 | { |
| 253 | // FIXME: Missing! |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | virtual void SwapBuffer() |
| 258 | { |
| 259 | SwapBuffers(m_hdc); |
| 260 | //wglSwapLayerBuffers(GetDC(window().m_hwnd), WGL_SWAP_MAIN_PLANE); |
| 261 | } |
| 262 | |
| 263 | static void load_library() |
| 264 | { |
| 265 | m_module = LoadLibraryA("opengl32.dll"); |
| 266 | } |
| 267 | |
| 268 | private: |
| 269 | |
| 270 | int setupPixelFormat(HDC hDC) |
| 271 | { |
| 272 | PIXELFORMATDESCRIPTOR pfd = { |
| 273 | sizeof(PIXELFORMATDESCRIPTOR), /* size */ |
| 274 | 1, /* version */ |
| 275 | PFD_SUPPORT_OPENGL | |
| 276 | PFD_DRAW_TO_WINDOW | |
| 277 | PFD_DOUBLEBUFFER, /* support double-buffering */ |
| 278 | PFD_TYPE_RGBA, /* color type */ |
| 279 | 32, /* prefered color depth */ |
| 280 | 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ |
| 281 | 0, /* no alpha buffer */ |
| 282 | 0, /* alpha bits (ignored) */ |
| 283 | 0, /* no accumulation buffer */ |
| 284 | 0, 0, 0, 0, /* accum bits (ignored) */ |
| 285 | 16, /* depth buffer */ |
| 286 | 0, /* no stencil buffer */ |
| 287 | 0, /* no auxiliary buffers */ |
| 288 | PFD_MAIN_PLANE, /* main layer */ |
| 289 | 0, /* reserved */ |
| 290 | 0, 0, 0, /* no layer, visible, damage masks */ |
| 291 | }; |
| 292 | int pixelFormat; |
| 293 | |
| 294 | pixelFormat = ChoosePixelFormat(hDC, &pfd); |
| 295 | if (pixelFormat == 0) { |
| 296 | strcpy(m_error, "ChoosePixelFormat failed"); |
| 297 | return 1; |
| 298 | } |
| 299 | |
| 300 | if (SetPixelFormat(hDC, pixelFormat, &pfd) != TRUE) { |
| 301 | strcpy(m_error, "SetPixelFormat failed."); |
| 302 | return 1; |
| 303 | } |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | HGLRC m_context; |
| 309 | HWND m_window; |
| 310 | HDC m_hdc; |
| 311 | char m_error[256]; |
| 312 | |
| 313 | PROC WINAPI (*wglGetProcAddress)(LPCSTR lpszProc); |
| 314 | HGLRC WINAPI (*wglCreateContext)(HDC hdc); |
| 315 | BOOL WINAPI (*wglDeleteContext)(HGLRC hglrc); |
| 316 | BOOL WINAPI (*wglMakeCurrent)(HDC hdc, HGLRC hglrc); |
| 317 | |
| 318 | static HMODULE m_module; |
| 319 | }; |
| 320 | |
| 321 | HMODULE win_gl_context::m_module; |
| 322 | |
| 323 | |
| 324 | #else |
| 325 | class sdl_gl_context : public osd_gl_context |
| 326 | { |
| 327 | public: |
| 328 | sdl_gl_context(SDL_Window *window) : osd_gl_context(), m_context(0), m_window(window) |
| 329 | { |
| 330 | m_error[0] = 0; |
| 331 | m_context = SDL_GL_CreateContext(window); |
| 332 | if (!m_context) |
| 333 | { |
| 334 | snprintf(m_error,255, "OpenGL not supported on this driver: %s", SDL_GetError()); |
| 335 | } |
| 336 | } |
| 337 | virtual ~sdl_gl_context() |
| 338 | { |
| 339 | SDL_GL_DeleteContext(m_context); |
| 340 | } |
| 341 | virtual void MakeCurrent() |
| 342 | { |
| 343 | SDL_GL_MakeCurrent(m_window, m_context); |
| 344 | } |
| 345 | |
| 346 | virtual int SetSwapInterval(const int swap) |
| 347 | { |
| 348 | return SDL_GL_SetSwapInterval(swap); |
| 349 | } |
| 350 | |
| 351 | virtual const char *LastErrorMsg() |
| 352 | { |
| 353 | if (m_error[0] == 0) |
| 354 | return NULL; |
| 355 | else |
| 356 | return m_error; |
| 357 | } |
| 358 | virtual void *getProcAddress(const char *proc) |
| 359 | { |
| 360 | return SDL_GL_GetProcAddress(proc); |
| 361 | } |
| 362 | |
| 363 | virtual void SwapBuffer() |
| 364 | { |
| 365 | SDL_GL_SwapWindow(m_window); |
| 366 | } |
| 367 | |
| 368 | private: |
| 369 | SDL_GLContext m_context; |
| 370 | SDL_Window *m_window; |
| 371 | char m_error[256]; |
| 372 | }; |
| 373 | #endif |
| 374 | #else |
| 375 | // SDL 1.2 |
| 376 | class sdl12_gl_context : public osd_gl_context |
| 377 | { |
| 378 | public: |
| 379 | sdl12_gl_context(SDL_Surface *window) : osd_gl_context(), m_window(window) |
| 380 | { |
| 381 | m_error[0] = 0; |
| 382 | } |
| 383 | virtual ~sdl12_gl_context() |
| 384 | { |
| 385 | } |
| 386 | virtual void MakeCurrent() |
| 387 | { |
| 388 | } |
| 389 | |
| 390 | virtual int SetSwapInterval(const int swap) |
| 391 | { |
| 392 | // Not supported on 1.2 |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | virtual const char *LastErrorMsg() |
| 397 | { |
| 398 | if (m_error[0] == 0) |
| 399 | return NULL; |
| 400 | else |
| 401 | return m_error; |
| 402 | } |
| 403 | |
| 404 | virtual void *getProcAddress(const char *proc) |
| 405 | { |
| 406 | return SDL_GL_GetProcAddress(proc); |
| 407 | } |
| 408 | |
| 409 | virtual void SwapBuffer() |
| 410 | { |
| 411 | SDL_GL_SwapBuffers(); |
| 412 | } |
| 413 | |
| 414 | private: |
| 415 | SDL_Surface *m_window; |
| 416 | char m_error[256]; |
| 417 | }; |
| 418 | |
| 419 | |
| 420 | #endif |
| 421 | |
| 196 | 422 | //============================================================ |
| 197 | 423 | // Textures |
| 198 | 424 | //============================================================ |
| r243778 | r243779 | |
| 262 | 488 | : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0), |
| 263 | 489 | m_width(0), m_height(0), |
| 264 | 490 | m_blitwidth(0), m_blitheight(0), |
| 265 | | #if (SDLMAME_SDL2) |
| 266 | | m_gl_context_id(0), |
| 267 | | #else |
| 268 | | #endif |
| 491 | m_gl_context(NULL), |
| 269 | 492 | m_initialized(0), |
| 270 | 493 | m_last_blendmode(0), |
| 271 | 494 | m_texture_max_width(0), |
| r243778 | r243779 | |
| 342 | 565 | int m_blitwidth; |
| 343 | 566 | int m_blitheight; |
| 344 | 567 | |
| 345 | | #if (SDLMAME_SDL2) |
| 346 | | SDL_GLContext m_gl_context_id; |
| 347 | | #ifdef OSD_WINDOWS |
| 348 | | HDC m_hdc; |
| 349 | | #endif |
| 350 | | #else |
| 351 | | #endif |
| 568 | osd_gl_context *m_gl_context; |
| 352 | 569 | |
| 353 | 570 | int m_initialized; // is everything well initialized, i.e. all GL stuff etc. |
| 354 | 571 | // 3D info (GL mode only) |
| r243778 | r243779 | |
| 533 | 750 | } |
| 534 | 751 | |
| 535 | 752 | //============================================================ |
| 536 | | // Windows Compatibility |
| 537 | | //============================================================ |
| 538 | | |
| 539 | | #ifdef OSD_WINDOWS |
| 540 | | PROC SDL_GL_GetProcAddress(const char *procname) |
| 541 | | { |
| 542 | | return wglGetProcAddress(procname); |
| 543 | | } |
| 544 | | #endif |
| 545 | | |
| 546 | | //============================================================ |
| 547 | 753 | // Load the OGL function addresses |
| 548 | 754 | //============================================================ |
| 549 | 755 | |
| 550 | | static void loadgl_functions(void) |
| 756 | static void loadgl_functions(osd_gl_context *context) |
| 551 | 757 | { |
| 552 | 758 | #ifdef USE_DISPATCH_GL |
| 553 | 759 | |
| r243778 | r243779 | |
| 558 | 764 | */ |
| 559 | 765 | |
| 560 | 766 | #define OSD_GL(ret,func,params) \ |
| 561 | | if (!( func = (ret (APIENTRY *)params) SDL_GL_GetProcAddress( #func ) )) \ |
| 767 | if (!( func = (ret (APIENTRY *)params) context->getProcAddress( #func ) )) \ |
| 562 | 768 | { err_count++; osd_printf_error("GL function %s not found!\n", #func ); } |
| 563 | 769 | |
| 564 | 770 | #define OSD_GL_UNUSED(ret,func,params) |
| r243778 | r243779 | |
| 577 | 783 | // Load GL library |
| 578 | 784 | //============================================================ |
| 579 | 785 | |
| 786 | #ifdef USE_DISPATCH_GL |
| 787 | osd_gl_dispatch *gl_dispatch; |
| 788 | #endif |
| 789 | |
| 580 | 790 | static void load_gl_lib(running_machine &machine) |
| 581 | 791 | { |
| 582 | | #ifdef USE_DISPATCH_GL |
| 583 | 792 | if (!dll_loaded) |
| 584 | 793 | { |
| 794 | #ifdef OSD_WINDOWS |
| 795 | win_gl_context::load_library(); |
| 796 | #else |
| 797 | #ifdef USE_DISPATCH_GL |
| 585 | 798 | /* |
| 586 | 799 | * directfb and and x11 use this env var |
| 587 | 800 | * SDL_VIDEO_GL_DRIVER |
| r243778 | r243779 | |
| 598 | 811 | } |
| 599 | 812 | osd_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>"); |
| 600 | 813 | /* FIXME: must be freed as well */ |
| 814 | #endif |
| 815 | #endif |
| 601 | 816 | gl_dispatch = (osd_gl_dispatch *) osd_malloc(sizeof(osd_gl_dispatch)); |
| 602 | 817 | dll_loaded=1; |
| 603 | 818 | } |
| 604 | | #endif |
| 605 | 819 | } |
| 606 | 820 | |
| 607 | 821 | void sdl_info_ogl::initialize_gl() |
| r243778 | r243779 | |
| 788 | 1002 | // a |
| 789 | 1003 | //============================================================ |
| 790 | 1004 | |
| 791 | | #ifdef OSD_WINDOWS |
| 792 | | void |
| 793 | | setupPixelFormat(HDC hDC) |
| 794 | | { |
| 795 | | PIXELFORMATDESCRIPTOR pfd = { |
| 796 | | sizeof(PIXELFORMATDESCRIPTOR), /* size */ |
| 797 | | 1, /* version */ |
| 798 | | PFD_SUPPORT_OPENGL | |
| 799 | | PFD_DRAW_TO_WINDOW | |
| 800 | | PFD_DOUBLEBUFFER, /* support double-buffering */ |
| 801 | | PFD_TYPE_RGBA, /* color type */ |
| 802 | | 32, /* prefered color depth */ |
| 803 | | 0, 0, 0, 0, 0, 0, /* color bits (ignored) */ |
| 804 | | 0, /* no alpha buffer */ |
| 805 | | 0, /* alpha bits (ignored) */ |
| 806 | | 0, /* no accumulation buffer */ |
| 807 | | 0, 0, 0, 0, /* accum bits (ignored) */ |
| 808 | | 16, /* depth buffer */ |
| 809 | | 0, /* no stencil buffer */ |
| 810 | | 0, /* no auxiliary buffers */ |
| 811 | | PFD_MAIN_PLANE, /* main layer */ |
| 812 | | 0, /* reserved */ |
| 813 | | 0, 0, 0, /* no layer, visible, damage masks */ |
| 814 | | }; |
| 815 | | int pixelFormat; |
| 816 | | |
| 817 | | pixelFormat = ChoosePixelFormat(hDC, &pfd); |
| 818 | | if (pixelFormat == 0) { |
| 819 | | osd_printf_error("ChoosePixelFormat failed.\n"); |
| 820 | | exit(1); |
| 821 | | } |
| 822 | | |
| 823 | | if (SetPixelFormat(hDC, pixelFormat, &pfd) != TRUE) { |
| 824 | | osd_printf_error("SetPixelFormat failed.\n"); |
| 825 | | exit(1); |
| 826 | | } |
| 827 | | } |
| 828 | | #endif |
| 829 | 1005 | int sdl_info_ogl::create() |
| 830 | 1006 | { |
| 831 | 1007 | #if (SDLMAME_SDL2) |
| 832 | 1008 | // create renderer |
| 833 | 1009 | #ifdef OSD_WINDOWS |
| 834 | | m_hdc = GetDC(window().m_hwnd); |
| 835 | | setupPixelFormat(m_hdc); |
| 836 | | m_gl_context_id = wglCreateContext(m_hdc); |
| 837 | | if (!m_gl_context_id) |
| 838 | | { |
| 839 | | char errorStr[1024]; |
| 840 | | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, errorStr, 255, NULL); |
| 841 | | osd_printf_error("OpenGL not supported on this driver %s\n", errorStr); |
| 842 | | return 1; |
| 843 | | } |
| 844 | | wglMakeCurrent(m_hdc, m_gl_context_id); |
| 1010 | m_gl_context = global_alloc(win_gl_context(window().m_hwnd)); |
| 845 | 1011 | #else |
| 846 | | m_gl_context_id = SDL_GL_CreateContext(window().sdl_window()); |
| 847 | | if (!m_gl_context_id) |
| 1012 | m_gl_context = global_alloc(sdl_gl_context(window().sdl_window())); |
| 1013 | #endif |
| 1014 | #else |
| 1015 | m_gl_context = global_alloc(sdl12_gl_context(window().sdl_surface())); |
| 1016 | #endif |
| 1017 | if (m_gl_context->LastErrorMsg() != NULL) |
| 848 | 1018 | { |
| 849 | | osd_printf_error("OpenGL not supported on this driver: %s\n", SDL_GetError()); |
| 1019 | osd_printf_error("%s\n", m_gl_context->LastErrorMsg()); |
| 850 | 1020 | return 1; |
| 851 | 1021 | } |
| 852 | | #endif |
| 1022 | m_gl_context->SetSwapInterval(video_config.waitvsync ? 1 : 0); |
| 853 | 1023 | |
| 854 | | #ifndef OSD_WINDOWS |
| 855 | | SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); |
| 856 | | #endif |
| 857 | | #else |
| 858 | | #endif |
| 859 | 1024 | |
| 860 | 1025 | m_blittimer = 0; |
| 861 | 1026 | m_surf_w = 0; |
| r243778 | r243779 | |
| 871 | 1036 | /* load any GL function addresses |
| 872 | 1037 | * this must be done here because we need a context |
| 873 | 1038 | */ |
| 874 | | loadgl_functions(); |
| 1039 | loadgl_functions(m_gl_context); |
| 875 | 1040 | initialize_gl(); |
| 876 | 1041 | |
| 877 | 1042 | |
| r243778 | r243779 | |
| 892 | 1057 | |
| 893 | 1058 | destroy_all_textures(); |
| 894 | 1059 | |
| 895 | | #if (SDLMAME_SDL2) |
| 896 | | #ifdef OSD_WINDOWS |
| 897 | | wglDeleteContext(m_gl_context_id); |
| 898 | | ReleaseDC(window().m_hwnd, m_hdc); |
| 899 | | #else |
| 900 | | SDL_GL_DeleteContext(m_gl_context_id); |
| 901 | | #endif |
| 902 | | #endif |
| 903 | | |
| 1060 | global_free(m_gl_context); |
| 1061 | m_gl_context = NULL; |
| 904 | 1062 | } |
| 905 | 1063 | |
| 906 | 1064 | |
| r243778 | r243779 | |
| 932 | 1090 | if ( !m_initialized ) |
| 933 | 1091 | return; |
| 934 | 1092 | |
| 935 | | #if (SDLMAME_SDL2) |
| 936 | | #ifdef OSD_WINDOWS |
| 937 | | wglMakeCurrent(m_hdc, m_gl_context_id); |
| 938 | | #else |
| 939 | | SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id); |
| 940 | | #endif |
| 941 | | #endif |
| 1093 | m_gl_context->MakeCurrent(); |
| 942 | 1094 | |
| 943 | 1095 | if(window().m_primlist) |
| 944 | 1096 | { |
| r243778 | r243779 | |
| 1043 | 1195 | // VBO: |
| 1044 | 1196 | if( m_usevbo ) |
| 1045 | 1197 | { |
| 1046 | | pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) SDL_GL_GetProcAddress("glGenBuffers"); |
| 1047 | | pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) SDL_GL_GetProcAddress("glDeleteBuffers"); |
| 1048 | | pfn_glBindBuffer = (PFNGLBINDBUFFERPROC) SDL_GL_GetProcAddress("glBindBuffer"); |
| 1049 | | pfn_glBufferData = (PFNGLBUFFERDATAPROC) SDL_GL_GetProcAddress("glBufferData"); |
| 1050 | | pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) SDL_GL_GetProcAddress("glBufferSubData"); |
| 1198 | pfn_glGenBuffers = (PFNGLGENBUFFERSPROC) m_gl_context->getProcAddress("glGenBuffers"); |
| 1199 | pfn_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) m_gl_context->getProcAddress("glDeleteBuffers"); |
| 1200 | pfn_glBindBuffer = (PFNGLBINDBUFFERPROC) m_gl_context->getProcAddress("glBindBuffer"); |
| 1201 | pfn_glBufferData = (PFNGLBUFFERDATAPROC) m_gl_context->getProcAddress("glBufferData"); |
| 1202 | pfn_glBufferSubData = (PFNGLBUFFERSUBDATAPROC) m_gl_context->getProcAddress("glBufferSubData"); |
| 1051 | 1203 | } |
| 1052 | 1204 | // PBO: |
| 1053 | 1205 | if ( m_usepbo ) |
| 1054 | 1206 | { |
| 1055 | | pfn_glMapBuffer = (PFNGLMAPBUFFERPROC) SDL_GL_GetProcAddress("glMapBuffer"); |
| 1056 | | pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) SDL_GL_GetProcAddress("glUnmapBuffer"); |
| 1207 | pfn_glMapBuffer = (PFNGLMAPBUFFERPROC) m_gl_context->getProcAddress("glMapBuffer"); |
| 1208 | pfn_glUnmapBuffer= (PFNGLUNMAPBUFFERPROC) m_gl_context->getProcAddress("glUnmapBuffer"); |
| 1057 | 1209 | } |
| 1058 | 1210 | // FBO: |
| 1059 | 1211 | if ( m_usefbo ) |
| 1060 | 1212 | { |
| 1061 | | pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glIsFramebufferEXT"); |
| 1062 | | pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) SDL_GL_GetProcAddress("glBindFramebufferEXT"); |
| 1063 | | pfn_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSEXTPROC) SDL_GL_GetProcAddress("glDeleteFramebuffersEXT"); |
| 1064 | | pfn_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSEXTPROC) SDL_GL_GetProcAddress("glGenFramebuffersEXT"); |
| 1065 | | pfn_glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) SDL_GL_GetProcAddress("glCheckFramebufferStatusEXT"); |
| 1066 | | pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) SDL_GL_GetProcAddress("glFramebufferTexture2DEXT"); |
| 1213 | pfn_glIsFramebuffer = (PFNGLISFRAMEBUFFEREXTPROC) m_gl_context->getProcAddress("glIsFramebufferEXT"); |
| 1214 | pfn_glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC) m_gl_context->getProcAddress("glBindFramebufferEXT"); |
| 1215 | pfn_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSEXTPROC) m_gl_context->getProcAddress("glDeleteFramebuffersEXT"); |
| 1216 | pfn_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSEXTPROC) m_gl_context->getProcAddress("glGenFramebuffersEXT"); |
| 1217 | pfn_glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) m_gl_context->getProcAddress("glCheckFramebufferStatusEXT"); |
| 1218 | pfn_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) m_gl_context->getProcAddress("glFramebufferTexture2DEXT"); |
| 1067 | 1219 | } |
| 1068 | 1220 | |
| 1069 | 1221 | if ( m_usevbo && |
| r243778 | r243779 | |
| 1195 | 1347 | if ( m_useglsl ) |
| 1196 | 1348 | { |
| 1197 | 1349 | #ifdef GL_ARB_multitexture |
| 1198 | | pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); |
| 1350 | pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) m_gl_context->getProcAddress("glActiveTextureARB"); |
| 1199 | 1351 | #else |
| 1200 | | pfn_glActiveTexture = (PFNGLACTIVETEXTUREPROC) SDL_GL_GetProcAddress("glActiveTexture"); |
| 1352 | pfn_glActiveTexture = (PFNGLACTIVETEXTUREPROC) m_gl_context->getProcAddress("glActiveTexture"); |
| 1201 | 1353 | #endif |
| 1202 | 1354 | if (!pfn_glActiveTexture) |
| 1203 | 1355 | { |
| r243778 | r243779 | |
| 1211 | 1363 | |
| 1212 | 1364 | if ( m_useglsl ) |
| 1213 | 1365 | { |
| 1214 | | m_glsl = glsl_shader_init(); |
| 1366 | m_glsl = glsl_shader_init(m_gl_context); |
| 1215 | 1367 | m_useglsl = (m_glsl != NULL ? 1 : 0); |
| 1216 | 1368 | |
| 1217 | 1369 | if ( ! m_useglsl ) |
| r243778 | r243779 | |
| 1348 | 1500 | clear_flags(FI_CHANGED); |
| 1349 | 1501 | } |
| 1350 | 1502 | |
| 1351 | | #if (SDLMAME_SDL2) |
| 1352 | | #ifdef OSD_WINDOWS |
| 1353 | | wglMakeCurrent(m_hdc, m_gl_context_id); |
| 1354 | | #else |
| 1355 | | SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id); |
| 1356 | | #endif |
| 1357 | | #endif |
| 1503 | m_gl_context->MakeCurrent(); |
| 1358 | 1504 | |
| 1359 | 1505 | if (m_init_context) |
| 1360 | 1506 | { |
| r243778 | r243779 | |
| 1702 | 1848 | window().m_primlist->release_lock(); |
| 1703 | 1849 | m_init_context = 0; |
| 1704 | 1850 | |
| 1705 | | #if (!SDLMAME_SDL2) |
| 1706 | | SDL_GL_SwapBuffers(); |
| 1707 | | #else |
| 1708 | | #ifdef OSD_WINDOWS |
| 1709 | | SwapBuffers(m_hdc); |
| 1710 | | //wglSwapLayerBuffers(GetDC(window().m_hwnd), WGL_SWAP_MAIN_PLANE); |
| 1711 | | #else |
| 1712 | | SDL_GL_SwapWindow(window().sdl_window()); |
| 1713 | | #endif |
| 1714 | | #endif |
| 1851 | m_gl_context->SwapBuffer(); |
| 1852 | |
| 1715 | 1853 | return 0; |
| 1716 | 1854 | } |
| 1717 | 1855 | |
trunk/src/osd/sdl/gl_shader_tool.c
| r243778 | r243779 | |
| 54 | 54 | PFNGLUNIFORM4IVARBPROC pfn_glUniform4ivARB=NULL; |
| 55 | 55 | |
| 56 | 56 | |
| 57 | | int gl_shader_loadExtention(PFNGLGETPROCADDRESSOS GetProcAddress) |
| 57 | int gl_shader_loadExtention(osd_gl_context *gl_ctx) |
| 58 | 58 | { |
| 59 | | pfn_glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) GetProcAddress("glGetObjectParameterivARB"); |
| 60 | | pfn_glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) GetProcAddress ("glGetInfoLogARB"); |
| 61 | | pfn_glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) GetProcAddress ("glDeleteObjectARB"); |
| 62 | | pfn_glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GetProcAddress ("glCreateShaderObjectARB"); |
| 63 | | pfn_glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GetProcAddress ("glShaderSourceARB"); |
| 64 | | pfn_glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GetProcAddress ("glCompileShaderARB"); |
| 65 | | pfn_glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GetProcAddress ("glCreateProgramObjectARB"); |
| 66 | | pfn_glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GetProcAddress ("glAttachObjectARB"); |
| 67 | | pfn_glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GetProcAddress ("glLinkProgramARB"); |
| 68 | | pfn_glValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC) GetProcAddress ("glValidateProgramARB"); |
| 69 | | pfn_glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GetProcAddress ("glUseProgramObjectARB"); |
| 70 | | pfn_glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GetProcAddress ("glGetUniformLocationARB"); |
| 71 | | pfn_glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GetProcAddress ("glUniform1fARB"); |
| 72 | | pfn_glUniform1iARB = (PFNGLUNIFORM1IARBPROC) GetProcAddress ("glUniform1iARB"); |
| 73 | | pfn_glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) GetProcAddress ("glUniform1fvARB"); |
| 74 | | pfn_glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) GetProcAddress ("glUniform2fvARB"); |
| 75 | | pfn_glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GetProcAddress ("glUniform3fvARB"); |
| 76 | | pfn_glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GetProcAddress ("glUniform4fvARB"); |
| 77 | | pfn_glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) GetProcAddress ("glUniform1ivARB"); |
| 78 | | pfn_glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) GetProcAddress ("glUniform2ivARB"); |
| 79 | | pfn_glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) GetProcAddress ("glUniform3ivARB"); |
| 80 | | pfn_glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) GetProcAddress ("glUniform4ivARB"); |
| 59 | pfn_glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) gl_ctx->getProcAddress("glGetObjectParameterivARB"); |
| 60 | pfn_glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) gl_ctx->getProcAddress ("glGetInfoLogARB"); |
| 61 | pfn_glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) gl_ctx->getProcAddress ("glDeleteObjectARB"); |
| 62 | pfn_glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) gl_ctx->getProcAddress ("glCreateShaderObjectARB"); |
| 63 | pfn_glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) gl_ctx->getProcAddress ("glShaderSourceARB"); |
| 64 | pfn_glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) gl_ctx->getProcAddress ("glCompileShaderARB"); |
| 65 | pfn_glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) gl_ctx->getProcAddress ("glCreateProgramObjectARB"); |
| 66 | pfn_glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) gl_ctx->getProcAddress ("glAttachObjectARB"); |
| 67 | pfn_glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) gl_ctx->getProcAddress ("glLinkProgramARB"); |
| 68 | pfn_glValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC) gl_ctx->getProcAddress ("glValidateProgramARB"); |
| 69 | pfn_glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) gl_ctx->getProcAddress ("glUseProgramObjectARB"); |
| 70 | pfn_glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) gl_ctx->getProcAddress ("glGetUniformLocationARB"); |
| 71 | pfn_glUniform1fARB = (PFNGLUNIFORM1FARBPROC) gl_ctx->getProcAddress ("glUniform1fARB"); |
| 72 | pfn_glUniform1iARB = (PFNGLUNIFORM1IARBPROC) gl_ctx->getProcAddress ("glUniform1iARB"); |
| 73 | pfn_glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) gl_ctx->getProcAddress ("glUniform1fvARB"); |
| 74 | pfn_glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) gl_ctx->getProcAddress ("glUniform2fvARB"); |
| 75 | pfn_glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) gl_ctx->getProcAddress ("glUniform3fvARB"); |
| 76 | pfn_glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) gl_ctx->getProcAddress ("glUniform4fvARB"); |
| 77 | pfn_glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) gl_ctx->getProcAddress ("glUniform1ivARB"); |
| 78 | pfn_glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) gl_ctx->getProcAddress ("glUniform2ivARB"); |
| 79 | pfn_glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) gl_ctx->getProcAddress ("glUniform3ivARB"); |
| 80 | pfn_glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) gl_ctx->getProcAddress ("glUniform4ivARB"); |
| 81 | 81 | |
| 82 | 82 | if ( pfn_glGetObjectParameterivARB && pfn_glGetInfoLogARB && pfn_glDeleteObjectARB && pfn_glCreateShaderObjectARB && |
| 83 | 83 | pfn_glShaderSourceARB && pfn_glCompileShaderARB && pfn_glCreateProgramObjectARB && pfn_glAttachObjectARB && |