📄 sdl_atarigl.c
字号:
/* 15 bits unsupported */ if (tinygl_present) { gl_pixelsize = 3; osmesa_format = VDI_RGB; if (redmask == 31<<10) { gl_copyshadow = CopyShadowRGBTo555; } else { gl_copyshadow = CopyShadowRGBTo565; gl_convert = Convert565To555le; } } else { gl_pixelsize = 4; gl_upsidedown = SDL_TRUE; osmesa_format = OSMESA_ARGB; if (redmask == 31<<10) { gl_copyshadow = CopyShadow8888To555; } else { gl_copyshadow = CopyShadow8888To565; gl_convert = Convert565To555le; } } break; case 16: /* 16 bits unsupported */ if (tinygl_present) { gl_pixelsize = 3; osmesa_format = VDI_RGB; gl_copyshadow = CopyShadowRGBTo565; if (redmask != 31<<11) { /* 565, little endian, unsupported */ gl_convert = Convert565le; } } else { gl_pixelsize = 4; gl_upsidedown = SDL_TRUE; osmesa_format = OSMESA_ARGB; gl_copyshadow = CopyShadow8888To565; if (redmask != 31<<11) { /* 565, little endian, unsupported */ gl_convert = Convert565le; } } break; case 24: gl_pixelsize = 3; if (tinygl_present) { osmesa_format = VDI_RGB; gl_copyshadow = CopyShadowDirect; if (redmask != 255<<16) { gl_copyshadow = CopyShadowRGBSwap; } } else { gl_copyshadow = CopyShadowDirect; gl_upsidedown = SDL_TRUE; if (redmask == 255<<16) { osmesa_format = OSMESA_RGB; } else { osmesa_format = OSMESA_BGR; } } break; case 32: if (tinygl_present) { gl_pixelsize = 3; osmesa_format = VDI_RGB; gl_copyshadow = CopyShadowRGBToARGB; if (redmask == 255) { gl_convert = CopyShadowRGBToABGR; } else if (redmask == 255<<8) { gl_convert = CopyShadowRGBToBGRA; } else if (redmask == 255<<24) { gl_convert = CopyShadowRGBToRGBA; } } else { gl_pixelsize = 4; gl_upsidedown = SDL_TRUE; gl_copyshadow = CopyShadowDirect; if (redmask == 255<<16) { osmesa_format = OSMESA_ARGB; } else if (redmask == 255<<8) { osmesa_format = OSMESA_BGRA; } else if (redmask == 255<<24) { osmesa_format = OSMESA_RGBA; } else { /* ABGR format unsupported */ osmesa_format = OSMESA_BGRA; gl_convert = ConvertBGRAToABGR; } } break; default: if (tinygl_present) { SDL_AtariGL_Quit(this, SDL_FALSE); return 0; } gl_pixelsize = 1; gl_copyshadow = CopyShadowDirect; osmesa_format = OSMESA_COLOR_INDEX; break; } /* Try to keep current context if possible */ recreatecontext=1; if (gl_shadow && (gl_curformat == osmesa_format) && (gl_curwidth == current->w) && (gl_curheight == current->h)) { recreatecontext = 0; } if (recreatecontext) { SDL_AtariGL_Quit(this, SDL_FALSE); gl_shadow = this->gl_data->OSMesaCreateLDG( osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h ); if (gl_shadow) { gl_curformat = osmesa_format; gl_curwidth = current->w; gl_curheight = current->h; } else { gl_curformat = 0; gl_curwidth = 0; gl_curheight = 0; } } return (gl_shadow != NULL);}/*--- Conversions routines from shadow buffer to the screen ---*/static void CopyShadowNull(_THIS, SDL_Surface *surface){}static void CopyShadowDirect(_THIS, SDL_Surface *surface){ int y, srcpitch, dstpitch; Uint8 *srcline, *dstline; srcline = gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { SDL_memcpy(dstline, srcline, srcpitch); srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint16 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>1; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint16 dstcolor; dstcolor = ((*srccol++)<<7) & (31<<10); dstcolor |= ((*srccol++)<<2) & (31<<5); dstcolor |= ((*srccol++)>>3) & 31; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint16 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>1; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint16 dstcolor; dstcolor = ((*srccol++)<<8) & (31<<11); dstcolor |= ((*srccol++)<<3) & (63<<5); dstcolor |= ((*srccol++)>>3) & 31; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint8 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { *dstcol++ = srccol[2]; *dstcol++ = srccol[1]; *dstcol++ = srccol[0]; srccol += 3; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint32 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint32 dstcolor; dstcolor = (*srccol++)<<16; dstcolor |= (*srccol++)<<8; dstcolor |= *srccol++; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint32 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint32 dstcolor; dstcolor = *srccol++; dstcolor |= (*srccol++)<<8; dstcolor |= (*srccol++)<<16; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint32 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint32 dstcolor; dstcolor = (*srccol++)<<8; dstcolor |= (*srccol++)<<16; dstcolor |= (*srccol++)<<24; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint32 *dstline, *dstcol; Uint8 *srcline, *srccol; srcline = (Uint8 *)gl_shadow; srcpitch = surface->w * gl_pixelsize; dstline = surface->pixels; dstpitch = surface->pitch >>2; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint32 dstcolor; dstcolor = (*srccol++)<<24; dstcolor |= (*srccol++)<<16; dstcolor |= (*srccol++)<<8; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadow8888To555(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint16 *dstline, *dstcol; Uint32 *srcline, *srccol; srcline = (Uint32 *)gl_shadow; srcpitch = (surface->w * gl_pixelsize) >>2; dstline = surface->pixels; dstpitch = surface->pitch >>1; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint32 srccolor; Uint16 dstcolor; srccolor = *srccol++; dstcolor = (srccolor>>9) & (31<<10); dstcolor |= (srccolor>>6) & (31<<5); dstcolor |= (srccolor>>3) & 31; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}static void CopyShadow8888To565(_THIS, SDL_Surface *surface){ int x,y, srcpitch, dstpitch; Uint16 *dstline, *dstcol; Uint32 *srcline, *srccol; srcline = (Uint32 *)gl_shadow; srcpitch = (surface->w * gl_pixelsize) >> 2; dstline = surface->pixels; dstpitch = surface->pitch >>1; if (gl_upsidedown) { srcline += (surface->h-1)*srcpitch; srcpitch = -srcpitch; } for (y=0; y<surface->h; y++) { srccol = srcline; dstcol = dstline; for (x=0; x<surface->w; x++) { Uint32 srccolor; Uint16 dstcolor; srccolor = *srccol++; dstcolor = (srccolor>>8) & (31<<11); dstcolor |= (srccolor>>5) & (63<<5); dstcolor |= (srccolor>>3) & 31; *dstcol++ = dstcolor; } srcline += srcpitch; dstline += dstpitch; }}/*--- Conversions routines in the screen ---*/static void ConvertNull(_THIS, SDL_Surface *surface){}static void Convert565To555be(_THIS, SDL_Surface *surface){ int x,y, pitch; unsigned short *line, *pixel; line = surface->pixels; pitch = surface->pitch >> 1; for (y=0; y<surface->h; y++) { pixel = line; for (x=0; x<surface->w; x++) { unsigned short color = *pixel; *pixel++ = (color & 0x1f)|((color>>1) & 0xffe0); } line += pitch; }}static void Convert565To555le(_THIS, SDL_Surface *surface){ int x,y, pitch; unsigned short *line, *pixel; line = surface->pixels; pitch = surface->pitch >>1; for (y=0; y<surface->h; y++) { pixel = line; for (x=0; x<surface->w; x++) { unsigned short color = *pixel; color = (color & 0x1f)|((color>>1) & 0xffe0); *pixel++ = SDL_Swap16(color); } line += pitch; }}static void Convert565le(_THIS, SDL_Surface *surface){ int x,y, pitch; unsigned short *line, *pixel; line = surface->pixels; pitch = surface->pitch >>1; for (y=0; y<surface->h; y++) { pixel = line; for (x=0; x<surface->w; x++) { unsigned short color = *pixel; *pixel++ = SDL_Swap16(color); } line += pitch; }}static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface){ int x,y, pitch; unsigned long *line, *pixel; line = surface->pixels; pitch = surface->pitch >>2; for (y=0; y<surface->h; y++) { pixel = line; for (x=0; x<surface->w; x++) { unsigned long color = *pixel; *pixel++ = (color<<24)|(color>>8); } line += pitch; }}#endif /* SDL_VIDEO_OPENGL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -