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
28 /* StormMesa implementation of SDL OpenGL support */
30 #include "SDL_error.h"
31 #include "SDL_cgxgl_c.h"
32 #include "SDL_cgxvideo.h"
35 AmigaMesaContext glcont
=NULL
;
39 int CGX_GL_Init(_THIS
)
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
;
55 attributes
[i
].ti_Tag
= AMA_DoubleBuf
;
56 if ( this->gl_config
.double_buffer
) {
57 attributes
[i
++].ti_Data
= GL_TRUE
;
60 attributes
[i
++].ti_Data
= GL_FALSE
;
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
;
70 attributes
[i
++].ti_Data
= GL_FALSE
;
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
;
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
;
90 attributes
[i
].ti_Tag
= TAG_DONE
;
92 glcont
= AmigaMesaCreateContext(attributes
);
93 if ( glcont
== NULL
) {
94 SDL_SetError("Couldn't create OpenGL context");
97 this->gl_data
->gl_active
= 1;
98 this->gl_config
.driver_loaded
= 1;
102 SDL_SetError("OpenGL support not configured");
108 void CGX_GL_Quit(_THIS
)
111 if ( glcont
!= NULL
) {
112 AmigaMesaDestroyContext(glcont
);
114 this->gl_data
->gl_active
= 0;
115 this->gl_config
.driver_loaded
= 0;
120 /* Attach context to another window */
121 int CGX_GL_Update(_THIS
)
124 struct TagItem tags
[2];
125 struct Window
*win
= (struct Window
*)SDL_Window
;
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
);
136 SDL_SetError("OpenGL support not configured");
143 /* Make the current context active */
144 int CGX_GL_MakeCurrent(_THIS
)
149 AmigaMesaMakeCurrent(glcont
, glcont
->buffer
);
153 void CGX_GL_SwapBuffers(_THIS
)
155 AmigaMesaSwapBuffers(glcont
);
158 int CGX_GL_GetAttribute(_THIS
, SDL_GLattr attrib
, int* value
) {
162 case SDL_GL_RED_SIZE
:
163 mesa_attrib
= GL_RED_BITS
;
165 case SDL_GL_GREEN_SIZE
:
166 mesa_attrib
= GL_GREEN_BITS
;
168 case SDL_GL_BLUE_SIZE
:
169 mesa_attrib
= GL_BLUE_BITS
;
171 case SDL_GL_ALPHA_SIZE
:
172 mesa_attrib
= GL_ALPHA_BITS
;
174 case SDL_GL_DOUBLEBUFFER
:
175 mesa_attrib
= GL_DOUBLEBUFFER
;
177 case SDL_GL_DEPTH_SIZE
:
178 mesa_attrib
= GL_DEPTH_BITS
;
180 case SDL_GL_STENCIL_SIZE
:
181 mesa_attrib
= GL_STENCIL_BITS
;
183 case SDL_GL_ACCUM_RED_SIZE
:
184 mesa_attrib
= GL_ACCUM_RED_BITS
;
186 case SDL_GL_ACCUM_GREEN_SIZE
:
187 mesa_attrib
= GL_ACCUM_GREEN_BITS
;
189 case SDL_GL_ACCUM_BLUE_SIZE
:
190 mesa_attrib
= GL_ACCUM_BLUE_BITS
;
192 case SDL_GL_ACCUM_ALPHA_SIZE
:
193 mesa_attrib
= GL_ACCUM_ALPHA_BITS
;
199 AmigaMesaGetConfig(glcont
->visual
, mesa_attrib
, value
);
203 void *CGX_GL_GetProcAddress(_THIS
, const char *proc
) {
205 func
= AmiGetGLProc(proc
);
209 int CGX_GL_LoadLibrary(_THIS
, const char *path
) {
210 /* Library is always open */
211 this->gl_config
.driver_loaded
= 1;
216 #endif /* HAVE_OPENGL */