diff options
Diffstat (limited to 'src/osd/sdl/drawogl.c')
-rw-r--r-- | src/osd/sdl/drawogl.c | 350 |
1 files changed, 175 insertions, 175 deletions
diff --git a/src/osd/sdl/drawogl.c b/src/osd/sdl/drawogl.c index 9969db22e22..cd8c9ce0501 100644 --- a/src/osd/sdl/drawogl.c +++ b/src/osd/sdl/drawogl.c @@ -1,5 +1,5 @@ //============================================================ -// +// // drawogl.c - SDL software and OpenGL implementation // // Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team. @@ -156,7 +156,7 @@ typedef struct _texture_info texture_info; #if USE_OPENGL typedef void (*texture_copy_func)(texture_info *texture, const render_texinfo *texsource); #endif - + /* texture_info holds information about a texture */ struct _texture_info { @@ -173,26 +173,26 @@ struct _texture_info int xprescale; // what is our X prescale factor? int yprescale; // what is our Y prescale factor? int nocopy; // must the texture date be copied? - + UINT32 texture; // OpenGL texture "name"/ID const GLint * texProperties; // texture properties texture_copy_func texCopyFn; // texture copy function, !=NULL if !nocopy GLenum texTarget; // OpenGL texture target int texpow2; // Is this texture pow2 - + UINT32 mpass_dest_idx; // Multipass dest idx [0..1] UINT32 mpass_textureunit[2]; // texture unit names for GLSL - + UINT32 mpass_texture_mamebm[2];// Multipass OpenGL texture "name"/ID for the shader UINT32 mpass_fbo_mamebm[2]; // framebuffer object for this texture, multipass UINT32 mpass_texture_scrn[2]; // Multipass OpenGL texture "name"/ID for the shader UINT32 mpass_fbo_scrn[2]; // framebuffer object for this texture, multipass - + UINT32 lut_texture; // LUT OpenGL texture "name"/ID for the shader - int lut_table_width; // LUT table width + int lut_table_width; // LUT table width int lut_table_height; // LUT table height - + UINT32 pbo; // pixel buffer object for this texture (DYNAMIC only!) UINT32 *data; // pixels for the texture int data_own; // do we own / allocated it ? @@ -205,7 +205,7 @@ struct _texture_info typedef struct _sdl_info sdl_info; struct _sdl_info { - INT32 blittimer; + INT32 blittimer; UINT32 extra_flags; #if (SDL_VERSION_ATLEAST(1,3,0)) @@ -219,19 +219,19 @@ struct _sdl_info // 3D info (GL mode only) texture_info * texlist; // list of active textures int last_blendmode; // previous blendmode - INT32 texture_max_width; // texture maximum width - INT32 texture_max_height; // texture maximum height + INT32 texture_max_width; // texture maximum width + INT32 texture_max_height; // texture maximum height int texpoweroftwo; // must textures be power-of-2 sized? int usevbo; // runtime check if VBO is available int usepbo; // runtime check if PBO is available int usefbo; // runtime check if FBO is available int useglsl; // runtime check if GLSL is available - + glsl_shader_info *glsl; // glsl_shader_info - + GLhandleARB glsl_program[2*GLSL_SHADER_MAX]; // GLSL programs, or 0 int glsl_program_num; // number of GLSL programs - int glsl_program_mb2sc; // GLSL program idx, which transforms + int glsl_program_mb2sc; // GLSL program idx, which transforms // the mame-bitmap -> screen-bitmap (size/rotation/..) // All progs <= glsl_program_mb2sc using the mame bitmap // as input, otherwise the screen bitmap. @@ -246,10 +246,10 @@ struct _sdl_info float last_hofs; float last_vofs; - + // Static vars from draogl_window_dra - INT32 surf_w; - INT32 surf_h; + INT32 surf_w; + INT32 surf_h; GLfloat texVerticex[8]; }; @@ -295,19 +295,19 @@ INLINE void set_blendmode(sdl_info *sdl, int blendmode) case BLENDMODE_NONE: glDisable(GL_BLEND); break; - case BLENDMODE_ALPHA: + case BLENDMODE_ALPHA: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; - case BLENDMODE_RGB_MULTIPLY: + case BLENDMODE_RGB_MULTIPLY: glEnable(GL_BLEND); glBlendFunc(GL_DST_COLOR, GL_ZERO); break; - case BLENDMODE_ADD: + case BLENDMODE_ADD: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); break; - } + } sdl->last_blendmode = blendmode; } @@ -335,7 +335,7 @@ static void load_gl_lib(void); // OGL 1.3 #ifdef GL_ARB_multitexture -static PFNGLACTIVETEXTUREARBPROC pfn_glActiveTexture = NULL; +static PFNGLACTIVETEXTUREARBPROC pfn_glActiveTexture = NULL; #else static PFNGLACTIVETEXTUREPROC pfn_glActiveTexture = NULL; #endif @@ -455,8 +455,8 @@ static void loadgl_functions(void) int err_count = 0; /* the following is tricky ... #func will be expanded to glBegin - * while func will be expanded to disp_p->glBegin - */ + * while func will be expanded to disp_p->glBegin + */ #define OSD_GL(ret,func,params) \ if (!( func = (ret (APIENTRY *)params) SDL_GL_GetProcAddress( #func ) )) \ @@ -467,11 +467,11 @@ static void loadgl_functions(void) #define GET_GLFUNC 1 #include "osd_opengl.h" #undef GET_GLFUNC - + if (err_count) fatalerror("Error loading GL library functions, giving up\n"); -#endif +#endif } //============================================================ @@ -484,9 +484,9 @@ static void load_gl_lib(void) if (!dll_loaded) { /* - * directfb and and x11 use this env var - * SDL_VIDEO_GL_DRIVER - */ + * directfb and and x11 use this env var + * SDL_VIDEO_GL_DRIVER + */ const char *stemp; stemp = options_get_string(mame_options(), SDLOPTION_GL_LIB); @@ -497,8 +497,8 @@ static void load_gl_lib(void) { fatalerror("Unable to load opengl library: %s\n", stemp ? stemp : "<default>"); } - mame_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>"); - /* FIXME: must be freed as well */ + mame_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>"); + /* FIXME: must be freed as well */ gl_dispatch = (osd_gl_dispatch *) osd_malloc(sizeof(osd_gl_dispatch)); dll_loaded=1; } @@ -523,7 +523,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) window->dxdata = sdl; #if (SDL_VERSION_ATLEAST(1,3,0)) - sdl->extra_flags = (window->fullscreen ? + sdl->extra_flags = (window->fullscreen ? SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); sdl->extra_flags |= SDL_WINDOW_OPENGL; @@ -534,7 +534,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) // create the SDL window SDL_SelectVideoDisplay(window->monitor->handle); - if (window->fullscreen && video_config.switchres) + if (window->fullscreen && video_config.switchres) { SDL_DisplayMode mode; SDL_GetCurrentDisplayMode(&mode); @@ -546,7 +546,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) } else SDL_SetWindowDisplayMode(window->window_id, NULL); // Use desktop - + window->window_id = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdl->extra_flags); @@ -560,7 +560,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) //SDL_SetWindowFullscreen(window->window_id, window->fullscreen); SDL_RaiseWindow(window->window_id); SDL_GetWindowSize(window->window_id, &window->width, &window->height); - + sdl->gl_context_id = SDL_GL_CreateContext(window->window_id); if (!sdl->gl_context_id) { @@ -569,7 +569,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) } SDL_GL_SetSwapInterval(video_config.waitvsync ? 2 : 0); - + #else sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); sdl->extra_flags |= SDL_OPENGL | SDL_DOUBLEBUF; @@ -578,11 +578,11 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) #if (SDL_VERSION_ATLEAST(1,2,10)) SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video_config.waitvsync ? 1 : 0); #endif - + load_gl_lib(); // create the SDL surface (which creates the window in windowed mode) - sdl->sdlsurf = SDL_SetVideoMode(width, height, + sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); if (!sdl->sdlsurf) @@ -590,7 +590,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) window->width = sdl->sdlsurf->w; window->height = sdl->sdlsurf->h; - + if ( (video_config.mode == VIDEO_MODE_OPENGL) && !(sdl->sdlsurf->flags & SDL_OPENGL) ) { mame_printf_error("OpenGL not supported on this driver!\n"); @@ -600,7 +600,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) // set the window title SDL_WM_SetCaption(window->title, "SDLMAME"); -#endif +#endif sdl->totalColors = window->totalColors; sdl->blittimer = 0; sdl->surf_w = 0; @@ -614,8 +614,8 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) sdl->texture_max_height = 64; /* load any GL function addresses - * this must be done here because we need a context - */ + * this must be done here because we need a context + */ loadgl_functions(); extstr = (char *)glGetString(GL_EXTENSIONS); @@ -712,7 +712,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) mame_printf_verbose("OpenGL: pixel buffers not supported\n"); } } - + if (strstr(extstr, "GL_EXT_framebuffer_object")) { sdl->usefbo = 1; @@ -728,7 +728,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) if (strstr(extstr, "GL_ARB_shader_objects") && strstr(extstr, "GL_ARB_shading_language_100") && strstr(extstr, "GL_ARB_vertex_shader") && - strstr(extstr, "GL_ARB_fragment_shader") + strstr(extstr, "GL_ARB_fragment_shader") ) { sdl->useglsl = video_config.glsl; @@ -763,7 +763,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height) shown_video_info = 1; sdl->init_context = 0; - + return 0; } @@ -783,13 +783,13 @@ static void drawogl_window_resize(sdl_window_info *window, int width, int height #else SDL_FreeSurface(sdl->sdlsurf); - sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, + sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags); window->width = sdl->sdlsurf->w; window->height = sdl->sdlsurf->h; #endif sdl->init_context = 1; - + } //============================================================ @@ -946,7 +946,7 @@ static void loadGLExtensions(sdl_window_info *window) } } - if ( sdl->usefbo && + if ( sdl->usefbo && ( !pfn_glIsFramebuffer || !pfn_glBindFramebuffer || !pfn_glDeleteFramebuffers || !pfn_glGenFramebuffers || !pfn_glCheckFramebufferStatus || !pfn_glFramebufferTexture2D )) @@ -1012,10 +1012,10 @@ static void loadGLExtensions(sdl_window_info *window) mame_printf_warning("OpenGL: FBO not supported\n"); } } - + if ( sdl->useglsl ) { - #ifdef GL_ARB_multitexture + #ifdef GL_ARB_multitexture pfn_glActiveTexture = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); #else pfn_glActiveTexture = (PFNGLACTIVETEXTUREPROC) SDL_GL_GetProcAddress("glActiveTexture"); @@ -1041,8 +1041,8 @@ static void loadGLExtensions(sdl_window_info *window) { mame_printf_warning("OpenGL: GLSL supported, but shader instantiation failed - disabled\n"); } - } - } + } + } if ( sdl->useglsl ) { @@ -1083,13 +1083,13 @@ static void loadGLExtensions(sdl_window_info *window) glsl_shader_feature = GLSL_SHADER_FEAT_CUSTOM; if (_once) { - mame_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n", + mame_printf_verbose("OpenGL: GLSL using mame bitmap shader filter %d: '%s'\n", sdl->glsl_program_num, video_config.glsl_shader_mamebm[i]); } sdl->glsl_program_mb2sc = sdl->glsl_program_num; // the last mame_bitmap (mb) shader does it. sdl->glsl_program_num++; } - } + } if ( video_config.glsl_shader_scrn_num > 0 && sdl->glsl_program_num==0 ) { @@ -1106,12 +1106,12 @@ static void loadGLExtensions(sdl_window_info *window) } else { if (_once) { - mame_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n", + mame_printf_verbose("OpenGL: GLSL using screen bitmap shader filter %d: '%s'\n", sdl->glsl_program_num, video_config.glsl_shader_scrn[i]); } sdl->glsl_program_num++; } - } + } if ( 0==sdl->glsl_program_num && 0 <= video_config.glsl_filter && video_config.glsl_filter < GLSL_SHADER_FEAT_INT_NUMBER ) @@ -1122,7 +1122,7 @@ static void loadGLExtensions(sdl_window_info *window) if (_once) { - mame_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n", + mame_printf_verbose("OpenGL: GLSL using shader filter '%s', idx: %d, num %d (vid filter: %d)\n", glsl_shader_get_filter_name_mamebm(glsl_shader_feature), glsl_shader_feature, sdl->glsl_program_num, video_config.filter); } @@ -1212,7 +1212,7 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) { loadGLExtensions(window); } - + sdl->surf_w=window->width; sdl->surf_h=window->height; @@ -1235,38 +1235,38 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); } - + // enable blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); sdl->last_blendmode = BLENDMODE_ALPHA; - + // set lines and points just barely above normal size to get proper results glLineWidth(video_config.beamwidth); glPointSize(video_config.beamwidth); - + // set up a nice simple 2D coordinate system, so GL behaves exactly how we'd like. // // (0,0) (w,0) // |~~~~~~~~~| - // | | - // | | - // | | + // | | + // | | + // | | // |_________| // (0,h) (w,h) - + glViewport(0.0, 0.0, (GLsizei)window->width, (GLsizei)window->height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)window->width, (GLdouble)window->height, 0.0, 0.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + if ( ! sdl->initialized ) { glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, sdl->texVerticex); // no VBO, since it's too volatile - + sdl->initialized = 1; } } @@ -1301,7 +1301,7 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) sdl->last_hofs = hofs; sdl->last_vofs = vofs; - + osd_lock_acquire(window->primlist->lock); // now draw @@ -1312,9 +1312,9 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) switch (prim->type) { /** - * Try to stay in one Begin/End block as long as possible, - * since entering and leaving one is most expensive.. - */ + * Try to stay in one Begin/End block as long as possible, + * since entering and leaving one is most expensive.. + */ case RENDER_PRIMITIVE_LINE: #if !USE_WIN32_STYLE_LINES // check if it's really a point @@ -1416,8 +1416,8 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update) if (a > 1.0) a = 1.0; glColor4f(r, g, b, a); -// texture = texture_update(window, prim, 0); -// if (texture) printf("line has texture!\n"); +// texture = texture_update(window, prim, 0); +// if (texture) printf("line has texture!\n"); // if we have a texture to use for the vectors, use it here #if 0 @@ -1716,7 +1716,7 @@ static void drawogl_window_destroy(sdl_window_info *window) //============================================================ // -// glBufferData to push a nocopy texture to the GPU is slower than TexSubImage2D, +// glBufferData to push a nocopy texture to the GPU is slower than TexSubImage2D, // so don't use PBO here // // we also don't want to use PBO's in the case of nocopy==TRUE, @@ -1733,14 +1733,14 @@ static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo texture->type = TEXTURE_TYPE_PLAIN; texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; - } + } // currently glsl supports idx and rgb palette lookups, // no special quality scaling, so we could drop the prescale criteria below .. if ( texture->type == TEXTURE_TYPE_NONE && - sdl->useglsl && + sdl->useglsl && ( - texture->format==SDL_TEXFORMAT_PALETTE16 || // glsl idx16 lut + texture->format==SDL_TEXFORMAT_PALETTE16 || // glsl idx16 lut texture->format==SDL_TEXFORMAT_RGB32_PALETTED || // glsl rgb32 lut/direct texture->format==SDL_TEXFORMAT_RGB15_PALETTED // glsl rgb15 lut/direct ) && @@ -1750,13 +1750,13 @@ static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo { texture->type = TEXTURE_TYPE_SHADER; texture->nocopy = TRUE; - texture->texTarget = GL_TEXTURE_2D; + texture->texTarget = GL_TEXTURE_2D; texture->texpow2 = sdl->texpoweroftwo; } // determine if we can skip the copy step // if this was not already decided by the shader condition above - if ( !texture->nocopy && + if ( !texture->nocopy && texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST] && !texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE] && texture->xprescale == 1 && texture->yprescale == 1 && @@ -1764,7 +1764,7 @@ static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo texsource->rowpixels <= sdl->texture_max_width ) { texture->nocopy = TRUE; - } + } if( texture->type == TEXTURE_TYPE_NONE && sdl->usepbo && !texture->nocopy ) @@ -1773,7 +1773,7 @@ static void texture_compute_type_subroutine(sdl_info *sdl, const render_texinfo texture->type = TEXTURE_TYPE_DYNAMIC; texture->texTarget = (sdl->usetexturerect)?GL_TEXTURE_RECTANGLE_ARB:GL_TEXTURE_2D; texture->texpow2 = (sdl->usetexturerect)?0:sdl->texpoweroftwo; - } + } if( texture->type == TEXTURE_TYPE_NONE ) { @@ -1803,17 +1803,17 @@ INLINE int get_valid_pow2_value(int v, int needPow2) static void texture_compute_size_subroutine(sdl_window_info *window, texture_info *texture, UINT32 flags, UINT32 width, UINT32 height, - int* p_width, int* p_height, int* p_width_create, int* p_height_create) + int* p_width, int* p_height, int* p_width_create, int* p_height_create) { sdl_info *sdl = (sdl_info *) window->dxdata; int width_create; int height_create; - if ( texture->texpow2 ) + if ( texture->texpow2 ) { width_create = gl_round_to_pow2 (width); height_create = gl_round_to_pow2 (height); - } else if ( texture->type==TEXTURE_TYPE_SHADER ) + } else if ( texture->type==TEXTURE_TYPE_SHADER ) { /** * at least use a multiple of 8 for shader .. just in case @@ -1867,8 +1867,8 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi } texture_compute_type_subroutine(sdl, texsource, texture, flags); - - texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, + + texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); // if we added pixels for the border, and that just barely pushed us over, take it back @@ -1879,8 +1879,8 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi texture->borderpix = FALSE; texture_compute_type_subroutine(sdl, texsource, texture, flags); - - texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, + + texture_compute_size_subroutine(window, texture, flags, texsource->width, texsource->height, &finalwidth, &finalheight, &finalwidth_create, &finalheight_create); } @@ -1888,7 +1888,7 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi if (finalwidth_create > sdl->texture_max_width || finalheight_create > sdl->texture_max_height) { static int printed = FALSE; - if (!printed) + if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth_create, finalheight_create, sdl->texture_max_width, sdl->texture_max_height); printed = TRUE; } @@ -1906,8 +1906,8 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi mame_printf_verbose("GL texture: copy %d, shader %d, dynamic %d, %dx%d %dx%d [%s, Equal: %d, Palette: %d,\n" " scale %dx%d, border %d, pitch %d,%d/%d], colors: %d, bytes/pix %d\n", !texture->nocopy, texture->type==TEXTURE_TYPE_SHADER, texture->type==TEXTURE_TYPE_DYNAMIC, - finalwidth, finalheight, finalwidth_create, finalheight_create, - texfmt_to_string[texture->format], + finalwidth, finalheight, finalwidth_create, finalheight_create, + texfmt_to_string[texture->format], (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_EQUALS_DEST], (int)texture_copy_properties[texture->format][SDL_TEXFORMAT_SRC_HAS_PALETTE], texture->xprescale, texture->yprescale, @@ -1927,7 +1927,7 @@ static void texture_compute_size_type(sdl_window_info *window, const render_texi // texture_create //============================================================ -static int gl_checkFramebufferStatus(void) +static int gl_checkFramebufferStatus(void) { GLenum status; status=(GLenum)pfn_glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); @@ -1955,7 +1955,7 @@ static int gl_checkFramebufferStatus(void) case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: mame_printf_error("GL FBO: incomplete,missing read buffer\n"); return -1; -#ifdef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT +#ifdef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: mame_printf_error("GL FBO: incomplete, duplicate attachment\n"); return -1; @@ -1977,7 +1977,7 @@ static int texture_fbo_create(UINT32 text_unit, UINT32 text_name, UINT32 fbo_nam glBindTexture(GL_TEXTURE_2D, text_name); { GLint _width, _height; - if ( gl_texture_check_size(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, + if ( gl_texture_check_size(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &_width, &_height, 1) ) { mame_printf_error("cannot create fbo texture, req: %dx%d, avail: %dx%d - bail out\n", @@ -1985,7 +1985,7 @@ static int texture_fbo_create(UINT32 text_unit, UINT32 text_name, UINT32 fbo_nam return -1; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL ); } // non-screen textures will never be filtered @@ -1995,7 +1995,7 @@ static int texture_fbo_create(UINT32 text_unit, UINT32 text_name, UINT32 fbo_nam glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - pfn_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + pfn_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, text_name, 0); if ( gl_checkFramebufferStatus() ) @@ -2007,7 +2007,7 @@ static int texture_fbo_create(UINT32 text_unit, UINT32 text_name, UINT32 fbo_nam return 0; } -static int texture_shader_create(sdl_window_info *window, +static int texture_shader_create(sdl_window_info *window, const render_texinfo *texsource, texture_info *texture, UINT32 flags) { sdl_info *sdl = (sdl_info *) window->dxdata; @@ -2050,18 +2050,18 @@ static int texture_shader_create(sdl_window_info *window, } /** - * We experience some GLSL LUT calculation inaccuracy on some GL drivers. - * while using the correct lut calculations. - * This error is due to the color index value to GLSL/texture passing process: - * mame:uint16_t -> OpenGL: GLfloat(alpha texture) -> GLSL:uint16_t (value regeneration) - * The latter inaccurate uint16_t value regeneration is buggy on some drivers/cards, - * therefor we always widen the lut size to pow2, - * and shape it equaly into 2D space (max texture size restriction). - * This is a practical GL driver workaround to minimize the chance for - * floating point arithmetic errors in the GLSL engine. - * - * Shape the lut texture to achieve texture max size compliance and equal 2D partitioning - */ + * We experience some GLSL LUT calculation inaccuracy on some GL drivers. + * while using the correct lut calculations. + * This error is due to the color index value to GLSL/texture passing process: + * mame:uint16_t -> OpenGL: GLfloat(alpha texture) -> GLSL:uint16_t (value regeneration) + * The latter inaccurate uint16_t value regeneration is buggy on some drivers/cards, + * therefor we always widen the lut size to pow2, + * and shape it equaly into 2D space (max texture size restriction). + * This is a practical GL driver workaround to minimize the chance for + * floating point arithmetic errors in the GLSL engine. + * + * Shape the lut texture to achieve texture max size compliance and equal 2D partitioning + */ lut_texture_width = sqrt((double)(texture->lut_table_width)); lut_texture_width = get_valid_pow2_value (lut_texture_width, 1); @@ -2075,9 +2075,9 @@ static int texture_shader_create(sdl_window_info *window, texture->lut_table_width = lut_texture_width; /** - * always use pow2 for LUT, to minimize the chance for floating point arithmetic errors - * (->buggy GLSL engine) - */ + * always use pow2 for LUT, to minimize the chance for floating point arithmetic errors + * (->buggy GLSL engine) + */ lut_table_height_pow2 = get_valid_pow2_value (texture->lut_table_height, 1 /* texture->texpow2 */); lut_table_width_pow2 = get_valid_pow2_value (texture->lut_table_width, 1 /* texture->texpow2 */); @@ -2104,7 +2104,7 @@ static int texture_shader_create(sdl_window_info *window, // multipass mode assert(sdl->usefbo); - // GL_TEXTURE3 GLSL Uniforms + // GL_TEXTURE3 GLSL Uniforms texture->mpass_dest_idx = 0; texture->mpass_textureunit[0] = GL_TEXTURE3; texture->mpass_textureunit[1] = GL_TEXTURE2; @@ -2192,7 +2192,7 @@ static int texture_shader_create(sdl_window_info *window, for (i=0; i<2; i++) { - if ( texture_fbo_create(texture->mpass_textureunit[i], + if ( texture_fbo_create(texture->mpass_textureunit[i], texture->mpass_texture_mamebm[i], texture->mpass_fbo_mamebm[i], texture->rawwidth_create, texture->rawheight_create) ) @@ -2216,7 +2216,7 @@ static int texture_shader_create(sdl_window_info *window, for (i=0; i<2; i++) { - if ( texture_fbo_create(texture->mpass_textureunit[i], + if ( texture_fbo_create(texture->mpass_textureunit[i], texture->mpass_texture_scrn[i], texture->mpass_fbo_scrn[i], surf_w_pow2, surf_h_pow2) ) @@ -2231,7 +2231,7 @@ static int texture_shader_create(sdl_window_info *window, if ( !(sdl->glsl_vid_attributes && texture->format!=SDL_TEXFORMAT_PALETTE16) ) { - // GL_TEXTURE1 + // GL_TEXTURE1 glGenTextures(1, (GLuint *)&texture->lut_texture); pfn_glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture->lut_texture); @@ -2273,7 +2273,7 @@ static int texture_shader_create(sdl_window_info *window, assert ( texture->lut_texture ); } - // GL_TEXTURE0 + // GL_TEXTURE0 // get a name for this texture glGenTextures(1, (GLuint *)&texture->texture); pfn_glActiveTexture(GL_TEXTURE0); @@ -2286,10 +2286,10 @@ static int texture_shader_create(sdl_window_info *window, UINT32 * dummy = NULL; GLint _width, _height; if ( gl_texture_check_size(GL_TEXTURE_2D, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], - texture->rawwidth_create, texture->rawheight_create, + texture->rawwidth_create, texture->rawheight_create, 0, - texture->texProperties[SDL_TEXFORMAT_FORMAT], - texture->texProperties[SDL_TEXFORMAT_TYPE], + texture->texProperties[SDL_TEXFORMAT_FORMAT], + texture->texProperties[SDL_TEXFORMAT_TYPE], &_width, &_height, 1) ) { mame_printf_error("cannot create bitmap texture, req: %dx%d, avail: %dx%d - bail out\n", @@ -2301,10 +2301,10 @@ static int texture_shader_create(sdl_window_info *window, texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); memset(dummy, 0, texture->rawwidth_create * texture->rawheight_create * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); - glTexImage2D(GL_TEXTURE_2D, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], - texture->rawwidth_create, texture->rawheight_create, + glTexImage2D(GL_TEXTURE_2D, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], + texture->rawwidth_create, texture->rawheight_create, 0, - texture->texProperties[SDL_TEXFORMAT_FORMAT], + texture->texProperties[SDL_TEXFORMAT_FORMAT], texture->texProperties[SDL_TEXFORMAT_TYPE], dummy); glFinish(); // should not be necessary, .. but make sure we won't access the memory after free free(dummy); @@ -2349,7 +2349,7 @@ static int texture_shader_create(sdl_window_info *window, dummy = (UINT32 *) malloc(texture->rawwidth_create * texture->rawheight_create * sizeof(UINT16)); memset(dummy, 0, texture->rawwidth_create * texture->rawheight_create * sizeof(UINT16)); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA16, - texture->rawwidth_create, texture->rawheight_create, + texture->rawwidth_create, texture->rawheight_create, 0, GL_ALPHA, GL_UNSIGNED_SHORT, dummy); glFinish(); // should not be necessary, .. but make sure we won't access the memory after free @@ -2377,7 +2377,7 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf { sdl_info *sdl = (sdl_info *) window->dxdata; texture_info *texture; - + // allocate a new texture texture = (texture_info *) malloc(sizeof(*texture)); memset(texture, 0, sizeof(*texture)); @@ -2399,15 +2399,15 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf } // set the texture_format - // - // src/emu/validity.c:validate_display() states, + // + // src/emu/validity.c:validate_display() states, // an emulated driver can only produce // BITMAP_FORMAT_INDEXED16, BITMAP_FORMAT_RGB15 and BITMAP_FORMAT_RGB32 // where only the first original paletted. // // other paletted formats, i.e.: // SDL_TEXFORMAT_RGB32_PALETTED, SDL_TEXFORMAT_RGB15_PALETTED and SDL_TEXFORMAT_YUY16_PALETTED - // add features like brightness etc by the mame core + // add features like brightness etc by the mame core // // all palette lookup may be implemented using shaders later on .. // that's why we keep the EQUAL flag TRUE, for all original true color bitmaps. @@ -2463,8 +2463,8 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf free(texture); return NULL; } - } - else + } + else { // get a name for this texture glGenTextures(1, (GLuint *)&texture->texture); @@ -2473,12 +2473,12 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf // make sure we're operating on *this* texture glBindTexture(texture->texTarget, texture->texture); - + // this doesn't actually upload, it just sets up the PBO's parameters - glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], - texture->rawwidth_create, texture->rawheight_create, - texture->borderpix ? 1 : 0, - texture->texProperties[SDL_TEXFORMAT_FORMAT], + glTexImage2D(texture->texTarget, 0, texture->texProperties[SDL_TEXFORMAT_INTERNAL], + texture->rawwidth_create, texture->rawheight_create, + texture->borderpix ? 1 : 0, + texture->texProperties[SDL_TEXFORMAT_FORMAT], texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); if ((PRIMFLAG_GET_SCREENTEX(flags)) && video_config.filter) @@ -2524,10 +2524,10 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); // set up the PBO dimension, .. - pfn_glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, + pfn_glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, texture->rawwidth * texture->rawheight * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE], NULL, GL_STREAM_DRAW); - } + } if ( !texture->nocopy && texture->type!=TEXTURE_TYPE_DYNAMIC ) { @@ -2579,9 +2579,9 @@ static void texture_set_data(texture_info *texture, const render_texinfo *texsou // always fill non-wrapping textures with an extra pixel on the top if (texture->borderpix) { - memset(texture->data, 0, + memset(texture->data, 0, (texsource->width * texture->xprescale + 2) * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); - } + } // when nescesarry copy (and convert) the data if (!texture->nocopy) @@ -2593,8 +2593,8 @@ static void texture_set_data(texture_info *texture, const render_texinfo *texsou // always fill non-wrapping textures with an extra pixel on the bottom if (texture->borderpix) { - memset((UINT8 *)texture->data + - (texsource->height + 1) * texture->rawwidth * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE], + memset((UINT8 *)texture->data + + (texsource->height + 1) * texture->rawwidth * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE], 0, (texsource->width * texture->xprescale + 2) * texture->texProperties[SDL_TEXFORMAT_PIXEL_SIZE]); } @@ -2617,19 +2617,19 @@ static void texture_set_data(texture_info *texture, const render_texinfo *texsou glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->texinfo.rowpixels); - // and upload the image + // and upload the image if(texture->format!=SDL_TEXFORMAT_PALETTE16) { - glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, - texture->texProperties[SDL_TEXFORMAT_FORMAT], + glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, + texture->texProperties[SDL_TEXFORMAT_FORMAT], texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); } else { - glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, + glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, GL_ALPHA, GL_UNSIGNED_SHORT, texture->data); } - } + } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) { glBindTexture(texture->texTarget, texture->texture); @@ -2640,10 +2640,10 @@ static void texture_set_data(texture_info *texture, const render_texinfo *texsou pfn_glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB); // kick off the DMA - glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, - texture->texProperties[SDL_TEXFORMAT_FORMAT], + glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, + texture->texProperties[SDL_TEXFORMAT_FORMAT], texture->texProperties[SDL_TEXFORMAT_TYPE], NULL); - } + } else { glBindTexture(texture->texTarget, texture->texture); @@ -2654,9 +2654,9 @@ static void texture_set_data(texture_info *texture, const render_texinfo *texsou else glPixelStorei(GL_UNPACK_ROW_LENGTH, texture->rawwidth); - // and upload the image - glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, - texture->texProperties[SDL_TEXFORMAT_FORMAT], + // and upload the image + glTexSubImage2D(texture->texTarget, 0, 0, 0, texture->rawwidth, texture->rawheight, + texture->texProperties[SDL_TEXFORMAT_FORMAT], texture->texProperties[SDL_TEXFORMAT_TYPE], texture->data); } } @@ -2688,7 +2688,7 @@ static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) // texture_update //============================================================ -static void texture_coord_update(sdl_window_info *window, +static void texture_coord_update(sdl_window_info *window, texture_info *texture, const render_primitive *prim, int shaderIdx) { sdl_info *sdl = (sdl_info *) window->dxdata; @@ -2813,7 +2813,7 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI if ( shaderIdx==0 ) { - glPushAttrib(GL_VIEWPORT_BIT); + glPushAttrib(GL_VIEWPORT_BIT); GL_CHECK_ERROR_NORMAL(); glViewport(0.0, 0.0, (GLsizei)texture->rawwidth, (GLsizei)texture->rawheight); } @@ -2825,7 +2825,7 @@ static void texture_mpass_flip(sdl_info *sdl, texture_info *texture, int shaderI } glClear(GL_COLOR_BUFFER_BIT); // make sure the whole texture is redrawn .. } - else + else { glBindTexture(texture->texTarget, 0); pfn_glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); @@ -2859,7 +2859,7 @@ static void texture_shader_update(sdl_window_info *window, texture_info *texture { if (scrnum == window->start_viewscreen) { - container = render_container_get_screen(screen); + container = render_container_get_screen(screen); } scrnum++; @@ -2902,9 +2902,9 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi // if we didn't find one, create a new texture if (texture == NULL && prim->texture.base != NULL) { - texture = texture_create(window, &prim->texture, prim->flags); + texture = texture_create(window, &prim->texture, prim->flags); - } + } else if (texture != NULL) { if ( texture->type == TEXTURE_TYPE_SHADER ) @@ -2914,11 +2914,11 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) { assert ( sdl->usepbo ) ; - pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); + pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, texture->pbo); glEnable(texture->texTarget); - } - else - { + } + else + { glEnable(texture->texTarget); } } @@ -2944,7 +2944,7 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi texture_set_data(texture, &prim->texture); texBound=1; } - } + } if (!texBound) { glBindTexture(texture->texTarget, texture->texture); @@ -2957,13 +2957,13 @@ static texture_info * texture_update(sdl_window_info *window, const render_primi pfn_glBindBuffer( GL_ARRAY_BUFFER_ARB, texture->texCoordBufferName ); // Load The Data pfn_glBufferSubData( GL_ARRAY_BUFFER_ARB, 0, 4*2*sizeof(GLfloat), texture->texCoord ); - glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // we are using ARB VBO buffers + glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // we are using ARB VBO buffers } else { glTexCoordPointer(2, GL_FLOAT, 0, texture->texCoord); } - } + } return texture; } @@ -2974,7 +2974,7 @@ static void texture_disable(sdl_info *sdl, texture_info * texture) { assert ( sdl->useglsl ); pfn_glUseProgramObjectARB(0); // back to fixed function pipeline - } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) + } else if ( texture->type == TEXTURE_TYPE_DYNAMIC ) { pfn_glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0); glDisable(texture->texTarget); @@ -3036,11 +3036,11 @@ static void drawogl_destroy_all_textures(sdl_window_info *window) #if (SDL_VERSION_ATLEAST(1,3,0)) SDL_GL_MakeCurrent(window->window_id, sdl->gl_context_id); #endif - + if(window->primlist && window->primlist->lock) - { - lock=TRUE; - osd_lock_acquire(window->primlist->lock); + { + lock=TRUE; + osd_lock_acquire(window->primlist->lock); } texture = sdl->texlist; @@ -3059,20 +3059,20 @@ static void drawogl_destroy_all_textures(sdl_window_info *window) pfn_glDeleteBuffers( 1, &(texture->texCoordBufferName) ); texture->texCoordBufferName=0; } - + if(sdl->usepbo && texture->pbo) { pfn_glDeleteBuffers( 1, (GLuint *)&(texture->pbo) ); texture->pbo=0; } - + if( sdl->glsl_program_num > 1 ) { assert(sdl->usefbo); pfn_glDeleteFramebuffers(2, (GLuint *)&texture->mpass_fbo_mamebm[0]); glDeleteTextures(2, (GLuint *)&texture->mpass_texture_mamebm[0]); } - + if ( sdl->glsl_program_mb2sc < sdl->glsl_program_num - 1 ) { assert(sdl->usefbo); @@ -3097,10 +3097,10 @@ static void drawogl_destroy_all_textures(sdl_window_info *window) if ( sdl->useglsl ) { - glsl_shader_free(sdl->glsl); + glsl_shader_free(sdl->glsl); sdl->glsl = NULL; } - + sdl->initialized = 0; if (lock) |