comparison src/video/cybergfx/SDL_cgxgl.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents d910939febfa
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
25 25
26 #include "SDL_cgxgl_c.h" 26 #include "SDL_cgxgl_c.h"
27 #include "SDL_cgxvideo.h" 27 #include "SDL_cgxvideo.h"
28 28
29 #if SDL_VIDEO_OPENGL 29 #if SDL_VIDEO_OPENGL
30 AmigaMesaContext glcont=NULL; 30 AmigaMesaContext glcont = NULL;
31 #endif 31 #endif
32 32
33 /* Init OpenGL */ 33 /* Init OpenGL */
34 int CGX_GL_Init(_THIS) 34 int
35 { 35 CGX_GL_Init(_THIS)
36 #if SDL_VIDEO_OPENGL 36 {
37 int i = 0; 37 #if SDL_VIDEO_OPENGL
38 struct TagItem attributes [ 14 ]; /* 14 should be more than enough :) */ 38 int i = 0;
39 struct Window *win = (struct Window *)SDL_Window; 39 struct TagItem attributes[14]; /* 14 should be more than enough :) */
40 40 struct Window *win = (struct Window *) SDL_Window;
41 // default config. Always used... 41
42 attributes[i].ti_Tag = AMA_Window; attributes[i++].ti_Data = (unsigned long)win; 42 // default config. Always used...
43 attributes[i].ti_Tag = AMA_Left; attributes[i++].ti_Data = 0; 43 attributes[i].ti_Tag = AMA_Window;
44 attributes[i].ti_Tag = AMA_Bottom; attributes[i++].ti_Data = 0; 44 attributes[i++].ti_Data = (unsigned long) win;
45 attributes[i].ti_Tag = AMA_Width; attributes[i++].ti_Data = win->Width-win->BorderLeft-win->BorderRight; 45 attributes[i].ti_Tag = AMA_Left;
46 attributes[i].ti_Tag = AMA_Height; attributes[i++].ti_Data = win->Height-win->BorderBottom-win->BorderTop; 46 attributes[i++].ti_Data = 0;
47 attributes[i].ti_Tag = AMA_DirectRender; attributes[i++].ti_Data = GL_TRUE; 47 attributes[i].ti_Tag = AMA_Bottom;
48 48 attributes[i++].ti_Data = 0;
49 // double buffer ? 49 attributes[i].ti_Tag = AMA_Width;
50 attributes[i].ti_Tag = AMA_DoubleBuf; 50 attributes[i++].ti_Data = win->Width - win->BorderLeft - win->BorderRight;
51 if ( this->gl_config.double_buffer ) { 51 attributes[i].ti_Tag = AMA_Height;
52 attributes[i++].ti_Data = GL_TRUE; 52 attributes[i++].ti_Data =
53 } 53 win->Height - win->BorderBottom - win->BorderTop;
54 else { 54 attributes[i].ti_Tag = AMA_DirectRender;
55 attributes[i++].ti_Data = GL_FALSE; 55 attributes[i++].ti_Data = GL_TRUE;
56 } 56
57 // RGB(A) Mode ? 57 // double buffer ?
58 attributes[i].ti_Tag = AMA_RGBMode; 58 attributes[i].ti_Tag = AMA_DoubleBuf;
59 if ( this->gl_config.red_size != 0 && 59 if (this->gl_config.double_buffer) {
60 this->gl_config.blue_size != 0 && 60 attributes[i++].ti_Data = GL_TRUE;
61 this->gl_config.green_size != 0 ) { 61 } else {
62 attributes[i++].ti_Data = GL_TRUE; 62 attributes[i++].ti_Data = GL_FALSE;
63 } 63 }
64 else { 64 // RGB(A) Mode ?
65 attributes[i++].ti_Data = GL_FALSE; 65 attributes[i].ti_Tag = AMA_RGBMode;
66 } 66 if (this->gl_config.red_size != 0 &&
67 // no depth buffer ? 67 this->gl_config.blue_size != 0 && this->gl_config.green_size != 0) {
68 if ( this->gl_config.depth_size == 0 ) { 68 attributes[i++].ti_Data = GL_TRUE;
69 attributes[i].ti_Tag = AMA_NoDepth; 69 } else {
70 attributes[i++].ti_Data = GL_TRUE; 70 attributes[i++].ti_Data = GL_FALSE;
71 } 71 }
72 // no stencil buffer ? 72 // no depth buffer ?
73 if ( this->gl_config.stencil_size == 0 ) { 73 if (this->gl_config.depth_size == 0) {
74 attributes[i].ti_Tag = AMA_NoStencil; 74 attributes[i].ti_Tag = AMA_NoDepth;
75 attributes[i++].ti_Data = GL_TRUE; 75 attributes[i++].ti_Data = GL_TRUE;
76 } 76 }
77 // no accum buffer ? 77 // no stencil buffer ?
78 if ( this->gl_config.accum_red_size != 0 && 78 if (this->gl_config.stencil_size == 0) {
79 this->gl_config.accum_blue_size != 0 && 79 attributes[i].ti_Tag = AMA_NoStencil;
80 this->gl_config.accum_green_size != 0 ) { 80 attributes[i++].ti_Data = GL_TRUE;
81 attributes[i].ti_Tag = AMA_NoAccum; 81 }
82 attributes[i++].ti_Data = GL_TRUE; 82 // no accum buffer ?
83 } 83 if (this->gl_config.accum_red_size != 0 &&
84 // done... 84 this->gl_config.accum_blue_size != 0 &&
85 attributes[i].ti_Tag = TAG_DONE; 85 this->gl_config.accum_green_size != 0) {
86 86 attributes[i].ti_Tag = AMA_NoAccum;
87 glcont = AmigaMesaCreateContext(attributes); 87 attributes[i++].ti_Data = GL_TRUE;
88 if ( glcont == NULL ) { 88 }
89 SDL_SetError("Couldn't create OpenGL context"); 89 // done...
90 return(-1); 90 attributes[i].ti_Tag = TAG_DONE;
91 } 91
92 this->gl_data->gl_active = 1; 92 glcont = AmigaMesaCreateContext(attributes);
93 this->gl_config.driver_loaded = 1; 93 if (glcont == NULL) {
94 94 SDL_SetError("Couldn't create OpenGL context");
95 return(0); 95 return (-1);
96 }
97 this->gl_data->gl_active = 1;
98 this->gl_config.driver_loaded = 1;
99
100 return (0);
96 #else 101 #else
97 SDL_SetError("OpenGL support not configured"); 102 SDL_SetError("OpenGL support not configured");
98 return(-1); 103 return (-1);
99 #endif 104 #endif
100 } 105 }
101 106
102 /* Quit OpenGL */ 107 /* Quit OpenGL */
103 void CGX_GL_Quit(_THIS) 108 void
104 { 109 CGX_GL_Quit(_THIS)
105 #if SDL_VIDEO_OPENGL 110 {
106 if ( glcont != NULL ) { 111 #if SDL_VIDEO_OPENGL
107 AmigaMesaDestroyContext(glcont); 112 if (glcont != NULL) {
108 glcont = NULL; 113 AmigaMesaDestroyContext(glcont);
109 this->gl_data->gl_active = 0; 114 glcont = NULL;
110 this->gl_config.driver_loaded = 0; 115 this->gl_data->gl_active = 0;
111 } 116 this->gl_config.driver_loaded = 0;
117 }
112 #endif 118 #endif
113 } 119 }
114 120
115 /* Attach context to another window */ 121 /* Attach context to another window */
116 int CGX_GL_Update(_THIS) 122 int
117 { 123 CGX_GL_Update(_THIS)
118 #if SDL_VIDEO_OPENGL 124 {
119 struct TagItem tags[2]; 125 #if SDL_VIDEO_OPENGL
120 struct Window *win = (struct Window*)SDL_Window; 126 struct TagItem tags[2];
121 if(glcont == NULL) { 127 struct Window *win = (struct Window *) SDL_Window;
122 return -1; //should never happen 128 if (glcont == NULL) {
123 } 129 return -1; //should never happen
124 tags[0].ti_Tag = AMA_Window; 130 }
125 tags[0].ti_Data = (unsigned long)win; 131 tags[0].ti_Tag = AMA_Window;
126 tags[1].ti_Tag = TAG_DONE; 132 tags[0].ti_Data = (unsigned long) win;
127 AmigaMesaSetRast(glcont, tags); 133 tags[1].ti_Tag = TAG_DONE;
128 134 AmigaMesaSetRast(glcont, tags);
129 return 0; 135
136 return 0;
130 #else 137 #else
131 SDL_SetError("OpenGL support not configured"); 138 SDL_SetError("OpenGL support not configured");
132 return -1; 139 return -1;
133 #endif 140 #endif
134 } 141 }
135 142
136 #if SDL_VIDEO_OPENGL 143 #if SDL_VIDEO_OPENGL
137 144
138 /* Make the current context active */ 145 /* Make the current context active */
139 int CGX_GL_MakeCurrent(_THIS) 146 int
140 { 147 CGX_GL_MakeCurrent(_THIS)
141 if(glcont == NULL) 148 {
142 return -1; 149 if (glcont == NULL)
143 150 return -1;
144 AmigaMesaMakeCurrent(glcont, glcont->buffer); 151
145 return 0; 152 AmigaMesaMakeCurrent(glcont, glcont->buffer);
146 } 153 return 0;
147 154 }
148 void CGX_GL_SwapBuffers(_THIS) 155
149 { 156 void
150 AmigaMesaSwapBuffers(glcont); 157 CGX_GL_SwapBuffers(_THIS)
151 } 158 {
152 159 AmigaMesaSwapBuffers(glcont);
153 int CGX_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) { 160 }
154 GLenum mesa_attrib; 161
155 162 int
156 switch(attrib) { 163 CGX_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
157 case SDL_GL_RED_SIZE: 164 {
158 mesa_attrib = GL_RED_BITS; 165 GLenum mesa_attrib;
159 break; 166
160 case SDL_GL_GREEN_SIZE: 167 switch (attrib) {
161 mesa_attrib = GL_GREEN_BITS; 168 case SDL_GL_RED_SIZE:
162 break; 169 mesa_attrib = GL_RED_BITS;
163 case SDL_GL_BLUE_SIZE: 170 break;
164 mesa_attrib = GL_BLUE_BITS; 171 case SDL_GL_GREEN_SIZE:
165 break; 172 mesa_attrib = GL_GREEN_BITS;
166 case SDL_GL_ALPHA_SIZE: 173 break;
167 mesa_attrib = GL_ALPHA_BITS; 174 case SDL_GL_BLUE_SIZE:
168 break; 175 mesa_attrib = GL_BLUE_BITS;
169 case SDL_GL_DOUBLEBUFFER: 176 break;
170 mesa_attrib = GL_DOUBLEBUFFER; 177 case SDL_GL_ALPHA_SIZE:
171 break; 178 mesa_attrib = GL_ALPHA_BITS;
172 case SDL_GL_DEPTH_SIZE: 179 break;
173 mesa_attrib = GL_DEPTH_BITS; 180 case SDL_GL_DOUBLEBUFFER:
174 break; 181 mesa_attrib = GL_DOUBLEBUFFER;
175 case SDL_GL_STENCIL_SIZE: 182 break;
176 mesa_attrib = GL_STENCIL_BITS; 183 case SDL_GL_DEPTH_SIZE:
177 break; 184 mesa_attrib = GL_DEPTH_BITS;
178 case SDL_GL_ACCUM_RED_SIZE: 185 break;
179 mesa_attrib = GL_ACCUM_RED_BITS; 186 case SDL_GL_STENCIL_SIZE:
180 break; 187 mesa_attrib = GL_STENCIL_BITS;
181 case SDL_GL_ACCUM_GREEN_SIZE: 188 break;
182 mesa_attrib = GL_ACCUM_GREEN_BITS; 189 case SDL_GL_ACCUM_RED_SIZE:
183 break; 190 mesa_attrib = GL_ACCUM_RED_BITS;
184 case SDL_GL_ACCUM_BLUE_SIZE: 191 break;
185 mesa_attrib = GL_ACCUM_BLUE_BITS; 192 case SDL_GL_ACCUM_GREEN_SIZE:
186 break; 193 mesa_attrib = GL_ACCUM_GREEN_BITS;
187 case SDL_GL_ACCUM_ALPHA_SIZE: 194 break;
188 mesa_attrib = GL_ACCUM_ALPHA_BITS; 195 case SDL_GL_ACCUM_BLUE_SIZE:
189 break; 196 mesa_attrib = GL_ACCUM_BLUE_BITS;
190 default : 197 break;
191 return -1; 198 case SDL_GL_ACCUM_ALPHA_SIZE:
192 } 199 mesa_attrib = GL_ACCUM_ALPHA_BITS;
193 200 break;
194 AmigaMesaGetConfig(glcont->visual, mesa_attrib, value); 201 default:
195 return 0; 202 return -1;
196 } 203 }
197 204
198 void *CGX_GL_GetProcAddress(_THIS, const char *proc) { 205 AmigaMesaGetConfig(glcont->visual, mesa_attrib, value);
199 void *func = NULL; 206 return 0;
200 func = AmiGetGLProc(proc); 207 }
201 return func; 208
202 } 209 void *
203 210 CGX_GL_GetProcAddress(_THIS, const char *proc)
204 int CGX_GL_LoadLibrary(_THIS, const char *path) { 211 {
205 /* Library is always open */ 212 void *func = NULL;
206 this->gl_config.driver_loaded = 1; 213 func = AmiGetGLProc(proc);
207 214 return func;
208 return 0; 215 }
216
217 int
218 CGX_GL_LoadLibrary(_THIS, const char *path)
219 {
220 /* Library is always open */
221 this->gl_config.driver_loaded = 1;
222
223 return 0;
209 } 224 }
210 225
211 #endif /* SDL_VIDEO_OPENGL */ 226 #endif /* SDL_VIDEO_OPENGL */
212 227 /* vi: set ts=4 sw=4 expandtab: */