2013-10-05 09:25:12 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "gl-subsystem.h"
|
|
|
|
|
2013-10-10 17:39:56 -07:00
|
|
|
bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
|
2013-10-05 09:25:12 -07:00
|
|
|
GLenum format, GLint internal_format, bool compressed,
|
|
|
|
uint32_t width, uint32_t height, uint32_t size, void ***p_data)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
void **data = *p_data;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_levels; i++) {
|
|
|
|
if (compressed) {
|
2013-10-10 17:39:56 -07:00
|
|
|
glCompressedTexImage2D(target, i, internal_format,
|
|
|
|
width, height, 0, size,
|
|
|
|
data ? *data : NULL);
|
2013-10-05 09:25:12 -07:00
|
|
|
if (!gl_success("glCompressedTexImage2D"))
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
} else {
|
2013-10-10 17:39:56 -07:00
|
|
|
glTexImage2D(target, i, internal_format, width, height,
|
|
|
|
0, format, type, data ? *data : NULL);
|
2013-10-05 09:25:12 -07:00
|
|
|
if (!gl_success("glTexImage2D"))
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2013-10-10 17:39:56 -07:00
|
|
|
if (data)
|
|
|
|
data++;
|
2013-10-05 09:25:12 -07:00
|
|
|
size /= 4;
|
|
|
|
width /= 2;
|
|
|
|
height /= 2;
|
2013-10-05 09:40:43 -07:00
|
|
|
|
|
|
|
if (width == 0) width = 1;
|
|
|
|
if (height == 0) height = 1;
|
2013-10-05 09:25:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
*p_data = data;
|
|
|
|
return success;
|
|
|
|
}
|
2013-10-10 17:39:56 -07:00
|
|
|
|
|
|
|
bool gl_copy_texture(struct gs_device *device,
|
|
|
|
GLuint src, GLenum src_target,
|
|
|
|
GLuint dst, GLenum dst_target,
|
|
|
|
uint32_t width, uint32_t height)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
width, height, 1);
|
|
|
|
success = gl_success("glCopyImageSubDataNV");
|
|
|
|
|
|
|
|
} else if (device->copy_type == COPY_TYPE_FBO_BLIT) {
|
|
|
|
/* TODO (implement FBOs) */
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
2013-10-11 11:41:36 -07:00
|
|
|
|
2013-10-11 13:00:39 -07:00
|
|
|
bool gl_create_buffer(GLenum target, GLuint *buffer, GLsizeiptr size,
|
|
|
|
const GLvoid *data, GLenum usage)
|
2013-10-11 11:41:36 -07:00
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
if (!gl_gen_buffers(1, buffer))
|
|
|
|
return false;
|
2013-10-11 13:00:39 -07:00
|
|
|
if (!gl_bind_buffer(target, *buffer))
|
2013-10-11 11:41:36 -07:00
|
|
|
return false;
|
|
|
|
|
2013-10-11 13:00:39 -07:00
|
|
|
glBufferData(target, size, data, usage);
|
2013-10-11 11:41:36 -07:00
|
|
|
success = gl_success("glBufferData");
|
|
|
|
|
2013-10-11 13:00:39 -07:00
|
|
|
gl_bind_buffer(target, 0);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool update_buffer(GLenum target, GLuint buffer, void *data, size_t size)
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!gl_bind_buffer(target, buffer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ptr = glMapBuffer(target, GL_WRITE_ONLY);
|
|
|
|
success = gl_success("glMapBuffer");
|
|
|
|
if (success && ptr) {
|
|
|
|
memcpy(ptr, data, size);
|
|
|
|
glUnmapBuffer(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_bind_buffer(target, 0);
|
2013-10-11 11:41:36 -07:00
|
|
|
return success;
|
|
|
|
}
|