Add copy_texture_region function

This commit is contained in:
BtbN
2014-04-09 20:04:58 +02:00
parent b312261abd
commit 97c94b183a
10 changed files with 135 additions and 48 deletions

View File

@@ -57,8 +57,8 @@ bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
}
static bool gl_copy_fbo(struct gs_device *device,
GLuint dst, GLenum dst_target,
GLuint src, GLenum src_target,
GLuint dst, GLenum dst_target, uint32_t dst_x, uint32_t dst_y,
GLuint src, GLenum src_target, uint32_t src_x, uint32_t src_y,
uint32_t width, uint32_t height,
enum gs_color_format format)
{
@@ -85,7 +85,7 @@ static bool gl_copy_fbo(struct gs_device *device,
if (!gl_success("glReadBuffer"))
goto fail;
glCopyTexSubImage2D(dst_target, 0, 0, 0, 0, 0, width, height);
glCopyTexSubImage2D(dst_target, 0, dst_x, dst_y, src_x, src_y, width, height);
if (!gl_success("glCopyTexSubImage2D"))
goto fail;
@@ -101,27 +101,28 @@ fail:
}
bool gl_copy_texture(struct gs_device *device,
GLuint dst, GLenum dst_target,
GLuint src, GLenum src_target,
GLuint dst, GLenum dst_target, uint32_t dst_x, uint32_t dst_y,
GLuint src, GLenum src_target, uint32_t src_x, uint32_t src_y,
uint32_t width, uint32_t height,
enum gs_color_format format)
{
bool success = false;
if (device->copy_type == COPY_TYPE_ARB) {
glCopyImageSubData(src, src_target, 0, 0, 0, 0,
dst, dst_target, 0, 0, 0, 0,
glCopyImageSubData(src, src_target, 0, src_x, src_y, 0,
dst, dst_target, 0, dst_x, dst_y, 0,
width, height, 1);
success = gl_success("glCopyImageSubData");
} else if (device->copy_type == COPY_TYPE_NV) {
glCopyImageSubDataNV(src, src_target, 0, 0, 0, 0,
dst, dst_target, 0, 0, 0, 0,
glCopyImageSubDataNV(src, src_target, 0, src_x, src_y, 0,
dst, dst_target, 0, dst_x, dst_y, 0,
width, height, 1);
success = gl_success("glCopyImageSubDataNV");
} else if (device->copy_type == COPY_TYPE_FBO_BLIT) {
if (gl_copy_fbo(device, dst, dst_target, src, src_target,
if (gl_copy_fbo(device, dst, dst_target, dst_x, dst_y,
src, src_target, src_x, src_y,
width, height, format))
success = true;
else

View File

@@ -149,8 +149,8 @@ extern bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
const void ***p_data);
extern bool gl_copy_texture(struct gs_device *device,
GLuint dst, GLenum dst_target,
GLuint src, GLenum src_target,
GLuint dst, GLenum dst_target, uint32_t dst_x, uint32_t dst_y,
GLuint src, GLenum src_target, uint32_t src_x, uint32_t src_y,
uint32_t width, uint32_t height,
enum gs_color_format format);

View File

@@ -59,6 +59,9 @@ static void APIENTRY gl_debug_proc(
GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar *message, const GLvoid *data )
{
UNUSED_PARAMETER(id);
UNUSED_PARAMETER(data);
blog( LOG_DEBUG,
"[%s][%s]{%s}: %.*s",
debug_source_table[GL_DEBUG_SOURCE_OFFSET(source)],
@@ -785,7 +788,9 @@ fail:
blog(LOG_ERROR, "device_setcuberendertarget (GL) failed");
}
void device_copy_texture(device_t device, texture_t dst, texture_t src)
void device_copy_texture_region(device_t device,
texture_t dst, uint32_t dst_x, uint32_t dst_y,
texture_t src, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h)
{
struct gs_texture_2d *src2d = (struct gs_texture_2d*)src;
struct gs_texture_2d *dst2d = (struct gs_texture_2d*)dst;
@@ -802,7 +807,7 @@ void device_copy_texture(device_t device, texture_t dst, texture_t src)
if (dst->type != GS_TEXTURE_2D || src->type != GS_TEXTURE_2D) {
blog(LOG_ERROR, "Source and destination textures must be 2D "
"textures");
"textures");
goto fail;
}
@@ -811,15 +816,18 @@ void device_copy_texture(device_t device, texture_t dst, texture_t src)
goto fail;
}
if (dst2d->width != src2d->width || dst2d->height != src2d->height) {
blog(LOG_ERROR, "Source and destination must have "
"the same dimensions");
uint32_t nw = (uint32_t)src_w ? (uint32_t)src_w : (src2d->width - src_x);
uint32_t nh = (uint32_t)src_h ? (uint32_t)src_h : (src2d->height - src_y);
if (dst2d->width - dst_x < nw || dst2d->height - dst_y < nh) {
blog(LOG_ERROR, "Destination texture region is not big "
"enough to hold the source region");
goto fail;
}
if (!gl_copy_texture(device, dst->texture, dst->gl_target,
src->texture, src->gl_target,
src2d->width, src2d->height, src->format))
if (!gl_copy_texture(device, dst->texture, dst->gl_target, dst_x, dst_y,
src->texture, src->gl_target, src_x, src_y,
nw, nh, src->format))
goto fail;
return;
@@ -828,6 +836,11 @@ fail:
blog(LOG_ERROR, "device_copy_texture (GL) failed");
}
void device_copy_texture(device_t device, texture_t dst, texture_t src)
{
device_copy_texture_region(device, dst, 0, 0, src, 0, 0, 0, 0);
}
void device_beginscene(device_t device)
{
clear_textures(device);