Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 5212:115fff0641ee
Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 06 Feb 2011 10:22:25 -0800 |
parents | ef5a61ea3202 |
children | 1be088cec098 |
comparison
equal
deleted
inserted
replaced
5211:78db79f5a4e2 | 5212:115fff0641ee |
---|---|
28 #include "SDL_sysvideo.h" | 28 #include "SDL_sysvideo.h" |
29 #include "SDL_blit.h" | 29 #include "SDL_blit.h" |
30 #include "SDL_pixels_c.h" | 30 #include "SDL_pixels_c.h" |
31 #include "../events/SDL_events_c.h" | 31 #include "../events/SDL_events_c.h" |
32 | 32 |
33 #if SDL_VIDEO_OPENGL | |
34 #include "SDL_opengl.h" | |
35 #endif /* SDL_VIDEO_OPENGL */ | |
36 | |
33 #if SDL_VIDEO_OPENGL_ES | 37 #if SDL_VIDEO_OPENGL_ES |
34 #include "SDL_opengles.h" | 38 #include "SDL_opengles.h" |
35 #endif /* SDL_VIDEO_OPENGL_ES */ | 39 #endif /* SDL_VIDEO_OPENGL_ES */ |
36 | 40 |
37 #if SDL_VIDEO_OPENGL | 41 #if SDL_VIDEO_OPENGL_ES2 |
38 #include "SDL_opengl.h" | 42 #include "SDL_opengles2.h" |
39 #endif /* SDL_VIDEO_OPENGL */ | 43 #endif /* SDL_VIDEO_OPENGL_ES2 */ |
40 | 44 |
41 #include "SDL_syswm.h" | 45 #include "SDL_syswm.h" |
42 | 46 |
43 /* On Windows, windows.h defines CreateWindow */ | 47 /* On Windows, windows.h defines CreateWindow */ |
44 #ifdef CreateWindow | 48 #ifdef CreateWindow |
479 _this->gl_config.stereo = 0; | 483 _this->gl_config.stereo = 0; |
480 _this->gl_config.multisamplebuffers = 0; | 484 _this->gl_config.multisamplebuffers = 0; |
481 _this->gl_config.multisamplesamples = 0; | 485 _this->gl_config.multisamplesamples = 0; |
482 _this->gl_config.retained_backing = 1; | 486 _this->gl_config.retained_backing = 1; |
483 _this->gl_config.accelerated = -1; /* accelerated or not, both are fine */ | 487 _this->gl_config.accelerated = -1; /* accelerated or not, both are fine */ |
488 #if SDL_VIDEO_OPENGL | |
484 _this->gl_config.major_version = 2; | 489 _this->gl_config.major_version = 2; |
485 _this->gl_config.minor_version = 1; | 490 _this->gl_config.minor_version = 1; |
491 #elif SDL_VIDEO_OPENGL_ES2 | |
492 _this->gl_config.major_version = 2; | |
493 _this->gl_config.minor_version = 0; | |
494 #elif SDL_VIDEO_OPENGL_ES | |
495 _this->gl_config.major_version = 1; | |
496 _this->gl_config.minor_version = 1; | |
497 #endif | |
486 | 498 |
487 /* Initialize the video subsystem */ | 499 /* Initialize the video subsystem */ |
488 if (_this->VideoInit(_this) < 0) { | 500 if (_this->VideoInit(_this) < 0) { |
489 SDL_VideoQuit(); | 501 SDL_VideoQuit(); |
490 return -1; | 502 return -1; |
1895 } | 1907 } |
1896 | 1908 |
1897 SDL_bool | 1909 SDL_bool |
1898 SDL_GL_ExtensionSupported(const char *extension) | 1910 SDL_GL_ExtensionSupported(const char *extension) |
1899 { | 1911 { |
1900 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES | 1912 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 |
1901 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); | 1913 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); |
1902 const char *extensions; | 1914 const char *extensions; |
1903 const char *start; | 1915 const char *start; |
1904 const char *where, *terminator; | 1916 const char *where, *terminator; |
1905 | 1917 |
1949 } | 1961 } |
1950 | 1962 |
1951 int | 1963 int |
1952 SDL_GL_SetAttribute(SDL_GLattr attr, int value) | 1964 SDL_GL_SetAttribute(SDL_GLattr attr, int value) |
1953 { | 1965 { |
1954 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES | 1966 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 |
1955 int retval; | 1967 int retval; |
1956 | 1968 |
1957 if (!_this) { | 1969 if (!_this) { |
1958 SDL_UninitializedVideo(); | 1970 SDL_UninitializedVideo(); |
1959 return -1; | 1971 return -1; |
2030 } | 2042 } |
2031 | 2043 |
2032 int | 2044 int |
2033 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) | 2045 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) |
2034 { | 2046 { |
2035 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES | 2047 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 |
2036 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); | 2048 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); |
2037 GLenum(APIENTRY * glGetErrorFunc) (void); | 2049 GLenum(APIENTRY * glGetErrorFunc) (void); |
2038 GLenum attrib = 0; | 2050 GLenum attrib = 0; |
2039 GLenum error = 0; | 2051 GLenum error = 0; |
2040 | 2052 |
2066 break; | 2078 break; |
2067 case SDL_GL_ALPHA_SIZE: | 2079 case SDL_GL_ALPHA_SIZE: |
2068 attrib = GL_ALPHA_BITS; | 2080 attrib = GL_ALPHA_BITS; |
2069 break; | 2081 break; |
2070 case SDL_GL_DOUBLEBUFFER: | 2082 case SDL_GL_DOUBLEBUFFER: |
2071 #ifndef SDL_VIDEO_OPENGL_ES | 2083 #if SDL_VIDEO_OPENGL |
2072 attrib = GL_DOUBLEBUFFER; | 2084 attrib = GL_DOUBLEBUFFER; |
2073 break; | 2085 break; |
2074 #else | 2086 #else |
2075 /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */ | 2087 /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */ |
2076 /* parameter which switches double buffer to single buffer. OpenGL ES */ | 2088 /* parameter which switches double buffer to single buffer. OpenGL ES */ |
2082 attrib = GL_DEPTH_BITS; | 2094 attrib = GL_DEPTH_BITS; |
2083 break; | 2095 break; |
2084 case SDL_GL_STENCIL_SIZE: | 2096 case SDL_GL_STENCIL_SIZE: |
2085 attrib = GL_STENCIL_BITS; | 2097 attrib = GL_STENCIL_BITS; |
2086 break; | 2098 break; |
2087 #ifndef SDL_VIDEO_OPENGL_ES | 2099 #if SDL_VIDEO_OPENGL |
2088 case SDL_GL_ACCUM_RED_SIZE: | 2100 case SDL_GL_ACCUM_RED_SIZE: |
2089 attrib = GL_ACCUM_RED_BITS; | 2101 attrib = GL_ACCUM_RED_BITS; |
2090 break; | 2102 break; |
2091 case SDL_GL_ACCUM_GREEN_SIZE: | 2103 case SDL_GL_ACCUM_GREEN_SIZE: |
2092 attrib = GL_ACCUM_GREEN_BITS; | 2104 attrib = GL_ACCUM_GREEN_BITS; |
2109 /* none of these are supported in OpenGL ES */ | 2121 /* none of these are supported in OpenGL ES */ |
2110 *value = 0; | 2122 *value = 0; |
2111 return 0; | 2123 return 0; |
2112 #endif | 2124 #endif |
2113 case SDL_GL_MULTISAMPLEBUFFERS: | 2125 case SDL_GL_MULTISAMPLEBUFFERS: |
2114 #ifndef SDL_VIDEO_OPENGL_ES | 2126 #if SDL_VIDEO_OPENGL |
2115 attrib = GL_SAMPLE_BUFFERS_ARB; | 2127 attrib = GL_SAMPLE_BUFFERS_ARB; |
2116 #else | 2128 #else |
2117 attrib = GL_SAMPLE_BUFFERS; | 2129 attrib = GL_SAMPLE_BUFFERS; |
2118 #endif | 2130 #endif |
2119 break; | 2131 break; |
2120 case SDL_GL_MULTISAMPLESAMPLES: | 2132 case SDL_GL_MULTISAMPLESAMPLES: |
2121 #ifndef SDL_VIDEO_OPENGL_ES | 2133 #if SDL_VIDEO_OPENGL |
2122 attrib = GL_SAMPLES_ARB; | 2134 attrib = GL_SAMPLES_ARB; |
2123 #else | 2135 #else |
2124 attrib = GL_SAMPLES; | 2136 attrib = GL_SAMPLES; |
2125 #endif | 2137 #endif |
2126 break; | 2138 break; |