Updated to latest source.
[AROS-Contrib.git] / SDL / SDL_cgxgl.c
blob4a72e73c15c530e1ba3c08c57b9839b57949883a
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Sam Lantinga
20 slouken@libsdl.org
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
28 /* StormMesa implementation of SDL OpenGL support */
30 #include "SDL_error.h"
31 #include "SDL_cgxgl_c.h"
32 #include "SDL_cgxvideo.h"
34 #ifdef HAVE_OPENGL
35 AmigaMesaContext glcont=NULL;
36 #endif
38 /* Init OpenGL */
39 int CGX_GL_Init(_THIS)
41 #ifdef HAVE_OPENGL
42 int i = 0;
43 struct TagItem attributes [ 14 ]; /* 14 should be more than enough :) */
44 struct Window *win = (struct Window *)SDL_Window;
46 // default config. Always used...
47 attributes[i].ti_Tag = AMA_Window; attributes[i++].ti_Data = (unsigned long)win;
48 attributes[i].ti_Tag = AMA_Left; attributes[i++].ti_Data = 0;
49 attributes[i].ti_Tag = AMA_Bottom; attributes[i++].ti_Data = 0;
50 attributes[i].ti_Tag = AMA_Width; attributes[i++].ti_Data = win->Width-win->BorderLeft-win->BorderRight;
51 attributes[i].ti_Tag = AMA_Height; attributes[i++].ti_Data = win->Height-win->BorderBottom-win->BorderTop;
52 attributes[i].ti_Tag = AMA_DirectRender; attributes[i++].ti_Data = GL_TRUE;
54 // double buffer ?
55 attributes[i].ti_Tag = AMA_DoubleBuf;
56 if ( this->gl_config.double_buffer ) {
57 attributes[i++].ti_Data = GL_TRUE;
59 else {
60 attributes[i++].ti_Data = GL_FALSE;
62 // RGB(A) Mode ?
63 attributes[i].ti_Tag = AMA_RGBMode;
64 if ( this->gl_config.red_size != 0 &&
65 this->gl_config.blue_size != 0 &&
66 this->gl_config.green_size != 0 ) {
67 attributes[i++].ti_Data = GL_TRUE;
69 else {
70 attributes[i++].ti_Data = GL_FALSE;
72 // no depth buffer ?
73 if ( this->gl_config.depth_size == 0 ) {
74 attributes[i].ti_Tag = AMA_NoDepth;
75 attributes[i++].ti_Data = GL_TRUE;
77 // no stencil buffer ?
78 if ( this->gl_config.stencil_size == 0 ) {
79 attributes[i].ti_Tag = AMA_NoStencil;
80 attributes[i++].ti_Data = GL_TRUE;
82 // no accum buffer ?
83 if ( this->gl_config.accum_red_size != 0 &&
84 this->gl_config.accum_blue_size != 0 &&
85 this->gl_config.accum_green_size != 0 ) {
86 attributes[i].ti_Tag = AMA_NoAccum;
87 attributes[i++].ti_Data = GL_TRUE;
89 // done...
90 attributes[i].ti_Tag = TAG_DONE;
92 glcont = AmigaMesaCreateContext(attributes);
93 if ( glcont == NULL ) {
94 SDL_SetError("Couldn't create OpenGL context");
95 return(-1);
97 this->gl_data->gl_active = 1;
98 this->gl_config.driver_loaded = 1;
100 return(0);
101 #else
102 SDL_SetError("OpenGL support not configured");
103 return(-1);
104 #endif
107 /* Quit OpenGL */
108 void CGX_GL_Quit(_THIS)
110 #ifdef HAVE_OPENGL
111 if ( glcont != NULL ) {
112 AmigaMesaDestroyContext(glcont);
113 glcont = NULL;
114 this->gl_data->gl_active = 0;
115 this->gl_config.driver_loaded = 0;
117 #endif
120 /* Attach context to another window */
121 int CGX_GL_Update(_THIS)
123 #ifdef HAVE_OPENGL
124 struct TagItem tags[2];
125 struct Window *win = (struct Window*)SDL_Window;
126 if(glcont == NULL) {
127 return -1; //should never happen
129 tags[0].ti_Tag = AMA_Window;
130 tags[0].ti_Data = (unsigned long)win;
131 tags[1].ti_Tag = TAG_DONE;
132 AmigaMesaSetRast(glcont, tags);
134 return 0;
135 #else
136 SDL_SetError("OpenGL support not configured");
137 return -1;
138 #endif
141 #ifdef HAVE_OPENGL
143 /* Make the current context active */
144 int CGX_GL_MakeCurrent(_THIS)
146 if(glcont == NULL)
147 return -1;
149 AmigaMesaMakeCurrent(glcont, glcont->buffer);
150 return 0;
153 void CGX_GL_SwapBuffers(_THIS)
155 AmigaMesaSwapBuffers(glcont);
158 int CGX_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) {
159 GLenum mesa_attrib;
161 switch(attrib) {
162 case SDL_GL_RED_SIZE:
163 mesa_attrib = GL_RED_BITS;
164 break;
165 case SDL_GL_GREEN_SIZE:
166 mesa_attrib = GL_GREEN_BITS;
167 break;
168 case SDL_GL_BLUE_SIZE:
169 mesa_attrib = GL_BLUE_BITS;
170 break;
171 case SDL_GL_ALPHA_SIZE:
172 mesa_attrib = GL_ALPHA_BITS;
173 break;
174 case SDL_GL_DOUBLEBUFFER:
175 mesa_attrib = GL_DOUBLEBUFFER;
176 break;
177 case SDL_GL_DEPTH_SIZE:
178 mesa_attrib = GL_DEPTH_BITS;
179 break;
180 case SDL_GL_STENCIL_SIZE:
181 mesa_attrib = GL_STENCIL_BITS;
182 break;
183 case SDL_GL_ACCUM_RED_SIZE:
184 mesa_attrib = GL_ACCUM_RED_BITS;
185 break;
186 case SDL_GL_ACCUM_GREEN_SIZE:
187 mesa_attrib = GL_ACCUM_GREEN_BITS;
188 break;
189 case SDL_GL_ACCUM_BLUE_SIZE:
190 mesa_attrib = GL_ACCUM_BLUE_BITS;
191 break;
192 case SDL_GL_ACCUM_ALPHA_SIZE:
193 mesa_attrib = GL_ACCUM_ALPHA_BITS;
194 break;
195 default :
196 return -1;
199 AmigaMesaGetConfig(glcont->visual, mesa_attrib, value);
200 return 0;
203 void *CGX_GL_GetProcAddress(_THIS, const char *proc) {
204 void *func = NULL;
205 func = AmiGetGLProc(proc);
206 return func;
209 int CGX_GL_LoadLibrary(_THIS, const char *path) {
210 /* Library is always open */
211 this->gl_config.driver_loaded = 1;
213 return 0;
216 #endif /* HAVE_OPENGL */