Use GL_RGB565 internal format when available.

This is a feature from ES2_compat extension.
It fixes the speed issue associated with using 16-bit textures on
desktop GL. Improves performance a bit as well as there's less bandwidth
usage during shading.

On my HD3000 laptop, performance improved with ~10%.
This commit is contained in:
Themaister 2014-01-01 21:42:31 +01:00
parent 63302e9404
commit 08ba1ad14e
2 changed files with 36 additions and 6 deletions

View File

@ -1268,11 +1268,17 @@ static inline void gl_copy_frame(void *data, const void *frame, unsigned width,
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch));
if (gl->base_size == 2)
{
// Always use 32-bit textures on desktop GL.
const void *buf = frame;
if (!gl->have_es2_compat)
{
// Convert to 32-bit textures on desktop GL.
gl_convert_frame_rgb16_32(gl, gl->conv_buffer, frame, width, height, pitch);
buf = gl->conv_buffer;
}
glTexSubImage2D(GL_TEXTURE_2D,
0, 0, 0, width, height, gl->texture_type,
gl->texture_fmt, gl->conv_buffer);
gl->texture_fmt, buf);
}
else
{
@ -1666,6 +1672,9 @@ static bool resolve_extensions(gl_t *gl)
RARCH_ERR("[GL]: Failed to init VAOs.\n");
return false;
}
// GL_RGB565 internal format support.
gl->have_es2_compat = gl_query_extension(gl, "ARB_ES2_compatibility");
#endif
#ifdef HAVE_GL_SYNC
@ -1743,6 +1752,16 @@ static inline void gl_set_texture_fmts(void *data, bool rgb32)
gl->internal_fmt = GL_RGBA;
gl->texture_type = GL_RGBA;
}
#ifndef HAVE_OPENGLES
if (!rgb32 && gl->have_es2_compat) // Use GL_RGB565 instead.
{
RARCH_LOG("[GL]: Using GL_RGB565 for texture uploads.\n");
gl->internal_fmt = RARCH_GL_INTERNAL_FORMAT16_565;
gl->texture_type = RARCH_GL_TEXTURE_TYPE16_565;
gl->texture_fmt = RARCH_GL_FORMAT16_565;
}
#endif
}
static inline void gl_reinit_textures(void *data, const video_info_t *video)

View File

@ -212,6 +212,8 @@ typedef struct gl
unsigned base_size; // 2 or 4
#ifdef HAVE_OPENGLES
bool support_unpack_row_length;
#else
bool have_es2_compat;
#endif
// Fonts
@ -266,7 +268,7 @@ typedef struct gl
#if defined(HAVE_PSGL)
#define RARCH_GL_INTERNAL_FORMAT32 GL_ARGB_SCE
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGB5
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGB5 // TODO: Verify if this is really 565 or just 555.
#define RARCH_GL_TEXTURE_TYPE32 GL_BGRA
#define RARCH_GL_TEXTURE_TYPE16 GL_BGRA
#define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV
@ -288,12 +290,21 @@ typedef struct gl
#define RARCH_GL_FORMAT16 GL_UNSIGNED_SHORT_5_6_5
#else
// On desktop, we always use 32-bit.
#define RARCH_GL_INTERNAL_FORMAT32 GL_RGBA
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGBA
#define RARCH_GL_INTERNAL_FORMAT32 GL_RGBA8
#define RARCH_GL_INTERNAL_FORMAT16 GL_RGBA8
#define RARCH_GL_TEXTURE_TYPE32 GL_BGRA
#define RARCH_GL_TEXTURE_TYPE16 GL_BGRA
#define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV
#define RARCH_GL_FORMAT16 GL_UNSIGNED_INT_8_8_8_8_REV
// GL_RGB565 internal format isn't in desktop GL until 4.1 core (ARB_ES2_compatibility).
// Check for this.
#ifndef GL_RGB565
#define GL_RGB565 0x8D62
#endif
#define RARCH_GL_INTERNAL_FORMAT16_565 GL_RGB565
#define RARCH_GL_TEXTURE_TYPE16_565 GL_RGB
#define RARCH_GL_FORMAT16_565 GL_UNSIGNED_SHORT_5_6_5
#endif
// Platform specific workarounds/hacks.