Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoaopengl.m @ 3057:089a77aebb7d
Added test program for SDL_CreateWindowFrom()
Make sure OpenGL library is loaded before working with OpenGL windows,
even those created with SDL_CreateWindowFrom()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 09 Feb 2009 05:32:12 +0000 |
parents | 99210400e8b9 |
children | 7812d3e9564e |
comparison
equal
deleted
inserted
replaced
3056:a434fe6360df | 3057:089a77aebb7d |
---|---|
46 #endif /* < 10.3 */ | 46 #endif /* < 10.3 */ |
47 | 47 |
48 int | 48 int |
49 Cocoa_GL_LoadLibrary(_THIS, const char *path) | 49 Cocoa_GL_LoadLibrary(_THIS, const char *path) |
50 { | 50 { |
51 if (_this->gl_config.driver_loaded) { | 51 /* Load the OpenGL library */ |
52 if (path) { | |
53 SDL_SetError("OpenGL library already loaded"); | |
54 return -1; | |
55 } else { | |
56 ++_this->gl_config.driver_loaded; | |
57 return 0; | |
58 } | |
59 } | |
60 if (path == NULL) { | 52 if (path == NULL) { |
61 path = SDL_getenv("SDL_OPENGL_LIBRARY"); | 53 path = SDL_getenv("SDL_OPENGL_LIBRARY"); |
62 } | 54 } |
63 if (path == NULL) { | 55 if (path == NULL) { |
64 path = DEFAULT_OPENGL; | 56 path = DEFAULT_OPENGL; |
67 if (!_this->gl_config.dll_handle) { | 59 if (!_this->gl_config.dll_handle) { |
68 return -1; | 60 return -1; |
69 } | 61 } |
70 SDL_strlcpy(_this->gl_config.driver_path, path, | 62 SDL_strlcpy(_this->gl_config.driver_path, path, |
71 SDL_arraysize(_this->gl_config.driver_path)); | 63 SDL_arraysize(_this->gl_config.driver_path)); |
72 _this->gl_config.driver_loaded = 1; | |
73 return 0; | 64 return 0; |
74 } | 65 } |
75 | 66 |
76 void * | 67 void * |
77 Cocoa_GL_GetProcAddress(_THIS, const char *proc) | 68 Cocoa_GL_GetProcAddress(_THIS, const char *proc) |
78 { | 69 { |
79 return SDL_LoadFunction(_this->gl_config.dll_handle, proc); | 70 return SDL_LoadFunction(_this->gl_config.dll_handle, proc); |
80 } | 71 } |
81 | 72 |
82 static void | 73 void |
83 Cocoa_GL_UnloadLibrary(_THIS) | 74 Cocoa_GL_UnloadLibrary(_THIS) |
84 { | 75 { |
85 if (_this->gl_config.driver_loaded > 0) { | 76 SDL_UnloadObject(_this->gl_config.dll_handle); |
86 if (--_this->gl_config.driver_loaded > 0) { | 77 _this->gl_config.dll_handle = NULL; |
87 return; | |
88 } | |
89 SDL_UnloadObject(_this->gl_config.dll_handle); | |
90 _this->gl_config.dll_handle = NULL; | |
91 } | |
92 } | |
93 | |
94 static int | |
95 Cocoa_GL_Initialize(_THIS) | |
96 { | |
97 if (_this->gl_data) { | |
98 ++_this->gl_data->initialized; | |
99 return 0; | |
100 } | |
101 | |
102 _this->gl_data = | |
103 (struct SDL_GLDriverData *) SDL_calloc(1, | |
104 sizeof(struct | |
105 SDL_GLDriverData)); | |
106 if (!_this->gl_data) { | |
107 SDL_OutOfMemory(); | |
108 return -1; | |
109 } | |
110 _this->gl_data->initialized = 1; | |
111 | |
112 if (Cocoa_GL_LoadLibrary(_this, NULL) < 0) { | |
113 return -1; | |
114 } | |
115 return 0; | |
116 } | |
117 | |
118 static void | |
119 Cocoa_GL_Shutdown(_THIS) | |
120 { | |
121 if (!_this->gl_data || (--_this->gl_data->initialized > 0)) { | |
122 return; | |
123 } | |
124 | |
125 Cocoa_GL_UnloadLibrary(_this); | |
126 | |
127 SDL_free(_this->gl_data); | |
128 _this->gl_data = NULL; | |
129 } | |
130 | |
131 int | |
132 Cocoa_GL_SetupWindow(_THIS, SDL_Window * window) | |
133 { | |
134 if (Cocoa_GL_Initialize(_this) < 0) { | |
135 return -1; | |
136 } | |
137 return 0; | |
138 } | |
139 | |
140 void | |
141 Cocoa_GL_CleanupWindow(_THIS, SDL_Window * window) | |
142 { | |
143 Cocoa_GL_Shutdown(_this); | |
144 } | 78 } |
145 | 79 |
146 SDL_GLContext | 80 SDL_GLContext |
147 Cocoa_GL_CreateContext(_THIS, SDL_Window * window) | 81 Cocoa_GL_CreateContext(_THIS, SDL_Window * window) |
148 { | 82 { |