fix GL pixel pack and unpack stuff
This commit is contained in:
parent
85e2fc6b07
commit
e804a9043d
@ -42,7 +42,6 @@ static bool create_pixel_pack_buffer(struct gs_stage_surface *surf)
|
||||
|
||||
static bool gl_init_stage_surface(struct gs_stage_surface *surf)
|
||||
{
|
||||
GLenum gl_type = get_gl_format_type(surf->format);
|
||||
bool success = true;
|
||||
|
||||
if (!gl_gen_textures(1, &surf->texture))
|
||||
@ -50,7 +49,7 @@ static bool gl_init_stage_surface(struct gs_stage_surface *surf)
|
||||
if (!gl_bind_texture(GL_TEXTURE_2D, surf->texture))
|
||||
return false;
|
||||
|
||||
if (!gl_init_face(GL_TEXTURE_2D, gl_type, 1, surf->gl_format,
|
||||
if (!gl_init_face(GL_TEXTURE_2D, surf->gl_type, 1, surf->gl_format,
|
||||
surf->gl_internal_format, false,
|
||||
surf->width, surf->height, 0, NULL))
|
||||
success = false;
|
||||
@ -76,6 +75,7 @@ stagesurf_t device_create_stagesurface(device_t device, uint32_t width,
|
||||
surf->height = height;
|
||||
surf->gl_format = convert_gs_format(color_format);
|
||||
surf->gl_internal_format = convert_gs_internal_format(color_format);
|
||||
surf->gl_type = get_gl_format_type(color_format);
|
||||
surf->bytes_per_pixel = gs_get_format_bpp(color_format)/8;
|
||||
|
||||
if (!gl_init_stage_surface(surf)) {
|
||||
@ -104,27 +104,53 @@ void stagesurface_destroy(stagesurf_t stagesurf)
|
||||
}
|
||||
}
|
||||
|
||||
static bool can_stage(struct gs_stage_surface *dst, struct gs_texture_2d *src)
|
||||
{
|
||||
if (src->base.type != GS_TEXTURE_2D) {
|
||||
blog(LOG_ERROR, "Source texture must be a 2D texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (src->width != dst->width || src->height != dst->height) {
|
||||
blog(LOG_ERROR, "Source and destination sizes do not match");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (src->base.format != dst->format) {
|
||||
blog(LOG_ERROR, "Source and destination format do not match");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void device_stage_texture(device_t device, stagesurf_t dst, texture_t src)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)src;
|
||||
if (src->type != GS_TEXTURE_2D) {
|
||||
blog(LOG_ERROR, "Source texture must be a 2D texture");
|
||||
if (!can_stage(dst, tex2d))
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (tex2d->width != dst->width || tex2d->height != dst->height) {
|
||||
blog(LOG_ERROR, "Source and destination do not match in size");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (!gl_copy_texture(device, tex2d->base.texture, GL_TEXTURE_2D,
|
||||
dst->texture, GL_TEXTURE_2D,
|
||||
dst->width, dst->height))
|
||||
goto failed;
|
||||
|
||||
if (!gl_bind_buffer(GL_TEXTURE_2D, dst->texture))
|
||||
goto failed;
|
||||
if (!gl_bind_buffer(GL_PIXEL_PACK_BUFFER, dst->pack_buffer))
|
||||
goto failed;
|
||||
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, dst->gl_format, dst->gl_type, 0);
|
||||
if (!gl_success("glGetTexImage"))
|
||||
goto failed;
|
||||
|
||||
gl_bind_buffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
gl_bind_texture(GL_TEXTURE_2D, 0);
|
||||
return;
|
||||
|
||||
failed:
|
||||
gl_bind_buffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
gl_bind_texture(GL_TEXTURE_2D, 0);
|
||||
blog(LOG_ERROR, "device_stage_texture (GL) failed");
|
||||
}
|
||||
|
||||
@ -170,5 +196,6 @@ void stagesurface_unmap(stagesurf_t stagesurf)
|
||||
|
||||
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
||||
gl_success("glUnmapBuffer");
|
||||
|
||||
gl_bind_buffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
}
|
||||
|
@ -226,6 +226,7 @@ struct gs_texture {
|
||||
enum gs_color_format format;
|
||||
GLenum gl_format;
|
||||
GLint gl_internal_format;
|
||||
GLenum gl_type;
|
||||
GLuint texture;
|
||||
uint32_t levels;
|
||||
bool is_dynamic;
|
||||
@ -256,6 +257,7 @@ struct gs_stage_surface {
|
||||
uint32_t bytes_per_pixel;
|
||||
GLenum gl_format;
|
||||
GLint gl_internal_format;
|
||||
GLenum gl_type;
|
||||
GLuint texture;
|
||||
GLuint pack_buffer;
|
||||
};
|
||||
|
@ -23,7 +23,6 @@ static bool upload_texture_2d(struct gs_texture_2d *tex, void **data)
|
||||
uint32_t tex_size = tex->height * row_size / 8;
|
||||
uint32_t num_levels = tex->base.levels;
|
||||
bool compressed = gs_is_compressed_format(tex->base.format);
|
||||
GLenum gl_type = get_gl_format_type(tex->base.format);
|
||||
bool success;
|
||||
|
||||
if (!num_levels)
|
||||
@ -32,7 +31,7 @@ static bool upload_texture_2d(struct gs_texture_2d *tex, void **data)
|
||||
if (!gl_bind_texture(GL_TEXTURE_2D, tex->base.texture))
|
||||
return false;
|
||||
|
||||
success = gl_init_face(GL_TEXTURE_2D, gl_type, num_levels,
|
||||
success = gl_init_face(GL_TEXTURE_2D, tex->base.gl_type, num_levels,
|
||||
tex->base.gl_format, tex->base.gl_internal_format,
|
||||
compressed, tex->width, tex->height, tex_size, &data);
|
||||
|
||||
@ -78,6 +77,7 @@ texture_t device_create_texture(device_t device, uint32_t width,
|
||||
tex->base.format = color_format;
|
||||
tex->base.gl_format = convert_gs_format(color_format);
|
||||
tex->base.gl_internal_format = convert_gs_internal_format(color_format);
|
||||
tex->base.gl_type = get_gl_format_type(color_format);
|
||||
tex->base.is_dynamic = flags & GS_DYNAMIC;
|
||||
tex->base.is_render_target = flags & GS_RENDERTARGET;
|
||||
tex->base.gen_mipmaps = flags & GS_BUILDMIPMAPS;
|
||||
@ -174,6 +174,7 @@ bool texture_map(texture_t tex, void **ptr, uint32_t *byte_width)
|
||||
gl_bind_buffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
|
||||
*byte_width = tex2d->width * gs_get_format_bpp(tex->format) / 8;
|
||||
*byte_width = (*byte_width + 3) & 0xFFFFFFFC;
|
||||
return true;
|
||||
|
||||
fail:
|
||||
@ -185,12 +186,30 @@ void texture_unmap(texture_t tex)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
|
||||
if (!is_texture_2d(tex, "texture_unmap"))
|
||||
return;
|
||||
goto failed;
|
||||
|
||||
if (!gl_bind_buffer(GL_PIXEL_UNPACK_BUFFER, tex2d->unpack_buffer))
|
||||
return;
|
||||
goto failed;
|
||||
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
gl_success("glUnmapBuffer");
|
||||
if (!gl_success("glUnmapBuffer"))
|
||||
goto failed;
|
||||
|
||||
if (!gl_bind_texture(GL_TEXTURE_2D, tex2d->base.texture))
|
||||
goto failed;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, tex->gl_internal_format,
|
||||
tex2d->width, tex2d->height, 0,
|
||||
tex->gl_format, tex->gl_type, 0);
|
||||
if (!gl_success("glTexImage2D"))
|
||||
goto failed;
|
||||
|
||||
gl_bind_buffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
gl_bind_texture(GL_TEXTURE_2D, 0);
|
||||
return;
|
||||
|
||||
failed:
|
||||
gl_bind_buffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
gl_bind_texture(GL_TEXTURE_2D, 0);
|
||||
blog(LOG_ERROR, "texture_unmap (GL) failed");
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ static bool gl_init_extensions(device_t device)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GL_ARB_copy_image)
|
||||
if (GLEW_ARB_copy_image)
|
||||
device->copy_type = COPY_TYPE_ARB;
|
||||
else if (GLEW_NV_copy_image)
|
||||
device->copy_type = COPY_TYPE_NV;
|
||||
|
Loading…
x
Reference in New Issue
Block a user