2013-10-10 12:37:03 -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
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-10-10 12:37:03 -07:00
|
|
|
(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"
|
|
|
|
|
|
|
|
static bool gl_init_zsbuffer(struct gs_zstencil_buffer *zs, uint32_t width,
|
|
|
|
uint32_t height)
|
|
|
|
{
|
|
|
|
glGenRenderbuffers(1, &zs->buffer);
|
|
|
|
if (!gl_success("glGenRenderbuffers"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!gl_bind_renderbuffer(GL_RENDERBUFFER, zs->buffer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, zs->format, width, height);
|
|
|
|
if (!gl_success("glRenderbufferStorage"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
gl_bind_renderbuffer(GL_RENDERBUFFER, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-12 16:28:10 -07:00
|
|
|
static inline GLenum get_attachment(enum gs_zstencil_format format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case GS_Z16: return GL_DEPTH_ATTACHMENT;
|
|
|
|
case GS_Z24_S8: return GL_DEPTH_STENCIL_ATTACHMENT;
|
|
|
|
case GS_Z32F: return GL_DEPTH_ATTACHMENT;
|
|
|
|
case GS_Z32F_S8X24: return GL_DEPTH_STENCIL_ATTACHMENT;
|
2013-10-24 01:29:06 -07:00
|
|
|
case GS_ZS_NONE: return 0;
|
2013-10-12 16:28:10 -07:00
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return 0;
|
2013-10-12 16:28:10 -07:00
|
|
|
}
|
|
|
|
|
2013-10-10 12:37:03 -07:00
|
|
|
zstencil_t device_create_zstencil(device_t device, uint32_t width,
|
|
|
|
uint32_t height, enum gs_zstencil_format format)
|
|
|
|
{
|
|
|
|
struct gs_zstencil_buffer *zs;
|
|
|
|
|
2014-02-09 11:34:07 -08:00
|
|
|
zs = bzalloc(sizeof(struct gs_zstencil_buffer));
|
2013-10-12 16:28:10 -07:00
|
|
|
zs->format = convert_zstencil_format(format);
|
|
|
|
zs->attachment = get_attachment(format);
|
2013-10-17 17:21:42 -07:00
|
|
|
zs->device = device;
|
2013-10-10 12:37:03 -07:00
|
|
|
|
|
|
|
if (!gl_init_zsbuffer(zs, width, height)) {
|
2013-10-10 17:39:56 -07:00
|
|
|
blog(LOG_ERROR, "device_create_zstencil (GL) failed");
|
2013-10-10 12:37:03 -07:00
|
|
|
zstencil_destroy(zs);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return zs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void zstencil_destroy(zstencil_t zs)
|
|
|
|
{
|
|
|
|
if (zs) {
|
|
|
|
if (zs->buffer) {
|
|
|
|
glDeleteRenderbuffers(1, &zs->buffer);
|
|
|
|
gl_success("glDeleteRenderbuffers");
|
|
|
|
}
|
|
|
|
|
|
|
|
bfree(zs);
|
|
|
|
}
|
|
|
|
}
|