Home | History | Annotate | Download | only in cybergfx
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2006 Sam Lantinga
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Lesser General Public
      7     License as published by the Free Software Foundation; either
      8     version 2.1 of the License, or (at your option) any later version.
      9 
     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     Lesser General Public License for more details.
     14 
     15     You should have received a copy of the GNU Lesser General Public
     16     License along with this library; if not, write to the Free Software
     17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 
     19     Sam Lantinga
     20     slouken (at) libsdl.org
     21 */
     22 #include "SDL_config.h"
     23 
     24 /* StormMesa implementation of SDL OpenGL support */
     25 
     26 #include "SDL_cgxgl_c.h"
     27 #include "SDL_cgxvideo.h"
     28 
     29 #if SDL_VIDEO_OPENGL
     30 AmigaMesaContext glcont=NULL;
     31 #endif
     32 
     33 /* Init OpenGL */
     34 int CGX_GL_Init(_THIS)
     35 {
     36 #if SDL_VIDEO_OPENGL
     37    int i = 0;
     38 	struct TagItem attributes [ 14 ]; /* 14 should be more than enough :) */
     39    struct Window *win = (struct Window *)SDL_Window;
     40 
     41 	// default config. Always used...
     42 	attributes[i].ti_Tag = AMA_Window;	attributes[i++].ti_Data = (unsigned long)win;
     43 	attributes[i].ti_Tag = AMA_Left;		attributes[i++].ti_Data = 0;
     44 	attributes[i].ti_Tag = AMA_Bottom;	attributes[i++].ti_Data = 0;
     45 	attributes[i].ti_Tag = AMA_Width;	attributes[i++].ti_Data = win->Width-win->BorderLeft-win->BorderRight;
     46 	attributes[i].ti_Tag = AMA_Height;	attributes[i++].ti_Data = win->Height-win->BorderBottom-win->BorderTop;
     47 	attributes[i].ti_Tag = AMA_DirectRender; attributes[i++].ti_Data = GL_TRUE;
     48 
     49 	// double buffer ?
     50 	attributes[i].ti_Tag = AMA_DoubleBuf;
     51 	if ( this->gl_config.double_buffer ) {
     52 		attributes[i++].ti_Data = GL_TRUE;
     53 	}
     54 	else {
     55 		attributes[i++].ti_Data = GL_FALSE;
     56 	}
     57 	// RGB(A) Mode ?
     58 	attributes[i].ti_Tag = AMA_RGBMode;
     59 	if ( this->gl_config.red_size   != 0 &&
     60 	     this->gl_config.blue_size  != 0 &&
     61 	     this->gl_config.green_size != 0 ) {
     62 		attributes[i++].ti_Data = GL_TRUE;
     63 	}
     64 	else {
     65 		attributes[i++].ti_Data = GL_FALSE;
     66 	}
     67 	// no depth buffer ?
     68 	if ( this->gl_config.depth_size == 0 ) {
     69 		attributes[i].ti_Tag = AMA_NoDepth;
     70 		attributes[i++].ti_Data = GL_TRUE;
     71 	}
     72 	// no stencil buffer ?
     73 	if ( this->gl_config.stencil_size == 0 ) {
     74 		attributes[i].ti_Tag = AMA_NoStencil;
     75 		attributes[i++].ti_Data = GL_TRUE;
     76 	}
     77 	// no accum buffer ?
     78 	if ( this->gl_config.accum_red_size   != 0 &&
     79 	     this->gl_config.accum_blue_size  != 0 &&
     80 	     this->gl_config.accum_green_size != 0 ) {
     81 		attributes[i].ti_Tag = AMA_NoAccum;
     82 		attributes[i++].ti_Data = GL_TRUE;
     83 	}
     84 	// done...
     85 	attributes[i].ti_Tag	= TAG_DONE;
     86 
     87 	glcont = AmigaMesaCreateContext(attributes);
     88 	if ( glcont == NULL ) {
     89 		SDL_SetError("Couldn't create OpenGL context");
     90 		return(-1);
     91 	}
     92 	this->gl_data->gl_active = 1;
     93 	this->gl_config.driver_loaded = 1;
     94 
     95 	return(0);
     96 #else
     97 	SDL_SetError("OpenGL support not configured");
     98 	return(-1);
     99 #endif
    100 }
    101 
    102 /* Quit OpenGL */
    103 void CGX_GL_Quit(_THIS)
    104 {
    105 #if SDL_VIDEO_OPENGL
    106 	if ( glcont != NULL ) {
    107 		AmigaMesaDestroyContext(glcont);
    108 		glcont = NULL;
    109 		this->gl_data->gl_active = 0;
    110 		this->gl_config.driver_loaded = 0;
    111 	}
    112 #endif
    113 }
    114 
    115 /* Attach context to another window */
    116 int CGX_GL_Update(_THIS)
    117 {
    118 #if SDL_VIDEO_OPENGL
    119 	struct TagItem tags[2];
    120 	struct Window *win = (struct Window*)SDL_Window;
    121 	if(glcont == NULL) {
    122 		return -1; //should never happen
    123 	}
    124 	tags[0].ti_Tag = AMA_Window;
    125 	tags[0].ti_Data = (unsigned long)win;
    126 	tags[1].ti_Tag = TAG_DONE;
    127 	AmigaMesaSetRast(glcont, tags);
    128 
    129 	return 0;
    130 #else
    131 	SDL_SetError("OpenGL support not configured");
    132 	return -1;
    133 #endif
    134 }
    135 
    136 #if SDL_VIDEO_OPENGL
    137 
    138 /* Make the current context active */
    139 int CGX_GL_MakeCurrent(_THIS)
    140 {
    141 	if(glcont == NULL)
    142 		return -1;
    143 
    144 	AmigaMesaMakeCurrent(glcont, glcont->buffer);
    145 	return 0;
    146 }
    147 
    148 void CGX_GL_SwapBuffers(_THIS)
    149 {
    150 	AmigaMesaSwapBuffers(glcont);
    151 }
    152 
    153 int CGX_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) {
    154 	GLenum mesa_attrib;
    155 
    156 	switch(attrib) {
    157 		case SDL_GL_RED_SIZE:
    158 			mesa_attrib = GL_RED_BITS;
    159 			break;
    160 		case SDL_GL_GREEN_SIZE:
    161 			mesa_attrib = GL_GREEN_BITS;
    162 			break;
    163 		case SDL_GL_BLUE_SIZE:
    164 			mesa_attrib = GL_BLUE_BITS;
    165 			break;
    166 		case SDL_GL_ALPHA_SIZE:
    167 			mesa_attrib = GL_ALPHA_BITS;
    168 			break;
    169 		case SDL_GL_DOUBLEBUFFER:
    170 			mesa_attrib = GL_DOUBLEBUFFER;
    171 			break;
    172 		case SDL_GL_DEPTH_SIZE:
    173 			mesa_attrib = GL_DEPTH_BITS;
    174 			break;
    175 		case SDL_GL_STENCIL_SIZE:
    176 			mesa_attrib = GL_STENCIL_BITS;
    177 			break;
    178 		case SDL_GL_ACCUM_RED_SIZE:
    179 			mesa_attrib = GL_ACCUM_RED_BITS;
    180 			break;
    181 		case SDL_GL_ACCUM_GREEN_SIZE:
    182 			mesa_attrib = GL_ACCUM_GREEN_BITS;
    183 			break;
    184 		case SDL_GL_ACCUM_BLUE_SIZE:
    185 			mesa_attrib = GL_ACCUM_BLUE_BITS;
    186 			break;
    187 		case SDL_GL_ACCUM_ALPHA_SIZE:
    188 			mesa_attrib = GL_ACCUM_ALPHA_BITS;
    189 			break;
    190 		default :
    191 			return -1;
    192 	}
    193 
    194 	AmigaMesaGetConfig(glcont->visual, mesa_attrib, value);
    195 	return 0;
    196 }
    197 
    198 void *CGX_GL_GetProcAddress(_THIS, const char *proc) {
    199 	void *func = NULL;
    200 	func = AmiGetGLProc(proc);
    201 	return func;
    202 }
    203 
    204 int CGX_GL_LoadLibrary(_THIS, const char *path) {
    205 	/* Library is always open */
    206 	this->gl_config.driver_loaded = 1;
    207 
    208 	return 0;
    209 }
    210 
    211 #endif /* SDL_VIDEO_OPENGL */
    212 
    213