Move gl_load_texture_data to gl_common.c

This commit is contained in:
twinaphex 2019-02-02 17:33:58 +01:00
parent 6b3fad0f53
commit 2560d1c105
3 changed files with 69 additions and 76 deletions

View File

@ -80,6 +80,75 @@ void gl_load_texture_image(GLenum target,
}
}
void gl_load_texture_data(
uint32_t id_data,
enum gfx_wrap_type wrap_type,
enum texture_filter_type filter_type,
unsigned alignment,
unsigned width, unsigned height,
const void *frame, unsigned base_size)
{
GLint mag_filter, min_filter;
bool want_mipmap = false;
bool use_rgba = video_driver_supports_rgba();
bool rgb32 = (base_size == (sizeof(uint32_t)));
GLenum wrap = gl_wrap_type_to_enum(wrap_type);
GLuint id = (GLuint)id_data;
bool have_mipmap = gl_check_capability(GL_CAPS_MIPMAP);
if (!have_mipmap)
{
/* Assume no mipmapping support. */
switch (filter_type)
{
case TEXTURE_FILTER_MIPMAP_LINEAR:
filter_type = TEXTURE_FILTER_LINEAR;
break;
case TEXTURE_FILTER_MIPMAP_NEAREST:
filter_type = TEXTURE_FILTER_NEAREST;
break;
default:
break;
}
}
switch (filter_type)
{
case TEXTURE_FILTER_MIPMAP_LINEAR:
min_filter = GL_LINEAR_MIPMAP_NEAREST;
mag_filter = GL_LINEAR;
want_mipmap = true;
break;
case TEXTURE_FILTER_MIPMAP_NEAREST:
min_filter = GL_NEAREST_MIPMAP_NEAREST;
mag_filter = GL_NEAREST;
want_mipmap = true;
break;
case TEXTURE_FILTER_NEAREST:
min_filter = GL_NEAREST;
mag_filter = GL_NEAREST;
break;
case TEXTURE_FILTER_LINEAR:
default:
min_filter = GL_LINEAR;
mag_filter = GL_LINEAR;
break;
}
gl_bind_texture(id, wrap, mag_filter, min_filter);
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
glTexImage2D(GL_TEXTURE_2D,
0,
(use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
width, height, 0,
(use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
(rgb32) ? RARCH_GL_FORMAT32 : GL_UNSIGNED_SHORT_4_4_4_4, frame);
if (want_mipmap && have_mipmap)
glGenerateMipmap(GL_TEXTURE_2D);
}
bool gl_add_lut(
const char *lut_path,
bool lut_mipmap,

View File

@ -600,74 +600,6 @@ static INLINE void gl_set_shader_viewports(gl_t *gl)
}
}
void gl_load_texture_data(
uint32_t id_data,
enum gfx_wrap_type wrap_type,
enum texture_filter_type filter_type,
unsigned alignment,
unsigned width, unsigned height,
const void *frame, unsigned base_size)
{
GLint mag_filter, min_filter;
bool want_mipmap = false;
bool use_rgba = video_driver_supports_rgba();
bool rgb32 = (base_size == (sizeof(uint32_t)));
GLenum wrap = gl_wrap_type_to_enum(wrap_type);
GLuint id = (GLuint)id_data;
bool have_mipmap = gl_check_capability(GL_CAPS_MIPMAP);
if (!have_mipmap)
{
/* Assume no mipmapping support. */
switch (filter_type)
{
case TEXTURE_FILTER_MIPMAP_LINEAR:
filter_type = TEXTURE_FILTER_LINEAR;
break;
case TEXTURE_FILTER_MIPMAP_NEAREST:
filter_type = TEXTURE_FILTER_NEAREST;
break;
default:
break;
}
}
switch (filter_type)
{
case TEXTURE_FILTER_MIPMAP_LINEAR:
min_filter = GL_LINEAR_MIPMAP_NEAREST;
mag_filter = GL_LINEAR;
want_mipmap = true;
break;
case TEXTURE_FILTER_MIPMAP_NEAREST:
min_filter = GL_NEAREST_MIPMAP_NEAREST;
mag_filter = GL_NEAREST;
want_mipmap = true;
break;
case TEXTURE_FILTER_NEAREST:
min_filter = GL_NEAREST;
mag_filter = GL_NEAREST;
break;
case TEXTURE_FILTER_LINEAR:
default:
min_filter = GL_LINEAR;
mag_filter = GL_LINEAR;
break;
}
gl_bind_texture(id, wrap, mag_filter, min_filter);
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
glTexImage2D(GL_TEXTURE_2D,
0,
(use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_INTERNAL_FORMAT32,
width, height, 0,
(use_rgba || !rgb32) ? GL_RGBA : RARCH_GL_TEXTURE_TYPE32,
(rgb32) ? RARCH_GL_FORMAT32 : GL_UNSIGNED_SHORT_4_4_4_4, frame);
if (want_mipmap && have_mipmap)
glGenerateMipmap(GL_TEXTURE_2D);
}
static void gl_set_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height,

View File

@ -165,14 +165,6 @@ static void gl2_renderchain_bind_backbuffer(void *data,
void context_bind_hw_render(void *data, bool enable);
void gl_load_texture_data(
uint32_t id_data,
enum gfx_wrap_type wrap_type,
enum texture_filter_type filter_type,
unsigned alignment,
unsigned width, unsigned height,
const void *frame, unsigned base_size);
void gl_set_viewport(
gl_t *gl, video_frame_info_t *video_info,
unsigned viewport_width,