mirror of https://github.com/snes9xgit/snes9x.git
Shaders: Add support for grayscale PNGs
GTK+: Fix invalid texture clear.
This commit is contained in:
parent
4c3d886dab
commit
02be8ba1f2
|
@ -302,8 +302,8 @@ void S9xOpenGLDisplayDriver::clear_buffers ()
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
scaled_max_width,
|
||||
scaled_max_height,
|
||||
MIN(scaled_max_width, texture_width),
|
||||
MIN(scaled_max_height, texture_height),
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_SHORT_5_6_5,
|
||||
buffer[1]);
|
||||
|
|
|
@ -485,20 +485,33 @@ bool GLSLShader::load_shader(char *filename)
|
|||
{
|
||||
int width, height;
|
||||
bool hasAlpha;
|
||||
bool grayscale;
|
||||
GLubyte* texData;
|
||||
|
||||
if (loadPngImage(temp, width, height, hasAlpha, &texData))
|
||||
if (loadPngImage(temp, width, height, grayscale, hasAlpha,
|
||||
&texData))
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
hasAlpha ? GL_RGBA : GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texData);
|
||||
if (grayscale)
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_LUMINANCE,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texData);
|
||||
else
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
hasAlpha ? GL_RGBA : GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
texData);
|
||||
l->width = width;
|
||||
l->height = height;
|
||||
free(texData);
|
||||
|
@ -555,9 +568,6 @@ bool GLSLShader::load_shader(char *filename)
|
|||
}
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glEnable(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, tex_coords);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
#ifdef USE_SLANG
|
||||
|
|
|
@ -81,7 +81,7 @@ void gl_log_errors(void)
|
|||
}
|
||||
|
||||
bool loadPngImage(const char *name, int &outWidth, int &outHeight,
|
||||
bool &outHasAlpha, GLubyte **outData)
|
||||
bool &grayscale, bool &outHasAlpha, GLubyte **outData)
|
||||
{
|
||||
#ifdef HAVE_LIBPNG
|
||||
png_structp png_ptr;
|
||||
|
@ -134,9 +134,14 @@ bool loadPngImage(const char *name, int &outWidth, int &outHeight,
|
|||
{
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
outHasAlpha = true;
|
||||
grayscale = false;
|
||||
break;
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
outHasAlpha = false;
|
||||
grayscale = false;
|
||||
break;
|
||||
case PNG_COLOR_TYPE_GRAY:
|
||||
grayscale = true;
|
||||
break;
|
||||
default:
|
||||
printf ("Unsupported color type: %d\n", png_get_color_type(png_ptr, info_ptr));
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct _STGA
|
|||
} STGA;
|
||||
|
||||
bool loadPngImage(const char *name, int &outWidth, int &outHeight,
|
||||
bool &outHasAlpha, GLubyte **outData);
|
||||
bool &grayscale, bool &outHasAlpha, GLubyte **outData);
|
||||
bool loadTGA(const char *filename, STGA &tgaFile);
|
||||
void gl_log_errors();
|
||||
bool gl_srgb_available();
|
||||
|
|
Loading…
Reference in New Issue