New upstream version 24.0.1+dfsg1
This commit is contained in:
parent
b14f9eae6d
commit
5a730d6ec3
842 changed files with 42245 additions and 33385 deletions
|
|
@ -21,10 +21,8 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
|
||||
//#include "util/darray.h"
|
||||
|
||||
|
||||
struct gl_windowinfo {
|
||||
NSView *view;
|
||||
};
|
||||
|
|
@ -37,9 +35,15 @@ static NSOpenGLContext *gl_context_create(void)
|
|||
{
|
||||
unsigned attrib_count = 0;
|
||||
|
||||
#define ADD_ATTR(x) \
|
||||
{ attributes[attrib_count++] = (NSOpenGLPixelFormatAttribute)x; }
|
||||
#define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); }
|
||||
#define ADD_ATTR(x) \
|
||||
{ \
|
||||
attributes[attrib_count++] = (NSOpenGLPixelFormatAttribute)x; \
|
||||
}
|
||||
#define ADD_ATTR2(x, y) \
|
||||
{ \
|
||||
ADD_ATTR(x); \
|
||||
ADD_ATTR(y); \
|
||||
}
|
||||
|
||||
NSOpenGLPixelFormatAttribute attributes[40];
|
||||
|
||||
|
|
@ -52,7 +56,7 @@ static NSOpenGLContext *gl_context_create(void)
|
|||
|
||||
NSOpenGLPixelFormat *pf;
|
||||
pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||
if(!pf) {
|
||||
if (!pf) {
|
||||
blog(LOG_ERROR, "Failed to create pixel format");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -60,7 +64,7 @@ static NSOpenGLContext *gl_context_create(void)
|
|||
NSOpenGLContext *context;
|
||||
context = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil];
|
||||
[pf release];
|
||||
if(!context) {
|
||||
if (!context) {
|
||||
blog(LOG_ERROR, "Failed to create context");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -98,7 +102,7 @@ fail:
|
|||
|
||||
void gl_platform_destroy(struct gl_platform *platform)
|
||||
{
|
||||
if(!platform)
|
||||
if (!platform)
|
||||
return;
|
||||
|
||||
[platform->context release];
|
||||
|
|
@ -121,10 +125,10 @@ void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
|
|||
|
||||
struct gl_windowinfo *gl_windowinfo_create(const struct gs_init_data *info)
|
||||
{
|
||||
if(!info)
|
||||
if (!info)
|
||||
return NULL;
|
||||
|
||||
if(!info->window.view)
|
||||
if (!info->window.view)
|
||||
return NULL;
|
||||
|
||||
struct gl_windowinfo *wi = bzalloc(sizeof(struct gl_windowinfo));
|
||||
|
|
@ -137,7 +141,7 @@ struct gl_windowinfo *gl_windowinfo_create(const struct gs_init_data *info)
|
|||
|
||||
void gl_windowinfo_destroy(struct gl_windowinfo *wi)
|
||||
{
|
||||
if(!wi)
|
||||
if (!wi)
|
||||
return;
|
||||
|
||||
wi->view = nil;
|
||||
|
|
@ -161,9 +165,14 @@ void device_leave_context(gs_device_t *device)
|
|||
[NSOpenGLContext clearCurrentContext];
|
||||
}
|
||||
|
||||
void *device_get_device_obj(gs_device_t *device)
|
||||
{
|
||||
return device->plat->context;
|
||||
}
|
||||
|
||||
void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
|
||||
{
|
||||
if(device->cur_swap == swap)
|
||||
if (device->cur_swap == swap)
|
||||
return;
|
||||
|
||||
device->cur_swap = swap;
|
||||
|
|
@ -180,14 +189,16 @@ void device_present(gs_device_t *device)
|
|||
}
|
||||
|
||||
void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width,
|
||||
uint32_t *height)
|
||||
uint32_t *height)
|
||||
{
|
||||
if(width) *width = swap->info.cx;
|
||||
if(height) *height = swap->info.cy;
|
||||
if (width)
|
||||
*width = swap->info.cx;
|
||||
if (height)
|
||||
*height = swap->info.cy;
|
||||
}
|
||||
|
||||
gs_texture_t *device_texture_create_from_iosurface(gs_device_t *device,
|
||||
void *iosurf)
|
||||
void *iosurf)
|
||||
{
|
||||
IOSurfaceRef ref = (IOSurfaceRef)iosurf;
|
||||
struct gs_texture_2d *tex = bzalloc(sizeof(struct gs_texture_2d));
|
||||
|
|
@ -195,23 +206,23 @@ gs_texture_t *device_texture_create_from_iosurface(gs_device_t *device,
|
|||
OSType pf = IOSurfaceGetPixelFormat(ref);
|
||||
if (pf != 'BGRA')
|
||||
blog(LOG_ERROR, "Unexpected pixel format: %d (%c%c%c%c)", pf,
|
||||
pf >> 24, pf >> 16, pf >> 8, pf);
|
||||
pf >> 24, pf >> 16, pf >> 8, pf);
|
||||
|
||||
const enum gs_color_format color_format = GS_BGRA;
|
||||
|
||||
tex->base.device = device;
|
||||
tex->base.type = GS_TEXTURE_2D;
|
||||
tex->base.format = GS_BGRA;
|
||||
tex->base.levels = 1;
|
||||
tex->base.gl_format = convert_gs_format(color_format);
|
||||
tex->base.device = device;
|
||||
tex->base.type = GS_TEXTURE_2D;
|
||||
tex->base.format = GS_BGRA;
|
||||
tex->base.levels = 1;
|
||||
tex->base.gl_format = convert_gs_format(color_format);
|
||||
tex->base.gl_internal_format = convert_gs_internal_format(color_format);
|
||||
tex->base.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
tex->base.gl_target = GL_TEXTURE_RECTANGLE;
|
||||
tex->base.is_dynamic = false;
|
||||
tex->base.is_render_target = false;
|
||||
tex->base.gen_mipmaps = false;
|
||||
tex->width = IOSurfaceGetWidth(ref);
|
||||
tex->height = IOSurfaceGetHeight(ref);
|
||||
tex->base.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
tex->base.gl_target = GL_TEXTURE_RECTANGLE;
|
||||
tex->base.is_dynamic = false;
|
||||
tex->base.is_render_target = false;
|
||||
tex->base.gen_mipmaps = false;
|
||||
tex->width = IOSurfaceGetWidth(ref);
|
||||
tex->height = IOSurfaceGetHeight(ref);
|
||||
|
||||
if (!gl_gen_textures(1, &tex->base.texture))
|
||||
goto fail;
|
||||
|
|
@ -220,34 +231,30 @@ gs_texture_t *device_texture_create_from_iosurface(gs_device_t *device,
|
|||
goto fail;
|
||||
|
||||
CGLError err = CGLTexImageIOSurface2D(
|
||||
[[NSOpenGLContext currentContext] CGLContextObj],
|
||||
tex->base.gl_target,
|
||||
tex->base.gl_internal_format,
|
||||
tex->width, tex->height,
|
||||
tex->base.gl_format,
|
||||
tex->base.gl_type,
|
||||
ref, 0);
|
||||
|
||||
if(err != kCGLNoError) {
|
||||
blog(LOG_ERROR, "CGLTexImageIOSurface2D: %u, %s"
|
||||
" (device_texture_create_from_iosurface)",
|
||||
err, CGLErrorString(err));
|
||||
[[NSOpenGLContext currentContext] CGLContextObj],
|
||||
tex->base.gl_target, tex->base.gl_internal_format, tex->width,
|
||||
tex->height, tex->base.gl_format, tex->base.gl_type, ref, 0);
|
||||
|
||||
if (err != kCGLNoError) {
|
||||
blog(LOG_ERROR,
|
||||
"CGLTexImageIOSurface2D: %u, %s"
|
||||
" (device_texture_create_from_iosurface)",
|
||||
err, CGLErrorString(err));
|
||||
|
||||
gl_success("CGLTexImageIOSurface2D");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!gl_tex_param_i(tex->base.gl_target,
|
||||
GL_TEXTURE_MAX_LEVEL, 0))
|
||||
if (!gl_tex_param_i(tex->base.gl_target, GL_TEXTURE_MAX_LEVEL, 0))
|
||||
goto fail;
|
||||
|
||||
if (!gl_bind_texture(tex->base.gl_target, 0))
|
||||
goto fail;
|
||||
|
||||
return (gs_texture_t*)tex;
|
||||
return (gs_texture_t *)tex;
|
||||
|
||||
fail:
|
||||
gs_texture_destroy((gs_texture_t*)tex);
|
||||
gs_texture_destroy((gs_texture_t *)tex);
|
||||
blog(LOG_ERROR, "device_texture_create_from_iosurface (GL) failed");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -260,34 +267,31 @@ bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf)
|
|||
if (!iosurf)
|
||||
return false;
|
||||
|
||||
struct gs_texture_2d *tex = (struct gs_texture_2d*)texture;
|
||||
struct gs_texture_2d *tex = (struct gs_texture_2d *)texture;
|
||||
IOSurfaceRef ref = (IOSurfaceRef)iosurf;
|
||||
|
||||
OSType pf = IOSurfaceGetPixelFormat(ref);
|
||||
if (pf != 'BGRA')
|
||||
blog(LOG_ERROR, "Unexpected pixel format: %d (%c%c%c%c)", pf,
|
||||
pf >> 24, pf >> 16, pf >> 8, pf);
|
||||
pf >> 24, pf >> 16, pf >> 8, pf);
|
||||
|
||||
if (tex->width != IOSurfaceGetWidth(ref) ||
|
||||
tex->height != IOSurfaceGetHeight(ref))
|
||||
tex->height != IOSurfaceGetHeight(ref))
|
||||
return false;
|
||||
|
||||
if (!gl_bind_texture(tex->base.gl_target, tex->base.texture))
|
||||
return false;
|
||||
|
||||
CGLError err = CGLTexImageIOSurface2D(
|
||||
[[NSOpenGLContext currentContext] CGLContextObj],
|
||||
tex->base.gl_target,
|
||||
tex->base.gl_internal_format,
|
||||
tex->width, tex->height,
|
||||
tex->base.gl_format,
|
||||
tex->base.gl_type,
|
||||
ref, 0);
|
||||
|
||||
if(err != kCGLNoError) {
|
||||
blog(LOG_ERROR, "CGLTexImageIOSurface2D: %u, %s"
|
||||
" (gs_texture_rebind_iosurface)",
|
||||
err, CGLErrorString(err));
|
||||
[[NSOpenGLContext currentContext] CGLContextObj],
|
||||
tex->base.gl_target, tex->base.gl_internal_format, tex->width,
|
||||
tex->height, tex->base.gl_format, tex->base.gl_type, ref, 0);
|
||||
|
||||
if (err != kCGLNoError) {
|
||||
blog(LOG_ERROR,
|
||||
"CGLTexImageIOSurface2D: %u, %s"
|
||||
" (gs_texture_rebind_iosurface)",
|
||||
err, CGLErrorString(err));
|
||||
|
||||
gl_success("CGLTexImageIOSurface2D");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
#include "gl-subsystem.h"
|
||||
|
||||
bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
|
||||
GLenum format, GLint internal_format, bool compressed,
|
||||
uint32_t width, uint32_t height, uint32_t size,
|
||||
const uint8_t ***p_data)
|
||||
GLenum format, GLint internal_format, bool compressed,
|
||||
uint32_t width, uint32_t height, uint32_t size,
|
||||
const uint8_t ***p_data)
|
||||
{
|
||||
bool success = true;
|
||||
const uint8_t **data = p_data ? *p_data : NULL;
|
||||
|
|
@ -29,14 +29,14 @@ bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
|
|||
for (i = 0; i < num_levels; i++) {
|
||||
if (compressed) {
|
||||
glCompressedTexImage2D(target, i, internal_format,
|
||||
width, height, 0, size,
|
||||
data ? *data : NULL);
|
||||
width, height, 0, size,
|
||||
data ? *data : NULL);
|
||||
if (!gl_success("glCompressedTexImage2D"))
|
||||
success = false;
|
||||
|
||||
} else {
|
||||
glTexImage2D(target, i, internal_format, width, height,
|
||||
0, format, type, data ? *data : NULL);
|
||||
0, format, type, data ? *data : NULL);
|
||||
if (!gl_success("glTexImage2D"))
|
||||
success = false;
|
||||
}
|
||||
|
|
@ -44,12 +44,14 @@ bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
|
|||
if (data)
|
||||
data++;
|
||||
|
||||
size /= 4;
|
||||
width /= 2;
|
||||
size /= 4;
|
||||
width /= 2;
|
||||
height /= 2;
|
||||
|
||||
if (width == 0) width = 1;
|
||||
if (height == 0) height = 1;
|
||||
if (width == 0)
|
||||
width = 1;
|
||||
if (height == 0)
|
||||
height = 1;
|
||||
}
|
||||
|
||||
if (data)
|
||||
|
|
@ -58,8 +60,8 @@ bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
|
|||
}
|
||||
|
||||
static bool gl_copy_fbo(struct gs_texture *dst, uint32_t dst_x, uint32_t dst_y,
|
||||
struct gs_texture *src, uint32_t src_x, uint32_t src_y,
|
||||
uint32_t width, uint32_t height)
|
||||
struct gs_texture *src, uint32_t src_x, uint32_t src_y,
|
||||
uint32_t width, uint32_t height)
|
||||
{
|
||||
struct fbo_info *fbo = get_fbo(src, width, height);
|
||||
GLint last_fbo;
|
||||
|
|
@ -76,7 +78,7 @@ static bool gl_copy_fbo(struct gs_texture *dst, uint32_t dst_x, uint32_t dst_y,
|
|||
goto fail;
|
||||
|
||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 0,
|
||||
src->gl_target, src->texture, 0);
|
||||
src->gl_target, src->texture, 0);
|
||||
if (!gl_success("glFrameBufferTexture2D"))
|
||||
goto fail;
|
||||
|
||||
|
|
@ -85,7 +87,7 @@ static bool gl_copy_fbo(struct gs_texture *dst, uint32_t dst_x, uint32_t dst_y,
|
|||
goto fail;
|
||||
|
||||
glCopyTexSubImage2D(dst->gl_target, 0, dst_x, dst_y, src_x, src_y,
|
||||
width, height);
|
||||
width, height);
|
||||
if (!gl_success("glCopyTexSubImage2D"))
|
||||
goto fail;
|
||||
|
||||
|
|
@ -101,27 +103,27 @@ fail:
|
|||
}
|
||||
|
||||
bool gl_copy_texture(struct gs_device *device, struct gs_texture *dst,
|
||||
uint32_t dst_x, uint32_t dst_y, struct gs_texture *src,
|
||||
uint32_t src_x, uint32_t src_y, uint32_t width,
|
||||
uint32_t height)
|
||||
uint32_t dst_x, uint32_t dst_y, struct gs_texture *src,
|
||||
uint32_t src_x, uint32_t src_y, uint32_t width,
|
||||
uint32_t height)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
if (device->copy_type == COPY_TYPE_ARB) {
|
||||
glCopyImageSubData(src->texture, src->gl_target, 0, src_x,
|
||||
src_y, 0, dst->texture, dst->gl_target, 0,
|
||||
dst_x, dst_y, 0, width, height, 1);
|
||||
src_y, 0, dst->texture, dst->gl_target, 0,
|
||||
dst_x, dst_y, 0, width, height, 1);
|
||||
success = gl_success("glCopyImageSubData");
|
||||
|
||||
} else if (device->copy_type == COPY_TYPE_NV) {
|
||||
glCopyImageSubDataNV(src->texture, src->gl_target, 0, src_x,
|
||||
src_y, 0, dst->texture, dst->gl_target, 0,
|
||||
dst_x, dst_y, 0, width, height, 1);
|
||||
src_y, 0, dst->texture, dst->gl_target, 0,
|
||||
dst_x, dst_y, 0, width, height, 1);
|
||||
success = gl_success("glCopyImageSubDataNV");
|
||||
|
||||
} else if (device->copy_type == COPY_TYPE_FBO_BLIT) {
|
||||
success = gl_copy_fbo(dst, dst_x, dst_y, src, src_x, src_y,
|
||||
width, height);
|
||||
width, height);
|
||||
if (!success)
|
||||
blog(LOG_ERROR, "gl_copy_texture failed");
|
||||
}
|
||||
|
|
@ -130,7 +132,7 @@ bool gl_copy_texture(struct gs_device *device, struct gs_texture *dst,
|
|||
}
|
||||
|
||||
bool gl_create_buffer(GLenum target, GLuint *buffer, GLsizeiptr size,
|
||||
const GLvoid *data, GLenum usage)
|
||||
const GLvoid *data, GLenum usage)
|
||||
{
|
||||
bool success;
|
||||
if (!gl_gen_buffers(1, buffer))
|
||||
|
|
@ -156,8 +158,7 @@ bool update_buffer(GLenum target, GLuint buffer, const void *data, size_t size)
|
|||
/* glMapBufferRange with these flags will actually give far better
|
||||
* performance than a plain glMapBuffer call */
|
||||
ptr = glMapBufferRange(target, 0, size,
|
||||
GL_MAP_WRITE_BIT |
|
||||
GL_MAP_INVALIDATE_BUFFER_BIT);
|
||||
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
|
||||
success = gl_success("glMapBufferRange");
|
||||
if (success && ptr) {
|
||||
memcpy(ptr, data, size);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,48 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
static const char *gl_error_to_str(GLenum errorcode)
|
||||
{
|
||||
static const struct {
|
||||
GLenum error;
|
||||
const char *str;
|
||||
} err_to_str[] = {
|
||||
{
|
||||
GL_INVALID_ENUM,
|
||||
"GL_INVALID_ENUM",
|
||||
},
|
||||
{
|
||||
GL_INVALID_VALUE,
|
||||
"GL_INVALID_VALUE",
|
||||
},
|
||||
{
|
||||
GL_INVALID_OPERATION,
|
||||
"GL_INVALID_OPERATION",
|
||||
},
|
||||
{
|
||||
GL_INVALID_FRAMEBUFFER_OPERATION,
|
||||
"GL_INVALID_FRAMEBUFFER_OPERATION",
|
||||
},
|
||||
{
|
||||
GL_OUT_OF_MEMORY,
|
||||
"GL_OUT_OF_MEMORY",
|
||||
},
|
||||
{
|
||||
GL_STACK_UNDERFLOW,
|
||||
"GL_STACK_UNDERFLOW",
|
||||
},
|
||||
{
|
||||
GL_STACK_OVERFLOW,
|
||||
"GL_STACK_OVERFLOW",
|
||||
},
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(err_to_str) / sizeof(*err_to_str); i++) {
|
||||
if (err_to_str[i].error == errorcode)
|
||||
return err_to_str[i].str;
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
/*
|
||||
* Okay, so GL error handling is.. unclean to work with. I don't want
|
||||
* to have to keep typing out the same stuff over and over again do I'll just
|
||||
|
|
@ -27,8 +69,20 @@ static inline bool gl_success(const char *funcname)
|
|||
{
|
||||
GLenum errorcode = glGetError();
|
||||
if (errorcode != GL_NO_ERROR) {
|
||||
blog(LOG_ERROR, "%s failed, glGetError returned 0x%X",
|
||||
funcname, errorcode);
|
||||
int attempts = 8;
|
||||
do {
|
||||
blog(LOG_ERROR,
|
||||
"%s failed, glGetError returned %s(0x%X)",
|
||||
funcname, gl_error_to_str(errorcode), errorcode);
|
||||
errorcode = glGetError();
|
||||
|
||||
--attempts;
|
||||
if (attempts == 0) {
|
||||
blog(LOG_ERROR,
|
||||
"Too many GL errors, moving on");
|
||||
break;
|
||||
}
|
||||
} while (errorcode != GL_NO_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -144,17 +198,17 @@ static inline bool gl_get_integer_v(GLenum pname, GLint *params)
|
|||
}
|
||||
|
||||
extern bool gl_init_face(GLenum target, GLenum type, uint32_t num_levels,
|
||||
GLenum format, GLint internal_format, bool compressed,
|
||||
uint32_t width, uint32_t height, uint32_t size,
|
||||
const uint8_t ***p_data);
|
||||
GLenum format, GLint internal_format, bool compressed,
|
||||
uint32_t width, uint32_t height, uint32_t size,
|
||||
const uint8_t ***p_data);
|
||||
|
||||
extern bool gl_copy_texture(struct gs_device *device, struct gs_texture *dst,
|
||||
uint32_t dst_x, uint32_t dst_y, struct gs_texture *src,
|
||||
uint32_t src_x, uint32_t src_y, uint32_t width,
|
||||
uint32_t height);
|
||||
uint32_t dst_x, uint32_t dst_y,
|
||||
struct gs_texture *src, uint32_t src_x,
|
||||
uint32_t src_y, uint32_t width, uint32_t height);
|
||||
|
||||
extern bool gl_create_buffer(GLenum target, GLuint *buffer, GLsizeiptr size,
|
||||
const GLvoid *data, GLenum usage);
|
||||
const GLvoid *data, GLenum usage);
|
||||
|
||||
extern bool update_buffer(GLenum target, GLuint buffer, const void *data,
|
||||
size_t size);
|
||||
size_t size);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ static inline bool init_ib(struct gs_index_buffer *ib)
|
|||
bool success;
|
||||
|
||||
success = gl_create_buffer(GL_ELEMENT_ARRAY_BUFFER, &ib->buffer,
|
||||
ib->size, ib->data, usage);
|
||||
ib->size, ib->data, usage);
|
||||
|
||||
if (!ib->dynamic) {
|
||||
bfree(ib->data);
|
||||
|
|
@ -34,21 +34,22 @@ static inline bool init_ib(struct gs_index_buffer *ib)
|
|||
}
|
||||
|
||||
gs_indexbuffer_t *device_indexbuffer_create(gs_device_t *device,
|
||||
enum gs_index_type type, void *indices, size_t num,
|
||||
uint32_t flags)
|
||||
enum gs_index_type type,
|
||||
void *indices, size_t num,
|
||||
uint32_t flags)
|
||||
{
|
||||
struct gs_index_buffer *ib = bzalloc(sizeof(struct gs_index_buffer));
|
||||
size_t width = type == GS_UNSIGNED_LONG ? 4 : 2;
|
||||
|
||||
ib->device = device;
|
||||
ib->data = indices;
|
||||
ib->device = device;
|
||||
ib->data = indices;
|
||||
ib->dynamic = flags & GS_DYNAMIC;
|
||||
ib->num = num;
|
||||
ib->width = width;
|
||||
ib->size = width * num;
|
||||
ib->type = type;
|
||||
ib->gl_type = type == GS_UNSIGNED_LONG ? GL_UNSIGNED_INT :
|
||||
GL_UNSIGNED_SHORT;
|
||||
ib->num = num;
|
||||
ib->width = width;
|
||||
ib->size = width * num;
|
||||
ib->type = type;
|
||||
ib->gl_type = type == GS_UNSIGNED_LONG ? GL_UNSIGNED_INT
|
||||
: GL_UNSIGNED_SHORT;
|
||||
|
||||
if (!init_ib(ib)) {
|
||||
blog(LOG_ERROR, "device_indexbuffer_create (GL) failed");
|
||||
|
|
@ -71,7 +72,7 @@ void gs_indexbuffer_destroy(gs_indexbuffer_t *ib)
|
|||
}
|
||||
|
||||
static inline void gs_indexbuffer_flush_internal(gs_indexbuffer_t *ib,
|
||||
const void *data)
|
||||
const void *data)
|
||||
{
|
||||
if (!ib->dynamic) {
|
||||
blog(LOG_ERROR, "Index buffer is not dynamic");
|
||||
|
|
|
|||
|
|
@ -43,17 +43,17 @@ static inline void shader_attrib_free(struct shader_attrib *attrib)
|
|||
}
|
||||
|
||||
static void gl_get_shader_info(GLuint shader, const char *file,
|
||||
char **error_string)
|
||||
char **error_string)
|
||||
{
|
||||
char *errors;
|
||||
GLint info_len = 0;
|
||||
char *errors;
|
||||
GLint info_len = 0;
|
||||
GLsizei chars_written = 0;
|
||||
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len);
|
||||
if (!gl_success("glGetProgramiv") || !info_len)
|
||||
return;
|
||||
|
||||
errors = bzalloc(info_len+1);
|
||||
errors = bzalloc(info_len + 1);
|
||||
glGetShaderInfoLog(shader, info_len, &chars_written, errors);
|
||||
gl_success("glGetShaderInfoLog");
|
||||
|
||||
|
|
@ -66,18 +66,18 @@ static void gl_get_shader_info(GLuint shader, const char *file,
|
|||
}
|
||||
|
||||
static bool gl_add_param(struct gs_shader *shader, struct shader_var *var,
|
||||
GLint *texture_id)
|
||||
GLint *texture_id)
|
||||
{
|
||||
struct gs_shader_param param = {0};
|
||||
|
||||
param.array_count = var->array_count;
|
||||
param.name = bstrdup(var->name);
|
||||
param.shader = shader;
|
||||
param.type = get_shader_param_type(var->type);
|
||||
param.name = bstrdup(var->name);
|
||||
param.shader = shader;
|
||||
param.type = get_shader_param_type(var->type);
|
||||
|
||||
if (param.type == GS_SHADER_PARAM_TEXTURE) {
|
||||
param.sampler_id = var->gl_sampler_id;
|
||||
param.texture_id = (*texture_id)++;
|
||||
param.sampler_id = var->gl_sampler_id;
|
||||
param.texture_id = (*texture_id)++;
|
||||
} else {
|
||||
param.changed = true;
|
||||
}
|
||||
|
|
@ -90,23 +90,24 @@ static bool gl_add_param(struct gs_shader *shader, struct shader_var *var,
|
|||
}
|
||||
|
||||
static inline bool gl_add_params(struct gs_shader *shader,
|
||||
struct gl_shader_parser *glsp)
|
||||
struct gl_shader_parser *glsp)
|
||||
{
|
||||
size_t i;
|
||||
GLint tex_id = 0;
|
||||
|
||||
for (i = 0; i < glsp->parser.params.num; i++)
|
||||
if (!gl_add_param(shader, glsp->parser.params.array+i, &tex_id))
|
||||
if (!gl_add_param(shader, glsp->parser.params.array + i,
|
||||
&tex_id))
|
||||
return false;
|
||||
|
||||
shader->viewproj = gs_shader_get_param_by_name(shader, "ViewProj");
|
||||
shader->world = gs_shader_get_param_by_name(shader, "World");
|
||||
shader->world = gs_shader_get_param_by_name(shader, "World");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void gl_add_sampler(struct gs_shader *shader,
|
||||
struct shader_sampler *sampler)
|
||||
struct shader_sampler *sampler)
|
||||
{
|
||||
gs_samplerstate_t *new_sampler;
|
||||
struct gs_sampler_info info;
|
||||
|
|
@ -118,44 +119,45 @@ static inline void gl_add_sampler(struct gs_shader *shader,
|
|||
}
|
||||
|
||||
static inline void gl_add_samplers(struct gs_shader *shader,
|
||||
struct gl_shader_parser *glsp)
|
||||
struct gl_shader_parser *glsp)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->parser.samplers.num; i++) {
|
||||
struct shader_sampler *sampler = glsp->parser.samplers.array+i;
|
||||
struct shader_sampler *sampler =
|
||||
glsp->parser.samplers.array + i;
|
||||
gl_add_sampler(shader, sampler);
|
||||
}
|
||||
}
|
||||
|
||||
static void get_attrib_type(const char *mapping, enum attrib_type *type,
|
||||
size_t *index)
|
||||
size_t *index)
|
||||
{
|
||||
if (strcmp(mapping, "POSITION") == 0) {
|
||||
*type = ATTRIB_POSITION;
|
||||
*type = ATTRIB_POSITION;
|
||||
|
||||
} else if (strcmp(mapping, "NORMAL") == 0) {
|
||||
*type = ATTRIB_NORMAL;
|
||||
*type = ATTRIB_NORMAL;
|
||||
|
||||
} else if (strcmp(mapping, "TANGENT") == 0) {
|
||||
*type = ATTRIB_TANGENT;
|
||||
*type = ATTRIB_TANGENT;
|
||||
|
||||
} else if (strcmp(mapping, "COLOR") == 0) {
|
||||
*type = ATTRIB_COLOR;
|
||||
*type = ATTRIB_COLOR;
|
||||
|
||||
} else if (astrcmp_n(mapping, "TEXCOORD", 8) == 0) {
|
||||
*type = ATTRIB_TEXCOORD;
|
||||
*index = (*(mapping+8)) - '0';
|
||||
*type = ATTRIB_TEXCOORD;
|
||||
*index = (*(mapping + 8)) - '0';
|
||||
return;
|
||||
|
||||
} else if (strcmp(mapping, "TARGET") == 0) {
|
||||
*type = ATTRIB_TARGET;
|
||||
*type = ATTRIB_TARGET;
|
||||
}
|
||||
|
||||
*index = 0;
|
||||
}
|
||||
|
||||
static inline bool gl_process_attrib(struct gs_shader *program,
|
||||
struct gl_parser_attrib *pa)
|
||||
struct gl_parser_attrib *pa)
|
||||
{
|
||||
struct shader_attrib attrib = {0};
|
||||
|
||||
|
|
@ -166,8 +168,8 @@ static inline bool gl_process_attrib(struct gs_shader *program,
|
|||
get_attrib_type(pa->mapping, &attrib.type, &attrib.index);
|
||||
attrib.name = pa->name.array;
|
||||
|
||||
pa->name.array = NULL;
|
||||
pa->name.len = 0;
|
||||
pa->name.array = NULL;
|
||||
pa->name.len = 0;
|
||||
pa->name.capacity = 0;
|
||||
|
||||
da_push_back(program->attribs, &attrib);
|
||||
|
|
@ -175,11 +177,11 @@ static inline bool gl_process_attrib(struct gs_shader *program,
|
|||
}
|
||||
|
||||
static inline bool gl_process_attribs(struct gs_shader *shader,
|
||||
struct gl_shader_parser *glsp)
|
||||
struct gl_shader_parser *glsp)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->attribs.num; i++) {
|
||||
struct gl_parser_attrib *pa = glsp->attribs.array+i;
|
||||
struct gl_parser_attrib *pa = glsp->attribs.array + i;
|
||||
if (!gl_process_attrib(shader, pa))
|
||||
return false;
|
||||
}
|
||||
|
|
@ -188,8 +190,8 @@ static inline bool gl_process_attribs(struct gs_shader *shader,
|
|||
}
|
||||
|
||||
static bool gl_shader_init(struct gs_shader *shader,
|
||||
struct gl_shader_parser *glsp,
|
||||
const char *file, char **error_string)
|
||||
struct gl_shader_parser *glsp, const char *file,
|
||||
char **error_string)
|
||||
{
|
||||
GLenum type = convert_shader_type(shader->type);
|
||||
int compiled = 0;
|
||||
|
|
@ -199,8 +201,8 @@ static bool gl_shader_init(struct gs_shader *shader,
|
|||
if (!gl_success("glCreateShader") || !shader->obj)
|
||||
return false;
|
||||
|
||||
glShaderSource(shader->obj, 1, (const GLchar**)&glsp->gl_string.array,
|
||||
0);
|
||||
glShaderSource(shader->obj, 1, (const GLchar **)&glsp->gl_string.array,
|
||||
0);
|
||||
if (!gl_success("glShaderSource"))
|
||||
return false;
|
||||
|
||||
|
|
@ -227,7 +229,8 @@ static bool gl_shader_init(struct gs_shader *shader,
|
|||
char *infoLog = malloc(sizeof(char) * infoLength);
|
||||
|
||||
GLsizei returnedLength = 0;
|
||||
glGetShaderInfoLog(shader->obj, infoLength, &returnedLength, infoLog);
|
||||
glGetShaderInfoLog(shader->obj, infoLength, &returnedLength,
|
||||
infoLog);
|
||||
blog(LOG_ERROR, "Error compiling shader:\n%s\n", infoLog);
|
||||
|
||||
free(infoLog);
|
||||
|
|
@ -249,15 +252,16 @@ static bool gl_shader_init(struct gs_shader *shader,
|
|||
}
|
||||
|
||||
static struct gs_shader *shader_create(gs_device_t *device,
|
||||
enum gs_shader_type type, const char *shader_str,
|
||||
const char *file, char **error_string)
|
||||
enum gs_shader_type type,
|
||||
const char *shader_str, const char *file,
|
||||
char **error_string)
|
||||
{
|
||||
struct gs_shader *shader = bzalloc(sizeof(struct gs_shader));
|
||||
struct gl_shader_parser glsp;
|
||||
bool success = true;
|
||||
|
||||
shader->device = device;
|
||||
shader->type = type;
|
||||
shader->type = type;
|
||||
|
||||
gl_shader_parser_init(&glsp, type);
|
||||
if (!gl_shader_parse(&glsp, shader_str, file))
|
||||
|
|
@ -274,25 +278,23 @@ static struct gs_shader *shader_create(gs_device_t *device,
|
|||
return shader;
|
||||
}
|
||||
|
||||
gs_shader_t *device_vertexshader_create(gs_device_t *device,
|
||||
const char *shader, const char *file,
|
||||
char **error_string)
|
||||
gs_shader_t *device_vertexshader_create(gs_device_t *device, const char *shader,
|
||||
const char *file, char **error_string)
|
||||
{
|
||||
struct gs_shader *ptr;
|
||||
ptr = shader_create(device, GS_SHADER_VERTEX, shader, file,
|
||||
error_string);
|
||||
error_string);
|
||||
if (!ptr)
|
||||
blog(LOG_ERROR, "device_vertexshader_create (GL) failed");
|
||||
return ptr;
|
||||
}
|
||||
|
||||
gs_shader_t *device_pixelshader_create(gs_device_t *device,
|
||||
const char *shader, const char *file,
|
||||
char **error_string)
|
||||
gs_shader_t *device_pixelshader_create(gs_device_t *device, const char *shader,
|
||||
const char *file, char **error_string)
|
||||
{
|
||||
struct gs_shader *ptr;
|
||||
ptr = shader_create(device, GS_SHADER_PIXEL, shader, file,
|
||||
error_string);
|
||||
error_string);
|
||||
if (!ptr)
|
||||
blog(LOG_ERROR, "device_pixelshader_create (GL) failed");
|
||||
return ptr;
|
||||
|
|
@ -307,11 +309,11 @@ static void remove_program_references(struct gs_shader *shader)
|
|||
bool destroy = false;
|
||||
|
||||
if (shader->type == GS_SHADER_VERTEX &&
|
||||
program->vertex_shader == shader)
|
||||
program->vertex_shader == shader)
|
||||
destroy = true;
|
||||
|
||||
else if (shader->type == GS_SHADER_PIXEL &&
|
||||
program->pixel_shader == shader)
|
||||
program->pixel_shader == shader)
|
||||
destroy = true;
|
||||
|
||||
if (destroy)
|
||||
|
|
@ -331,13 +333,13 @@ void gs_shader_destroy(gs_shader_t *shader)
|
|||
remove_program_references(shader);
|
||||
|
||||
for (i = 0; i < shader->attribs.num; i++)
|
||||
shader_attrib_free(shader->attribs.array+i);
|
||||
shader_attrib_free(shader->attribs.array + i);
|
||||
|
||||
for (i = 0; i < shader->samplers.num; i++)
|
||||
gs_samplerstate_destroy(shader->samplers.array[i]);
|
||||
|
||||
for (i = 0; i < shader->params.num; i++)
|
||||
shader_param_free(shader->params.array+i);
|
||||
shader_param_free(shader->params.array + i);
|
||||
|
||||
if (shader->obj) {
|
||||
glDeleteShader(shader->obj);
|
||||
|
|
@ -358,14 +360,14 @@ int gs_shader_get_num_params(const gs_shader_t *shader)
|
|||
gs_sparam_t *gs_shader_get_param_by_idx(gs_shader_t *shader, uint32_t param)
|
||||
{
|
||||
assert(param < shader->params.num);
|
||||
return shader->params.array+param;
|
||||
return shader->params.array + param;
|
||||
}
|
||||
|
||||
gs_sparam_t *gs_shader_get_param_by_name(gs_shader_t *shader, const char *name)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < shader->params.num; i++) {
|
||||
struct gs_shader_param *param = shader->params.array+i;
|
||||
struct gs_shader_param *param = shader->params.array + i;
|
||||
|
||||
if (strcmp(param->name, name) == 0)
|
||||
return param;
|
||||
|
|
@ -385,7 +387,7 @@ gs_sparam_t *gs_shader_get_world_matrix(const gs_shader_t *shader)
|
|||
}
|
||||
|
||||
void gs_shader_get_param_info(const gs_sparam_t *param,
|
||||
struct gs_shader_param_info *info)
|
||||
struct gs_shader_param_info *info)
|
||||
{
|
||||
info->type = param->type;
|
||||
info->name = param->name;
|
||||
|
|
@ -441,14 +443,14 @@ void gs_shader_set_texture(gs_sparam_t *param, gs_texture_t *val)
|
|||
}
|
||||
|
||||
static inline bool validate_param(struct program_param *pp,
|
||||
size_t expected_size)
|
||||
size_t expected_size)
|
||||
{
|
||||
if (pp->param->cur_value.num != expected_size) {
|
||||
blog(LOG_ERROR, "Parameter '%s' set to invalid size %u, "
|
||||
"expected %u",
|
||||
pp->param->name,
|
||||
(unsigned int)pp->param->cur_value.num,
|
||||
(unsigned int)expected_size);
|
||||
blog(LOG_ERROR,
|
||||
"Parameter '%s' set to invalid size %u, "
|
||||
"expected %u",
|
||||
pp->param->name, (unsigned int)pp->param->cur_value.num,
|
||||
(unsigned int)expected_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -456,63 +458,62 @@ static inline bool validate_param(struct program_param *pp,
|
|||
}
|
||||
|
||||
static void program_set_param_data(struct gs_program *program,
|
||||
struct program_param *pp)
|
||||
struct program_param *pp)
|
||||
{
|
||||
void *array = pp->param->cur_value.array;
|
||||
|
||||
if (pp->param->type == GS_SHADER_PARAM_BOOL ||
|
||||
pp->param->type == GS_SHADER_PARAM_INT) {
|
||||
if (validate_param(pp, sizeof(int))) {
|
||||
glUniform1iv(pp->obj, 1, (int*)array);
|
||||
glUniform1iv(pp->obj, 1, (int *)array);
|
||||
gl_success("glUniform1iv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_INT2) {
|
||||
if (validate_param(pp, sizeof(int) * 2)) {
|
||||
glUniform2iv(pp->obj, 1, (int*)array);
|
||||
glUniform2iv(pp->obj, 1, (int *)array);
|
||||
gl_success("glUniform2iv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_INT3) {
|
||||
if (validate_param(pp, sizeof(int) * 3)) {
|
||||
glUniform3iv(pp->obj, 1, (int*)array);
|
||||
glUniform3iv(pp->obj, 1, (int *)array);
|
||||
gl_success("glUniform3iv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_INT4) {
|
||||
if (validate_param(pp, sizeof(int) * 4)) {
|
||||
glUniform4iv(pp->obj, 1, (int*)array);
|
||||
glUniform4iv(pp->obj, 1, (int *)array);
|
||||
gl_success("glUniform4iv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_FLOAT) {
|
||||
if (validate_param(pp, sizeof(float))) {
|
||||
glUniform1fv(pp->obj, 1, (float*)array);
|
||||
glUniform1fv(pp->obj, 1, (float *)array);
|
||||
gl_success("glUniform1fv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_VEC2) {
|
||||
if (validate_param(pp, sizeof(struct vec2))) {
|
||||
glUniform2fv(pp->obj, 1, (float*)array);
|
||||
glUniform2fv(pp->obj, 1, (float *)array);
|
||||
gl_success("glUniform2fv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_VEC3) {
|
||||
if (validate_param(pp, sizeof(float) * 3)) {
|
||||
glUniform3fv(pp->obj, 1, (float*)array);
|
||||
glUniform3fv(pp->obj, 1, (float *)array);
|
||||
gl_success("glUniform3fv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_VEC4) {
|
||||
if (validate_param(pp, sizeof(struct vec4))) {
|
||||
glUniform4fv(pp->obj, 1, (float*)array);
|
||||
glUniform4fv(pp->obj, 1, (float *)array);
|
||||
gl_success("glUniform4fv");
|
||||
}
|
||||
|
||||
} else if (pp->param->type == GS_SHADER_PARAM_MATRIX4X4) {
|
||||
if (validate_param(pp, sizeof(struct matrix4))) {
|
||||
glUniformMatrix4fv(pp->obj, 1, false,
|
||||
(float*)array);
|
||||
glUniformMatrix4fv(pp->obj, 1, false, (float *)array);
|
||||
gl_success("glUniformMatrix4fv");
|
||||
}
|
||||
|
||||
|
|
@ -525,7 +526,7 @@ static void program_set_param_data(struct gs_program *program,
|
|||
|
||||
glUniform1i(pp->obj, pp->param->texture_id);
|
||||
device_load_texture(program->device, pp->param->texture,
|
||||
pp->param->texture_id);
|
||||
pp->param->texture_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -539,15 +540,15 @@ void program_update_params(struct gs_program *program)
|
|||
|
||||
static void print_link_errors(GLuint program)
|
||||
{
|
||||
char *errors = NULL;
|
||||
GLint info_len = 0;
|
||||
char *errors = NULL;
|
||||
GLint info_len = 0;
|
||||
GLsizei chars_written = 0;
|
||||
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_len);
|
||||
if (!gl_success("glGetProgramiv") || !info_len)
|
||||
return;
|
||||
|
||||
errors = calloc(1, info_len+1);
|
||||
errors = calloc(1, info_len + 1);
|
||||
glGetProgramInfoLog(program, info_len, &chars_written, errors);
|
||||
gl_success("glGetShaderInfoLog");
|
||||
|
||||
|
|
@ -557,15 +558,17 @@ static void print_link_errors(GLuint program)
|
|||
}
|
||||
|
||||
static bool assign_program_attrib(struct gs_program *program,
|
||||
struct shader_attrib *attrib)
|
||||
struct shader_attrib *attrib)
|
||||
{
|
||||
GLint attrib_obj = glGetAttribLocation(program->obj, attrib->name);
|
||||
if (!gl_success("glGetAttribLocation"))
|
||||
return false;
|
||||
|
||||
if (attrib_obj == -1) {
|
||||
blog(LOG_ERROR, "glGetAttribLocation: Could not find "
|
||||
"attribute '%s'", attrib->name);
|
||||
blog(LOG_ERROR,
|
||||
"glGetAttribLocation: Could not find "
|
||||
"attribute '%s'",
|
||||
attrib->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -587,7 +590,7 @@ static inline bool assign_program_attribs(struct gs_program *program)
|
|||
}
|
||||
|
||||
static bool assign_program_param(struct gs_program *program,
|
||||
struct gs_shader_param *param)
|
||||
struct gs_shader_param *param)
|
||||
{
|
||||
struct program_param info;
|
||||
|
||||
|
|
@ -605,7 +608,7 @@ static bool assign_program_param(struct gs_program *program,
|
|||
}
|
||||
|
||||
static inline bool assign_program_shader_params(struct gs_program *program,
|
||||
struct gs_shader *shader)
|
||||
struct gs_shader *shader)
|
||||
{
|
||||
for (size_t i = 0; i < shader->params.num; i++) {
|
||||
struct gs_shader_param *param = shader->params.array + i;
|
||||
|
|
@ -631,9 +634,9 @@ struct gs_program *gs_program_create(struct gs_device *device)
|
|||
struct gs_program *program = bzalloc(sizeof(*program));
|
||||
int linked = false;
|
||||
|
||||
program->device = device;
|
||||
program->device = device;
|
||||
program->vertex_shader = device->cur_vertex_shader;
|
||||
program->pixel_shader = device->cur_pixel_shader;
|
||||
program->pixel_shader = device->cur_pixel_shader;
|
||||
|
||||
program->obj = glCreateProgram();
|
||||
if (!gl_success("glCreateProgram"))
|
||||
|
|
@ -725,18 +728,39 @@ void gs_shader_set_val(gs_sparam_t *param, const void *val, size_t size)
|
|||
count = 1;
|
||||
|
||||
switch ((uint32_t)param->type) {
|
||||
case GS_SHADER_PARAM_FLOAT: expected_size = sizeof(float); break;
|
||||
case GS_SHADER_PARAM_FLOAT:
|
||||
expected_size = sizeof(float);
|
||||
break;
|
||||
case GS_SHADER_PARAM_BOOL:
|
||||
case GS_SHADER_PARAM_INT: expected_size = sizeof(int); break;
|
||||
case GS_SHADER_PARAM_INT2: expected_size = sizeof(int) * 2; break;
|
||||
case GS_SHADER_PARAM_INT3: expected_size = sizeof(int) * 3; break;
|
||||
case GS_SHADER_PARAM_INT4: expected_size = sizeof(int) * 4; break;
|
||||
case GS_SHADER_PARAM_VEC2: expected_size = sizeof(float)*2; break;
|
||||
case GS_SHADER_PARAM_VEC3: expected_size = sizeof(float)*3; break;
|
||||
case GS_SHADER_PARAM_VEC4: expected_size = sizeof(float)*4; break;
|
||||
case GS_SHADER_PARAM_MATRIX4X4: expected_size = sizeof(float)*4*4;break;
|
||||
case GS_SHADER_PARAM_TEXTURE: expected_size = sizeof(void*); break;
|
||||
default: expected_size = 0;
|
||||
case GS_SHADER_PARAM_INT:
|
||||
expected_size = sizeof(int);
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT2:
|
||||
expected_size = sizeof(int) * 2;
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT3:
|
||||
expected_size = sizeof(int) * 3;
|
||||
break;
|
||||
case GS_SHADER_PARAM_INT4:
|
||||
expected_size = sizeof(int) * 4;
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC2:
|
||||
expected_size = sizeof(float) * 2;
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC3:
|
||||
expected_size = sizeof(float) * 3;
|
||||
break;
|
||||
case GS_SHADER_PARAM_VEC4:
|
||||
expected_size = sizeof(float) * 4;
|
||||
break;
|
||||
case GS_SHADER_PARAM_MATRIX4X4:
|
||||
expected_size = sizeof(float) * 4 * 4;
|
||||
break;
|
||||
case GS_SHADER_PARAM_TEXTURE:
|
||||
expected_size = sizeof(void *);
|
||||
break;
|
||||
default:
|
||||
expected_size = 0;
|
||||
}
|
||||
|
||||
expected_size *= count;
|
||||
|
|
@ -745,12 +769,12 @@ void gs_shader_set_val(gs_sparam_t *param, const void *val, size_t size)
|
|||
|
||||
if (expected_size != size) {
|
||||
blog(LOG_ERROR, "gs_shader_set_val (GL): Size of shader "
|
||||
"param does not match the size of the input");
|
||||
"param does not match the size of the input");
|
||||
return;
|
||||
}
|
||||
|
||||
if (param->type == GS_SHADER_PARAM_TEXTURE)
|
||||
gs_shader_set_texture(param, *(gs_texture_t**)val);
|
||||
gs_shader_set_texture(param, *(gs_texture_t **)val);
|
||||
else
|
||||
da_copy_array(param->cur_value, val, size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,15 @@
|
|||
#include "gl-shaderparser.h"
|
||||
|
||||
static void gl_write_function_contents(struct gl_shader_parser *glsp,
|
||||
struct cf_token **p_token, const char *end);
|
||||
struct cf_token **p_token,
|
||||
const char *end);
|
||||
|
||||
static inline struct shader_var *sp_getparam(struct gl_shader_parser *glsp,
|
||||
struct cf_token *token)
|
||||
struct cf_token *token)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->parser.params.num; i++) {
|
||||
struct shader_var *param = glsp->parser.params.array+i;
|
||||
struct shader_var *param = glsp->parser.params.array + i;
|
||||
if (strref_cmp(&token->str, param->name) == 0)
|
||||
return param;
|
||||
}
|
||||
|
|
@ -35,11 +36,12 @@ static inline struct shader_var *sp_getparam(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static inline size_t sp_getsampler(struct gl_shader_parser *glsp,
|
||||
struct cf_token *token)
|
||||
struct cf_token *token)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->parser.samplers.num; i++) {
|
||||
struct shader_sampler *sampler = glsp->parser.samplers.array+i;
|
||||
struct shader_sampler *sampler =
|
||||
glsp->parser.samplers.array + i;
|
||||
if (strref_cmp(&token->str, sampler->name) == 0)
|
||||
return i;
|
||||
}
|
||||
|
|
@ -48,14 +50,14 @@ static inline size_t sp_getsampler(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static inline int cmp_type(const char *name, const size_t name_len,
|
||||
const char *type, const size_t type_len)
|
||||
const char *type, const size_t type_len)
|
||||
{
|
||||
size_t min_len = (name_len < type_len) ? type_len : name_len;
|
||||
return astrcmp_n(name, type, min_len);
|
||||
}
|
||||
|
||||
static bool gl_write_type_n(struct gl_shader_parser *glsp,
|
||||
const char *type, size_t len)
|
||||
static bool gl_write_type_n(struct gl_shader_parser *glsp, const char *type,
|
||||
size_t len)
|
||||
{
|
||||
if (cmp_type(type, len, "float2", 6) == 0)
|
||||
dstr_cat(&glsp->gl_string, "vec2");
|
||||
|
|
@ -90,14 +92,14 @@ static bool gl_write_type_n(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static inline void gl_write_type(struct gl_shader_parser *glsp,
|
||||
const char *type)
|
||||
const char *type)
|
||||
{
|
||||
if (!gl_write_type_n(glsp, type, strlen(type)))
|
||||
dstr_cat(&glsp->gl_string, type);
|
||||
}
|
||||
|
||||
static inline bool gl_write_type_token(struct gl_shader_parser *glsp,
|
||||
struct cf_token *token)
|
||||
struct cf_token *token)
|
||||
{
|
||||
return gl_write_type_n(glsp, token->str.array, token->str.len);
|
||||
}
|
||||
|
|
@ -122,7 +124,7 @@ static inline void gl_write_params(struct gl_shader_parser *glsp)
|
|||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->parser.params.num; i++) {
|
||||
struct shader_var *var = glsp->parser.params.array+i;
|
||||
struct shader_var *var = glsp->parser.params.array + i;
|
||||
gl_write_var(glsp, var);
|
||||
dstr_cat(&glsp->gl_string, ";\n");
|
||||
}
|
||||
|
|
@ -131,12 +133,13 @@ static inline void gl_write_params(struct gl_shader_parser *glsp)
|
|||
}
|
||||
|
||||
static void gl_write_storage_var(struct gl_shader_parser *glsp,
|
||||
struct shader_var *var, bool input, const char *prefix);
|
||||
struct shader_var *var, bool input,
|
||||
const char *prefix);
|
||||
|
||||
/* unwraps a structure that's used for input/output */
|
||||
static void gl_unwrap_storage_struct(struct gl_shader_parser *glsp,
|
||||
struct shader_struct *st, const char *name, bool input,
|
||||
const char *prefix)
|
||||
struct shader_struct *st, const char *name,
|
||||
bool input, const char *prefix)
|
||||
{
|
||||
struct dstr prefix_str;
|
||||
size_t i;
|
||||
|
|
@ -148,7 +151,7 @@ static void gl_unwrap_storage_struct(struct gl_shader_parser *glsp,
|
|||
dstr_cat(&prefix_str, "_");
|
||||
|
||||
for (i = 0; i < st->vars.num; i++) {
|
||||
struct shader_var *st_var = st->vars.array+i;
|
||||
struct shader_var *st_var = st->vars.array + i;
|
||||
gl_write_storage_var(glsp, st_var, input, prefix_str.array);
|
||||
}
|
||||
|
||||
|
|
@ -156,14 +159,24 @@ static void gl_unwrap_storage_struct(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static void gl_write_storage_var(struct gl_shader_parser *glsp,
|
||||
struct shader_var *var, bool input, const char *prefix)
|
||||
struct shader_var *var, bool input,
|
||||
const char *prefix)
|
||||
{
|
||||
struct shader_struct *st = shader_parser_getstruct(&glsp->parser,
|
||||
var->type);
|
||||
struct shader_struct *st =
|
||||
shader_parser_getstruct(&glsp->parser, var->type);
|
||||
|
||||
if (st) {
|
||||
gl_unwrap_storage_struct(glsp, st, var->name, input, prefix);
|
||||
} else {
|
||||
if (input && (strcmp(var->mapping, "VERTEXID") == 0))
|
||||
return;
|
||||
if (strcmp(var->mapping, "POSITION") == 0) {
|
||||
if (!input && (glsp->type == GS_SHADER_VERTEX))
|
||||
return;
|
||||
if (input && (glsp->type == GS_SHADER_PIXEL))
|
||||
return;
|
||||
}
|
||||
|
||||
struct gl_parser_attrib attrib;
|
||||
gl_parser_attrib_init(&attrib);
|
||||
|
||||
|
|
@ -178,24 +191,24 @@ static void gl_write_storage_var(struct gl_shader_parser *glsp,
|
|||
dstr_cat_dstr(&glsp->gl_string, &attrib.name);
|
||||
dstr_cat(&glsp->gl_string, ";\n");
|
||||
|
||||
attrib.input = input;
|
||||
attrib.input = input;
|
||||
attrib.mapping = var->mapping;
|
||||
da_push_back(glsp->attribs, &attrib);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void gl_write_inputs(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main)
|
||||
struct shader_func *main)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < main->params.num; i++)
|
||||
gl_write_storage_var(glsp, main->params.array+i, true,
|
||||
"inputval_");
|
||||
gl_write_storage_var(glsp, main->params.array + i, true,
|
||||
"inputval_");
|
||||
dstr_cat(&glsp->gl_string, "\n");
|
||||
}
|
||||
|
||||
static void gl_write_outputs(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main)
|
||||
struct shader_func *main)
|
||||
{
|
||||
struct shader_var var = {0};
|
||||
var.type = main->return_type;
|
||||
|
|
@ -208,7 +221,7 @@ static void gl_write_outputs(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static void gl_write_struct(struct gl_shader_parser *glsp,
|
||||
struct shader_struct *st)
|
||||
struct shader_struct *st)
|
||||
{
|
||||
size_t i;
|
||||
dstr_cat(&glsp->gl_string, "struct ");
|
||||
|
|
@ -216,7 +229,7 @@ static void gl_write_struct(struct gl_shader_parser *glsp,
|
|||
dstr_cat(&glsp->gl_string, " {\n");
|
||||
|
||||
for (i = 0; i < st->vars.num; i++) {
|
||||
struct shader_var *var = st->vars.array+i;
|
||||
struct shader_var *var = st->vars.array + i;
|
||||
|
||||
dstr_cat(&glsp->gl_string, "\t");
|
||||
gl_write_var(glsp, var);
|
||||
|
|
@ -230,7 +243,7 @@ static void gl_write_interface_block(struct gl_shader_parser *glsp)
|
|||
{
|
||||
if (glsp->type == GS_SHADER_VERTEX) {
|
||||
dstr_cat(&glsp->gl_string, "out gl_PerVertex {\n"
|
||||
"\tvec4 gl_Position;\n};\n\n");
|
||||
"\tvec4 gl_Position;\n};\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +251,7 @@ static inline void gl_write_structs(struct gl_shader_parser *glsp)
|
|||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->parser.structs.num; i++) {
|
||||
struct shader_struct *st = glsp->parser.structs.array+i;
|
||||
struct shader_struct *st = glsp->parser.structs.array + i;
|
||||
gl_write_struct(glsp, st);
|
||||
}
|
||||
}
|
||||
|
|
@ -267,13 +280,15 @@ static inline void gl_write_structs(struct gl_shader_parser *glsp)
|
|||
*/
|
||||
|
||||
static bool gl_write_mul(struct gl_shader_parser *glsp,
|
||||
struct cf_token **p_token)
|
||||
struct cf_token **p_token)
|
||||
{
|
||||
struct cf_parser *cfp = &glsp->parser.cfp;
|
||||
cfp->cur_token = *p_token;
|
||||
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_token_is(cfp, "(")) return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
if (!cf_token_is(cfp, "("))
|
||||
return false;
|
||||
|
||||
dstr_cat(&glsp->gl_string, "(");
|
||||
gl_write_function_contents(glsp, &cfp->cur_token, ",");
|
||||
|
|
@ -287,13 +302,15 @@ static bool gl_write_mul(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static bool gl_write_saturate(struct gl_shader_parser *glsp,
|
||||
struct cf_token **p_token)
|
||||
struct cf_token **p_token)
|
||||
{
|
||||
struct cf_parser *cfp = &glsp->parser.cfp;
|
||||
cfp->cur_token = *p_token;
|
||||
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_token_is(cfp, "(")) return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
if (!cf_token_is(cfp, "("))
|
||||
return false;
|
||||
|
||||
dstr_cat(&glsp->gl_string, "clamp");
|
||||
gl_write_function_contents(glsp, &cfp->cur_token, ")");
|
||||
|
|
@ -304,23 +321,29 @@ static bool gl_write_saturate(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static inline bool gl_write_texture_call(struct gl_shader_parser *glsp,
|
||||
struct shader_var *var, const char *call, bool sampler)
|
||||
struct shader_var *var,
|
||||
const char *call, bool sampler)
|
||||
{
|
||||
struct cf_parser *cfp = &glsp->parser.cfp;
|
||||
size_t sampler_id = (size_t)-1;
|
||||
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_token_is(cfp, "(")) return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
if (!cf_token_is(cfp, "("))
|
||||
return false;
|
||||
|
||||
if (sampler) {
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
sampler_id = sp_getsampler(glsp, cfp->cur_token);
|
||||
if (sampler_id == (size_t) -1) return false;
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_token_is(cfp, ",")) return false;
|
||||
}
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
const size_t sampler_id = sp_getsampler(glsp, cfp->cur_token);
|
||||
if (sampler_id == (size_t)-1)
|
||||
return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
if (!cf_token_is(cfp, ","))
|
||||
return false;
|
||||
|
||||
var->gl_sampler_id = sampler_id;
|
||||
var->gl_sampler_id = sampler_id;
|
||||
}
|
||||
|
||||
dstr_cat(&glsp->gl_string, call);
|
||||
dstr_cat(&glsp->gl_string, "(");
|
||||
|
|
@ -331,15 +354,19 @@ static inline bool gl_write_texture_call(struct gl_shader_parser *glsp,
|
|||
|
||||
/* processes texture.Sample(sampler, texcoord) */
|
||||
static bool gl_write_texture_code(struct gl_shader_parser *glsp,
|
||||
struct cf_token **p_token, struct shader_var *var)
|
||||
struct cf_token **p_token,
|
||||
struct shader_var *var)
|
||||
{
|
||||
struct cf_parser *cfp = &glsp->parser.cfp;
|
||||
bool written = false;
|
||||
cfp->cur_token = *p_token;
|
||||
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_token_is(cfp, ".")) return false;
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
if (!cf_token_is(cfp, "."))
|
||||
return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
|
||||
const char *function_end = ")";
|
||||
|
||||
|
|
@ -360,7 +387,8 @@ static bool gl_write_texture_code(struct gl_shader_parser *glsp,
|
|||
if (!written)
|
||||
return false;
|
||||
|
||||
if (!cf_next_token(cfp)) return false;
|
||||
if (!cf_next_token(cfp))
|
||||
return false;
|
||||
|
||||
gl_write_function_contents(glsp, &cfp->cur_token, ")");
|
||||
dstr_cat(&glsp->gl_string, function_end);
|
||||
|
|
@ -370,7 +398,7 @@ static bool gl_write_texture_code(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static bool gl_write_intrinsic(struct gl_shader_parser *glsp,
|
||||
struct cf_token **p_token)
|
||||
struct cf_token **p_token)
|
||||
{
|
||||
struct cf_token *token = *p_token;
|
||||
bool written = true;
|
||||
|
|
@ -407,13 +435,13 @@ static bool gl_write_intrinsic(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static void gl_write_function_contents(struct gl_shader_parser *glsp,
|
||||
struct cf_token **p_token, const char *end)
|
||||
struct cf_token **p_token,
|
||||
const char *end)
|
||||
{
|
||||
struct cf_token *token = *p_token;
|
||||
|
||||
if (token->type != CFTOKEN_NAME
|
||||
|| ( !gl_write_type_token(glsp, token)
|
||||
&& !gl_write_intrinsic(glsp, &token)))
|
||||
if (token->type != CFTOKEN_NAME || (!gl_write_type_token(glsp, token) &&
|
||||
!gl_write_intrinsic(glsp, &token)))
|
||||
dstr_cat_strref(&glsp->gl_string, &token->str);
|
||||
|
||||
while (token->type != CFTOKEN_NONE) {
|
||||
|
|
@ -444,7 +472,7 @@ static void gl_write_function_contents(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static void gl_write_function(struct gl_shader_parser *glsp,
|
||||
struct shader_func *func)
|
||||
struct shader_func *func)
|
||||
{
|
||||
size_t i;
|
||||
struct cf_token *token;
|
||||
|
|
@ -460,7 +488,7 @@ static void gl_write_function(struct gl_shader_parser *glsp,
|
|||
dstr_cat(&glsp->gl_string, "(");
|
||||
|
||||
for (i = 0; i < func->params.num; i++) {
|
||||
struct shader_var *param = func->params.array+i;
|
||||
struct shader_var *param = func->params.array + i;
|
||||
|
||||
if (i > 0)
|
||||
dstr_cat(&glsp->gl_string, ", ");
|
||||
|
|
@ -478,14 +506,14 @@ static inline void gl_write_functions(struct gl_shader_parser *glsp)
|
|||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->parser.funcs.num; i++) {
|
||||
struct shader_func *func = glsp->parser.funcs.array+i;
|
||||
struct shader_func *func = glsp->parser.funcs.array + i;
|
||||
gl_write_function(glsp, func);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void gl_write_main_interface_assign(
|
||||
struct gl_shader_parser *glsp, struct shader_var *var,
|
||||
const char *src)
|
||||
static inline void gl_write_main_interface_assign(struct gl_shader_parser *glsp,
|
||||
struct shader_var *var,
|
||||
const char *src)
|
||||
{
|
||||
/* vertex shaders: write gl_Position */
|
||||
if (glsp->type == GS_SHADER_VERTEX &&
|
||||
|
|
@ -498,12 +526,13 @@ static inline void gl_write_main_interface_assign(
|
|||
}
|
||||
|
||||
static void gl_write_main_storage_assign(struct gl_shader_parser *glsp,
|
||||
struct shader_var *var, const char *dst, const char *src,
|
||||
bool input)
|
||||
struct shader_var *var,
|
||||
const char *dst, const char *src,
|
||||
bool input)
|
||||
{
|
||||
struct shader_struct *st;
|
||||
struct dstr dst_copy = {0};
|
||||
char ch_left = input ? '.' : '_';
|
||||
char ch_left = input ? '.' : '_';
|
||||
char ch_right = input ? '_' : '.';
|
||||
|
||||
if (dst) {
|
||||
|
|
@ -526,20 +555,31 @@ static void gl_write_main_storage_assign(struct gl_shader_parser *glsp,
|
|||
dstr_cat_ch(&src_copy, ch_right);
|
||||
|
||||
for (i = 0; i < st->vars.num; i++) {
|
||||
struct shader_var *st_var = st->vars.array+i;
|
||||
struct shader_var *st_var = st->vars.array + i;
|
||||
gl_write_main_storage_assign(glsp, st_var,
|
||||
dst_copy.array, src_copy.array, input);
|
||||
dst_copy.array,
|
||||
src_copy.array, input);
|
||||
}
|
||||
|
||||
dstr_free(&src_copy);
|
||||
} else {
|
||||
if (!dstr_is_empty(&dst_copy))
|
||||
dstr_cat_dstr(&glsp->gl_string, &dst_copy);
|
||||
dstr_cat(&glsp->gl_string, " = ");
|
||||
if (src)
|
||||
dstr_cat(&glsp->gl_string, src);
|
||||
dstr_cat(&glsp->gl_string, var->name);
|
||||
dstr_cat(&glsp->gl_string, ";\n");
|
||||
if (input || (glsp->type != GS_SHADER_VERTEX) ||
|
||||
(strcmp(var->mapping, "POSITION"))) {
|
||||
if (!dstr_is_empty(&dst_copy))
|
||||
dstr_cat_dstr(&glsp->gl_string, &dst_copy);
|
||||
dstr_cat(&glsp->gl_string, " = ");
|
||||
if (input && (strcmp(var->mapping, "VERTEXID") == 0))
|
||||
dstr_cat(&glsp->gl_string, "uint(gl_VertexID)");
|
||||
else if (input && (glsp->type == GS_SHADER_PIXEL) &&
|
||||
(strcmp(var->mapping, "POSITION") == 0))
|
||||
dstr_cat(&glsp->gl_string, "gl_FragCoord");
|
||||
else {
|
||||
if (src)
|
||||
dstr_cat(&glsp->gl_string, src);
|
||||
dstr_cat(&glsp->gl_string, var->name);
|
||||
}
|
||||
dstr_cat(&glsp->gl_string, ";\n");
|
||||
}
|
||||
|
||||
if (!input)
|
||||
gl_write_main_interface_assign(glsp, var, src);
|
||||
|
|
@ -549,28 +589,28 @@ static void gl_write_main_storage_assign(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static inline void gl_write_main_storage_inputs(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main)
|
||||
struct shader_func *main)
|
||||
{
|
||||
gl_write_main_storage_assign(glsp, main->params.array, NULL,
|
||||
"inputval_", true);
|
||||
"inputval_", true);
|
||||
}
|
||||
|
||||
static inline void gl_write_main_storage_outputs(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main)
|
||||
struct shader_func *main)
|
||||
{
|
||||
/* we only do this *if* we're writing a struct, because otherwise
|
||||
* the call to 'main' already does the assignment for us */
|
||||
if (!main->mapping) {
|
||||
struct shader_var var = {0};
|
||||
var.name = "outputval";
|
||||
var.type = (char*)main->return_type;
|
||||
var.type = main->return_type;
|
||||
dstr_cat(&glsp->gl_string, "\n");
|
||||
gl_write_main_storage_assign(glsp, &var, NULL, NULL, false);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void gl_write_main_vars(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main_func)
|
||||
struct shader_func *main_func)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < main_func->params.num; i++) {
|
||||
|
|
@ -589,7 +629,7 @@ static inline void gl_write_main_vars(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static inline void gl_write_main_func_call(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main_func)
|
||||
struct shader_func *main_func)
|
||||
{
|
||||
size_t i;
|
||||
dstr_cat(&glsp->gl_string, "\n\toutputval = _main_wrap(");
|
||||
|
|
@ -604,7 +644,7 @@ static inline void gl_write_main_func_call(struct gl_shader_parser *glsp,
|
|||
}
|
||||
|
||||
static void gl_write_main(struct gl_shader_parser *glsp,
|
||||
struct shader_func *main)
|
||||
struct shader_func *main)
|
||||
{
|
||||
dstr_cat(&glsp->gl_string, "void main(void)\n{\n");
|
||||
|
||||
|
|
@ -622,22 +662,22 @@ static void gl_rename_attributes(struct gl_shader_parser *glsp)
|
|||
size_t i = 0, input_idx = 0, output_idx = 0;
|
||||
|
||||
for (i = 0; i < glsp->attribs.num; i++) {
|
||||
struct gl_parser_attrib *attrib = glsp->attribs.array+i;
|
||||
struct gl_parser_attrib *attrib = glsp->attribs.array + i;
|
||||
struct dstr new_name = {0};
|
||||
const char *prefix;
|
||||
size_t val;
|
||||
|
||||
if (attrib->input) {
|
||||
prefix = glsp->input_prefix;
|
||||
val = input_idx++;
|
||||
val = input_idx++;
|
||||
} else {
|
||||
prefix = glsp->output_prefix;
|
||||
val = output_idx++;
|
||||
val = output_idx++;
|
||||
}
|
||||
|
||||
dstr_printf(&new_name, "%s%u", prefix, (unsigned int)val);
|
||||
dstr_replace(&glsp->gl_string, attrib->name.array,
|
||||
new_name.array);
|
||||
new_name.array);
|
||||
dstr_move(&attrib->name, &new_name);
|
||||
}
|
||||
}
|
||||
|
|
@ -653,6 +693,7 @@ static bool gl_shader_buildstring(struct gl_shader_parser *glsp)
|
|||
}
|
||||
|
||||
dstr_copy(&glsp->gl_string, "#version 150\n\n");
|
||||
dstr_cat(&glsp->gl_string, "const bool obs_glsl_compile = true;\n\n");
|
||||
gl_write_params(glsp);
|
||||
gl_write_inputs(glsp, main_func);
|
||||
gl_write_outputs(glsp, main_func);
|
||||
|
|
@ -665,8 +706,8 @@ static bool gl_shader_buildstring(struct gl_shader_parser *glsp)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool gl_shader_parse(struct gl_shader_parser *glsp,
|
||||
const char *shader_str, const char *file)
|
||||
bool gl_shader_parse(struct gl_shader_parser *glsp, const char *shader_str,
|
||||
const char *file)
|
||||
{
|
||||
bool success = shader_parse(&glsp->parser, shader_str, file);
|
||||
char *str = shader_parser_geterrors(&glsp->parser);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
|
||||
struct gl_parser_attrib {
|
||||
struct dstr name;
|
||||
const char *mapping;
|
||||
bool input;
|
||||
const char *mapping;
|
||||
bool input;
|
||||
};
|
||||
|
||||
static inline void gl_parser_attrib_init(struct gl_parser_attrib *attr)
|
||||
|
|
@ -43,26 +43,26 @@ static inline void gl_parser_attrib_free(struct gl_parser_attrib *attr)
|
|||
}
|
||||
|
||||
struct gl_shader_parser {
|
||||
enum gs_shader_type type;
|
||||
const char *input_prefix;
|
||||
const char *output_prefix;
|
||||
struct shader_parser parser;
|
||||
struct dstr gl_string;
|
||||
|
||||
DARRAY(uint32_t) texture_samplers;
|
||||
enum gs_shader_type type;
|
||||
const char *input_prefix;
|
||||
const char *output_prefix;
|
||||
struct shader_parser parser;
|
||||
struct dstr gl_string;
|
||||
|
||||
DARRAY(uint32_t) texture_samplers;
|
||||
DARRAY(struct gl_parser_attrib) attribs;
|
||||
};
|
||||
|
||||
static inline void gl_shader_parser_init(struct gl_shader_parser *glsp,
|
||||
enum gs_shader_type type)
|
||||
enum gs_shader_type type)
|
||||
{
|
||||
glsp->type = type;
|
||||
|
||||
if (type == GS_SHADER_VERTEX) {
|
||||
glsp->input_prefix = "_input_attrib";
|
||||
glsp->input_prefix = "_input_attrib";
|
||||
glsp->output_prefix = "_vertex_shader_attrib";
|
||||
} else if (type == GS_SHADER_PIXEL) {
|
||||
glsp->input_prefix = "_vertex_shader_attrib";
|
||||
glsp->input_prefix = "_vertex_shader_attrib";
|
||||
glsp->output_prefix = "_pixel_shader_attrib";
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ static inline void gl_shader_parser_free(struct gl_shader_parser *glsp)
|
|||
{
|
||||
size_t i;
|
||||
for (i = 0; i < glsp->attribs.num; i++)
|
||||
gl_parser_attrib_free(glsp->attribs.array+i);
|
||||
gl_parser_attrib_free(glsp->attribs.array + i);
|
||||
|
||||
da_free(glsp->attribs);
|
||||
da_free(glsp->texture_samplers);
|
||||
|
|
@ -85,4 +85,4 @@ static inline void gl_shader_parser_free(struct gl_shader_parser *glsp)
|
|||
}
|
||||
|
||||
extern bool gl_shader_parse(struct gl_shader_parser *glsp,
|
||||
const char *shader_str, const char *file);
|
||||
const char *shader_str, const char *file);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ static bool create_pixel_pack_buffer(struct gs_stage_surface *surf)
|
|||
if (!gl_bind_buffer(GL_PIXEL_PACK_BUFFER, surf->pack_buffer))
|
||||
return false;
|
||||
|
||||
size = surf->width * surf->bytes_per_pixel;
|
||||
size = (size+3) & 0xFFFFFFFC; /* align width to 4-byte boundary */
|
||||
size = surf->width * surf->bytes_per_pixel;
|
||||
size = (size + 3) & 0xFFFFFFFC; /* align width to 4-byte boundary */
|
||||
size *= surf->height;
|
||||
|
||||
glBufferData(GL_PIXEL_PACK_BUFFER, size, 0, GL_DYNAMIC_READ);
|
||||
|
|
@ -43,18 +43,19 @@ static bool create_pixel_pack_buffer(struct gs_stage_surface *surf)
|
|||
}
|
||||
|
||||
gs_stagesurf_t *device_stagesurface_create(gs_device_t *device, uint32_t width,
|
||||
uint32_t height, enum gs_color_format color_format)
|
||||
uint32_t height,
|
||||
enum gs_color_format color_format)
|
||||
{
|
||||
struct gs_stage_surface *surf;
|
||||
surf = bzalloc(sizeof(struct gs_stage_surface));
|
||||
surf->device = device;
|
||||
surf->format = color_format;
|
||||
surf->width = width;
|
||||
surf->height = height;
|
||||
surf->gl_format = convert_gs_format(color_format);
|
||||
surf->device = device;
|
||||
surf->format = color_format;
|
||||
surf->width = 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;
|
||||
surf->gl_type = get_gl_format_type(color_format);
|
||||
surf->bytes_per_pixel = gs_get_format_bpp(color_format) / 8;
|
||||
|
||||
if (!create_pixel_pack_buffer(surf)) {
|
||||
blog(LOG_ERROR, "device_stagesurface_create (GL) failed");
|
||||
|
|
@ -99,7 +100,7 @@ static bool can_stage(struct gs_stage_surface *dst, struct gs_texture_2d *src)
|
|||
|
||||
if (src->width != dst->width || src->height != dst->height) {
|
||||
blog(LOG_ERROR, "Source and destination must have the same "
|
||||
"dimensions");
|
||||
"dimensions");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -111,9 +112,9 @@ static bool can_stage(struct gs_stage_surface *dst, struct gs_texture_2d *src)
|
|||
/* Apparently for mac, PBOs won't do an asynchronous transfer unless you use
|
||||
* FBOs along with glReadPixels, which is really dumb. */
|
||||
void device_stage_texture(gs_device_t *device, gs_stagesurf_t *dst,
|
||||
gs_texture_t *src)
|
||||
gs_texture_t *src)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)src;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)src;
|
||||
struct fbo_info *fbo;
|
||||
GLint last_fbo;
|
||||
bool success = false;
|
||||
|
|
@ -132,12 +133,12 @@ void device_stage_texture(gs_device_t *device, gs_stagesurf_t *dst,
|
|||
goto failed_unbind_buffer;
|
||||
|
||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 0,
|
||||
src->gl_target, src->texture, 0);
|
||||
src->gl_target, src->texture, 0);
|
||||
if (!gl_success("glFrameBufferTexture2D"))
|
||||
goto failed_unbind_all;
|
||||
|
||||
glReadPixels(0, 0, dst->width, dst->height, dst->gl_format,
|
||||
dst->gl_type, 0);
|
||||
dst->gl_type, 0);
|
||||
if (!gl_success("glReadPixels"))
|
||||
goto failed_unbind_all;
|
||||
|
||||
|
|
@ -159,9 +160,9 @@ failed:
|
|||
#else
|
||||
|
||||
void device_stage_texture(gs_device_t *device, gs_stagesurf_t *dst,
|
||||
gs_texture_t *src)
|
||||
gs_texture_t *src)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)src;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)src;
|
||||
if (!can_stage(dst, tex2d))
|
||||
goto failed;
|
||||
|
||||
|
|
@ -198,14 +199,14 @@ uint32_t gs_stagesurface_get_height(const gs_stagesurf_t *stagesurf)
|
|||
return stagesurf->height;
|
||||
}
|
||||
|
||||
enum gs_color_format gs_stagesurface_get_color_format(
|
||||
const gs_stagesurf_t *stagesurf)
|
||||
enum gs_color_format
|
||||
gs_stagesurface_get_color_format(const gs_stagesurf_t *stagesurf)
|
||||
{
|
||||
return stagesurf->format;
|
||||
}
|
||||
|
||||
bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data,
|
||||
uint32_t *linesize)
|
||||
uint32_t *linesize)
|
||||
{
|
||||
if (!gl_bind_buffer(GL_PIXEL_PACK_BUFFER, stagesurf->pack_buffer))
|
||||
goto fail;
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
#ifdef _DEBUG
|
||||
|
||||
static void APIENTRY gl_debug_proc(
|
||||
GLenum source, GLenum type, GLuint id, GLenum severity,
|
||||
GLsizei length, const GLchar *message, const GLvoid *data )
|
||||
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);
|
||||
|
|
@ -45,58 +45,71 @@ static void APIENTRY gl_debug_proc(
|
|||
}
|
||||
#endif
|
||||
|
||||
switch(source) {
|
||||
switch (source) {
|
||||
case GL_DEBUG_SOURCE_API:
|
||||
source_str = "API"; break;
|
||||
source_str = "API";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
||||
source_str = "Window System"; break;
|
||||
source_str = "Window System";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
||||
source_str = "Shader Compiler"; break;
|
||||
source_str = "Shader Compiler";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
||||
source_str = "Third Party"; break;
|
||||
source_str = "Third Party";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_APPLICATION:
|
||||
source_str = "Application"; break;
|
||||
source_str = "Application";
|
||||
break;
|
||||
case GL_DEBUG_SOURCE_OTHER:
|
||||
source_str = "Other"; break;
|
||||
source_str = "Other";
|
||||
break;
|
||||
default:
|
||||
source_str = "Unknown";
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
type_str = "Error"; break;
|
||||
type_str = "Error";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
type_str = "Deprecated Behavior"; break;
|
||||
type_str = "Deprecated Behavior";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
type_str = "Undefined Behavior"; break;
|
||||
type_str = "Undefined Behavior";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
type_str = "Portability"; break;
|
||||
type_str = "Portability";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
type_str = "Performance"; break;
|
||||
type_str = "Performance";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_OTHER:
|
||||
type_str = "Other"; break;
|
||||
default:
|
||||
type_str = "Other";
|
||||
break;
|
||||
default:
|
||||
type_str = "Unknown";
|
||||
}
|
||||
|
||||
switch(severity) {
|
||||
switch (severity) {
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
severity_str = "High"; break;
|
||||
severity_str = "High";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
severity_str = "Medium"; break;
|
||||
severity_str = "Medium";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
severity_str = "Low"; break;
|
||||
severity_str = "Low";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
severity_str = "Notification"; break;
|
||||
severity_str = "Notification";
|
||||
break;
|
||||
default:
|
||||
severity_str = "Unknown";
|
||||
}
|
||||
|
||||
blog(LOG_DEBUG,
|
||||
"[%s][%s]{%s}: %.*s",
|
||||
source_str, type_str, severity_str,
|
||||
length, message
|
||||
);
|
||||
blog(LOG_DEBUG, "[%s][%s]{%s}: %.*s", source_str, type_str,
|
||||
severity_str, length, message);
|
||||
}
|
||||
|
||||
static void gl_enable_debug()
|
||||
|
|
@ -108,18 +121,18 @@ static void gl_enable_debug()
|
|||
glDebugMessageCallbackARB(gl_debug_proc, NULL);
|
||||
} else {
|
||||
blog(LOG_DEBUG, "Failed to set GL debug callback as it is "
|
||||
"not supported.");
|
||||
"not supported.");
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void gl_enable_debug() {}
|
||||
#endif
|
||||
|
||||
static bool gl_init_extensions(struct gs_device* device)
|
||||
static bool gl_init_extensions(struct gs_device *device)
|
||||
{
|
||||
if (!GLAD_GL_VERSION_2_1) {
|
||||
blog(LOG_ERROR, "obs-studio requires OpenGL version 2.1 or "
|
||||
"higher.");
|
||||
"higher.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +140,7 @@ static bool gl_init_extensions(struct gs_device* device)
|
|||
|
||||
if (!GLAD_GL_VERSION_3_0 && !GLAD_GL_ARB_framebuffer_object) {
|
||||
blog(LOG_ERROR, "OpenGL extension ARB_framebuffer_object "
|
||||
"is required.");
|
||||
"is required.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -158,14 +171,14 @@ static void clear_textures(struct gs_device *device)
|
|||
}
|
||||
|
||||
void convert_sampler_info(struct gs_sampler_state *sampler,
|
||||
const struct gs_sampler_info *info)
|
||||
const struct gs_sampler_info *info)
|
||||
{
|
||||
GLint max_anisotropy_max;
|
||||
convert_filter(info->filter, &sampler->min_filter,
|
||||
&sampler->mag_filter);
|
||||
sampler->address_u = convert_address_mode(info->address_u);
|
||||
sampler->address_v = convert_address_mode(info->address_v);
|
||||
sampler->address_w = convert_address_mode(info->address_w);
|
||||
&sampler->mag_filter);
|
||||
sampler->address_u = convert_address_mode(info->address_u);
|
||||
sampler->address_v = convert_address_mode(info->address_v);
|
||||
sampler->address_w = convert_address_mode(info->address_w);
|
||||
sampler->max_anisotropy = info->max_anisotropy;
|
||||
|
||||
max_anisotropy_max = 1;
|
||||
|
|
@ -181,10 +194,10 @@ void convert_sampler_info(struct gs_sampler_state *sampler,
|
|||
else if (sampler->max_anisotropy > max_anisotropy_max)
|
||||
sampler->max_anisotropy = max_anisotropy_max;
|
||||
|
||||
blog(LOG_DEBUG, "convert_sampler_info: 1 <= max_anisotropy <= "
|
||||
"%d violated, selected: %d, set: %d",
|
||||
max_anisotropy_max,
|
||||
info->max_anisotropy, sampler->max_anisotropy);
|
||||
blog(LOG_DEBUG,
|
||||
"convert_sampler_info: 1 <= max_anisotropy <= "
|
||||
"%d violated, selected: %d, set: %d",
|
||||
max_anisotropy_max, info->max_anisotropy, sampler->max_anisotropy);
|
||||
}
|
||||
|
||||
const char *device_get_name(void)
|
||||
|
|
@ -218,7 +231,7 @@ int device_create(gs_device_t **p_device, uint32_t adapter)
|
|||
const char *glRenderer = (const char *)glGetString(GL_RENDERER);
|
||||
|
||||
blog(LOG_INFO, "Loading up OpenGL on adapter %s %s", glVendor,
|
||||
glRenderer);
|
||||
glRenderer);
|
||||
|
||||
if (!gl_init_extensions(device)) {
|
||||
errorcode = GS_ERROR_NOT_SUPPORTED;
|
||||
|
|
@ -226,23 +239,26 @@ int device_create(gs_device_t **p_device, uint32_t adapter)
|
|||
}
|
||||
|
||||
const char *glVersion = (const char *)glGetString(GL_VERSION);
|
||||
const char *glShadingLanguage = (const char *)glGetString(
|
||||
GL_SHADING_LANGUAGE_VERSION);
|
||||
const char *glShadingLanguage =
|
||||
(const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
|
||||
blog(LOG_INFO, "OpenGL loaded successfully, version %s, shading "
|
||||
"language %s", glVersion, glShadingLanguage);
|
||||
blog(LOG_INFO,
|
||||
"OpenGL loaded successfully, version %s, shading "
|
||||
"language %s",
|
||||
glVersion, glShadingLanguage);
|
||||
|
||||
gl_enable(GL_CULL_FACE);
|
||||
|
||||
gl_gen_vertex_arrays(1, &device->empty_vao);
|
||||
|
||||
device_leave_context(device);
|
||||
device->cur_swap = NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
blog(LOG_INFO, "Warning: The OpenGL renderer is currently in use. "
|
||||
"On windows, the OpenGL renderer can decrease "
|
||||
"capture performance due to the lack of specific "
|
||||
"features used to maximize capture performance. "
|
||||
"The Direct3D 11 renderer is recommended instead.");
|
||||
"On windows, the OpenGL renderer can decrease "
|
||||
"capture performance due to the lack of specific "
|
||||
"features used to maximize capture performance. "
|
||||
"The Direct3D 11 renderer is recommended instead.");
|
||||
#endif
|
||||
|
||||
*p_device = device;
|
||||
|
|
@ -262,6 +278,8 @@ void device_destroy(gs_device_t *device)
|
|||
while (device->first_program)
|
||||
gs_program_destroy(device->first_program);
|
||||
|
||||
gl_delete_vertex_arrays(1, &device->empty_vao);
|
||||
|
||||
da_free(device->proj_stack);
|
||||
gl_platform_destroy(device->plat);
|
||||
bfree(device);
|
||||
|
|
@ -269,13 +287,13 @@ void device_destroy(gs_device_t *device)
|
|||
}
|
||||
|
||||
gs_swapchain_t *device_swapchain_create(gs_device_t *device,
|
||||
const struct gs_init_data *info)
|
||||
const struct gs_init_data *info)
|
||||
{
|
||||
struct gs_swap_chain *swap = bzalloc(sizeof(struct gs_swap_chain));
|
||||
|
||||
swap->device = device;
|
||||
swap->info = *info;
|
||||
swap->wi = gl_windowinfo_create(info);
|
||||
swap->info = *info;
|
||||
swap->wi = gl_windowinfo_create(info);
|
||||
if (!swap->wi) {
|
||||
blog(LOG_ERROR, "device_swapchain_create (GL) failed");
|
||||
gs_swapchain_destroy(swap);
|
||||
|
|
@ -337,9 +355,10 @@ uint32_t device_get_height(const gs_device_t *device)
|
|||
}
|
||||
|
||||
gs_texture_t *device_voltexture_create(gs_device_t *device, uint32_t width,
|
||||
uint32_t height, uint32_t depth,
|
||||
enum gs_color_format color_format, uint32_t levels,
|
||||
const uint8_t **data, uint32_t flags)
|
||||
uint32_t height, uint32_t depth,
|
||||
enum gs_color_format color_format,
|
||||
uint32_t levels, const uint8_t **data,
|
||||
uint32_t flags)
|
||||
{
|
||||
/* TODO */
|
||||
UNUSED_PARAMETER(device);
|
||||
|
|
@ -353,19 +372,45 @@ gs_texture_t *device_voltexture_create(gs_device_t *device, uint32_t width,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
gs_samplerstate_t *device_samplerstate_create(gs_device_t *device,
|
||||
const struct gs_sampler_info *info)
|
||||
gs_samplerstate_t *
|
||||
device_samplerstate_create(gs_device_t *device,
|
||||
const struct gs_sampler_info *info)
|
||||
{
|
||||
struct gs_sampler_state *sampler;
|
||||
|
||||
sampler = bzalloc(sizeof(struct gs_sampler_state));
|
||||
sampler->device = device;
|
||||
sampler->ref = 1;
|
||||
sampler->ref = 1;
|
||||
|
||||
convert_sampler_info(sampler, info);
|
||||
return sampler;
|
||||
}
|
||||
|
||||
gs_timer_t *device_timer_create(gs_device_t *device)
|
||||
{
|
||||
UNUSED_PARAMETER(device);
|
||||
|
||||
struct gs_timer *timer;
|
||||
|
||||
GLuint queries[2];
|
||||
glGenQueries(2, queries);
|
||||
if (!gl_success("glGenQueries"))
|
||||
return NULL;
|
||||
|
||||
timer = bzalloc(sizeof(struct gs_timer));
|
||||
timer->queries[0] = queries[0];
|
||||
timer->queries[1] = queries[1];
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
gs_timer_range_t *device_timer_range_create(gs_device_t *device)
|
||||
{
|
||||
UNUSED_PARAMETER(device);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum gs_texture_type device_get_texture_type(const gs_texture_t *texture)
|
||||
{
|
||||
return texture->type;
|
||||
|
|
@ -374,17 +419,17 @@ enum gs_texture_type device_get_texture_type(const gs_texture_t *texture)
|
|||
static void strip_mipmap_filter(GLint *filter)
|
||||
{
|
||||
switch (*filter) {
|
||||
case GL_NEAREST:
|
||||
case GL_LINEAR:
|
||||
return;
|
||||
case GL_NEAREST_MIPMAP_NEAREST:
|
||||
case GL_NEAREST_MIPMAP_LINEAR:
|
||||
*filter = GL_NEAREST;
|
||||
return;
|
||||
case GL_LINEAR_MIPMAP_NEAREST:
|
||||
case GL_LINEAR_MIPMAP_LINEAR:
|
||||
*filter = GL_LINEAR;
|
||||
return;
|
||||
case GL_NEAREST:
|
||||
case GL_LINEAR:
|
||||
return;
|
||||
case GL_NEAREST_MIPMAP_NEAREST:
|
||||
case GL_NEAREST_MIPMAP_LINEAR:
|
||||
*filter = GL_NEAREST;
|
||||
return;
|
||||
case GL_LINEAR_MIPMAP_NEAREST:
|
||||
case GL_LINEAR_MIPMAP_LINEAR:
|
||||
*filter = GL_LINEAR;
|
||||
return;
|
||||
}
|
||||
*filter = GL_NEAREST;
|
||||
}
|
||||
|
|
@ -401,7 +446,7 @@ static inline void apply_swizzle(struct gs_texture *tex)
|
|||
|
||||
static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss)
|
||||
{
|
||||
bool success = true;
|
||||
bool success = true;
|
||||
GLint min_filter;
|
||||
|
||||
if (tex->cur_sampler == ss)
|
||||
|
|
@ -419,11 +464,10 @@ static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss)
|
|||
if (gs_texture_is_rect(tex))
|
||||
strip_mipmap_filter(&min_filter);
|
||||
|
||||
if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MIN_FILTER,
|
||||
min_filter))
|
||||
if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MIN_FILTER, min_filter))
|
||||
success = false;
|
||||
if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAG_FILTER,
|
||||
ss->mag_filter))
|
||||
ss->mag_filter))
|
||||
success = false;
|
||||
if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_S, ss->address_u))
|
||||
success = false;
|
||||
|
|
@ -432,7 +476,7 @@ static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss)
|
|||
if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_R, ss->address_w))
|
||||
success = false;
|
||||
if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
||||
ss->max_anisotropy))
|
||||
ss->max_anisotropy))
|
||||
success = false;
|
||||
|
||||
apply_swizzle(tex);
|
||||
|
|
@ -441,13 +485,13 @@ static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss)
|
|||
}
|
||||
|
||||
static inline struct gs_shader_param *get_texture_param(gs_device_t *device,
|
||||
int unit)
|
||||
int unit)
|
||||
{
|
||||
struct gs_shader *shader = device->cur_pixel_shader;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < shader->params.num; i++) {
|
||||
struct gs_shader_param *param = shader->params.array+i;
|
||||
struct gs_shader_param *param = shader->params.array + i;
|
||||
if (param->type == GS_SHADER_PARAM_TEXTURE) {
|
||||
if (param->texture_id == unit)
|
||||
return param;
|
||||
|
|
@ -506,13 +550,13 @@ fail:
|
|||
}
|
||||
|
||||
static bool load_sampler_on_textures(gs_device_t *device, gs_samplerstate_t *ss,
|
||||
int sampler_unit)
|
||||
int sampler_unit)
|
||||
{
|
||||
struct gs_shader *shader = device->cur_pixel_shader;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < shader->params.num; i++) {
|
||||
struct gs_shader_param *param = shader->params.array+i;
|
||||
struct gs_shader_param *param = shader->params.array + i;
|
||||
|
||||
if (param->type == GS_SHADER_PARAM_TEXTURE &&
|
||||
param->sampler_id == (uint32_t)sampler_unit &&
|
||||
|
|
@ -528,7 +572,7 @@ static bool load_sampler_on_textures(gs_device_t *device, gs_samplerstate_t *ss,
|
|||
}
|
||||
|
||||
void device_load_samplerstate(gs_device_t *device, gs_samplerstate_t *ss,
|
||||
int unit)
|
||||
int unit)
|
||||
{
|
||||
/* need a pixel shader to properly bind samplers */
|
||||
if (!device->cur_pixel_shader)
|
||||
|
|
@ -563,7 +607,7 @@ void device_load_vertexshader(gs_device_t *device, gs_shader_t *vertshader)
|
|||
}
|
||||
|
||||
static void load_default_pixelshader_samplers(struct gs_device *device,
|
||||
struct gs_shader *ps)
|
||||
struct gs_shader *ps)
|
||||
{
|
||||
size_t i;
|
||||
if (!ps)
|
||||
|
|
@ -629,17 +673,17 @@ gs_zstencil_t *device_get_zstencil_target(const gs_device_t *device)
|
|||
}
|
||||
|
||||
static bool get_tex_dimensions(gs_texture_t *tex, uint32_t *width,
|
||||
uint32_t *height)
|
||||
uint32_t *height)
|
||||
{
|
||||
if (tex->type == GS_TEXTURE_2D) {
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
|
||||
*width = tex2d->width;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)tex;
|
||||
*width = tex2d->width;
|
||||
*height = tex2d->height;
|
||||
return true;
|
||||
|
||||
} else if (tex->type == GS_TEXTURE_CUBE) {
|
||||
struct gs_texture_cube *cube = (struct gs_texture_cube*)tex;
|
||||
*width = cube->size;
|
||||
struct gs_texture_cube *cube = (struct gs_texture_cube *)tex;
|
||||
*width = cube->size;
|
||||
*height = cube->size;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -654,9 +698,8 @@ static bool get_tex_dimensions(gs_texture_t *tex, uint32_t *width,
|
|||
*/
|
||||
struct fbo_info *get_fbo(gs_texture_t *tex, uint32_t width, uint32_t height)
|
||||
{
|
||||
if (tex->fbo && tex->fbo->width == width &&
|
||||
tex->fbo->height == height &&
|
||||
tex->fbo->format == tex->format)
|
||||
if (tex->fbo && tex->fbo->width == width &&
|
||||
tex->fbo->height == height && tex->fbo->format == tex->format)
|
||||
return tex->fbo;
|
||||
|
||||
GLuint fbo;
|
||||
|
|
@ -665,12 +708,12 @@ struct fbo_info *get_fbo(gs_texture_t *tex, uint32_t width, uint32_t height)
|
|||
return NULL;
|
||||
|
||||
tex->fbo = bmalloc(sizeof(struct fbo_info));
|
||||
tex->fbo->fbo = fbo;
|
||||
tex->fbo->width = width;
|
||||
tex->fbo->height = height;
|
||||
tex->fbo->format = tex->format;
|
||||
tex->fbo->cur_render_target = NULL;
|
||||
tex->fbo->cur_render_side = 0;
|
||||
tex->fbo->fbo = fbo;
|
||||
tex->fbo->width = width;
|
||||
tex->fbo->height = height;
|
||||
tex->fbo->format = tex->format;
|
||||
tex->fbo->cur_render_target = NULL;
|
||||
tex->fbo->cur_render_side = 0;
|
||||
tex->fbo->cur_zstencil_buffer = NULL;
|
||||
|
||||
return tex->fbo;
|
||||
|
|
@ -703,7 +746,7 @@ static bool set_current_fbo(gs_device_t *device, struct fbo_info *fbo)
|
|||
}
|
||||
|
||||
static bool attach_rendertarget(struct fbo_info *fbo, gs_texture_t *tex,
|
||||
int side)
|
||||
int side)
|
||||
{
|
||||
if (fbo->cur_render_target == tex)
|
||||
return true;
|
||||
|
|
@ -712,14 +755,14 @@ static bool attach_rendertarget(struct fbo_info *fbo, gs_texture_t *tex,
|
|||
|
||||
if (tex->type == GS_TEXTURE_2D) {
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
tex->texture, 0);
|
||||
GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||
tex->texture, 0);
|
||||
|
||||
} else if (tex->type == GS_TEXTURE_CUBE) {
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X + side,
|
||||
tex->texture, 0);
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X + side,
|
||||
tex->texture, 0);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -743,8 +786,8 @@ static bool attach_zstencil(struct fbo_info *fbo, gs_zstencil_t *zs)
|
|||
zs_attachment = zs->attachment;
|
||||
}
|
||||
|
||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER,
|
||||
zs_attachment, GL_RENDERBUFFER, zsbuffer);
|
||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, zs_attachment,
|
||||
GL_RENDERBUFFER, zsbuffer);
|
||||
if (!gl_success("glFramebufferRenderbuffer"))
|
||||
return false;
|
||||
|
||||
|
|
@ -752,17 +795,17 @@ static bool attach_zstencil(struct fbo_info *fbo, gs_zstencil_t *zs)
|
|||
}
|
||||
|
||||
static bool set_target(gs_device_t *device, gs_texture_t *tex, int side,
|
||||
gs_zstencil_t *zs)
|
||||
gs_zstencil_t *zs)
|
||||
{
|
||||
struct fbo_info *fbo;
|
||||
|
||||
if (device->cur_render_target == tex &&
|
||||
device->cur_zstencil_buffer == zs &&
|
||||
device->cur_render_side == side)
|
||||
if (device->cur_render_target == tex &&
|
||||
device->cur_zstencil_buffer == zs &&
|
||||
device->cur_render_side == side)
|
||||
return true;
|
||||
|
||||
device->cur_render_target = tex;
|
||||
device->cur_render_side = side;
|
||||
device->cur_render_target = tex;
|
||||
device->cur_render_side = side;
|
||||
device->cur_zstencil_buffer = zs;
|
||||
|
||||
if (!tex)
|
||||
|
|
@ -783,7 +826,7 @@ static bool set_target(gs_device_t *device, gs_texture_t *tex, int side,
|
|||
}
|
||||
|
||||
void device_set_render_target(gs_device_t *device, gs_texture_t *tex,
|
||||
gs_zstencil_t *zstencil)
|
||||
gs_zstencil_t *zstencil)
|
||||
{
|
||||
if (tex) {
|
||||
if (tex->type != GS_TEXTURE_2D) {
|
||||
|
|
@ -807,7 +850,7 @@ fail:
|
|||
}
|
||||
|
||||
void device_set_cube_render_target(gs_device_t *device, gs_texture_t *cubetex,
|
||||
int side, gs_zstencil_t *zstencil)
|
||||
int side, gs_zstencil_t *zstencil)
|
||||
{
|
||||
if (cubetex) {
|
||||
if (cubetex->type != GS_TEXTURE_CUBE) {
|
||||
|
|
@ -830,13 +873,13 @@ fail:
|
|||
blog(LOG_ERROR, "device_set_cube_render_target (GL) failed");
|
||||
}
|
||||
|
||||
void device_copy_texture_region(gs_device_t *device,
|
||||
gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y,
|
||||
gs_texture_t *src, uint32_t src_x, uint32_t src_y,
|
||||
uint32_t src_w, uint32_t src_h)
|
||||
void device_copy_texture_region(gs_device_t *device, gs_texture_t *dst,
|
||||
uint32_t dst_x, uint32_t dst_y,
|
||||
gs_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;
|
||||
struct gs_texture_2d *src2d = (struct gs_texture_2d *)src;
|
||||
struct gs_texture_2d *dst2d = (struct gs_texture_2d *)dst;
|
||||
|
||||
if (!src) {
|
||||
blog(LOG_ERROR, "Source texture is NULL");
|
||||
|
|
@ -850,7 +893,7 @@ void device_copy_texture_region(gs_device_t *device,
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -859,19 +902,19 @@ void device_copy_texture_region(gs_device_t *device,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
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);
|
||||
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");
|
||||
"enough to hold the source region");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!gl_copy_texture(device, dst, dst_x, dst_y, src, src_x, src_y, nw,
|
||||
nh))
|
||||
nh))
|
||||
goto fail;
|
||||
|
||||
return;
|
||||
|
|
@ -881,7 +924,7 @@ fail:
|
|||
}
|
||||
|
||||
void device_copy_texture(gs_device_t *device, gs_texture_t *dst,
|
||||
gs_texture_t *src)
|
||||
gs_texture_t *src)
|
||||
{
|
||||
device_copy_texture_region(device, dst, 0, 0, src, 0, 0, 0, 0);
|
||||
}
|
||||
|
|
@ -891,7 +934,7 @@ void device_begin_scene(gs_device_t *device)
|
|||
clear_textures(device);
|
||||
}
|
||||
|
||||
static inline bool can_render(const gs_device_t *device)
|
||||
static inline bool can_render(const gs_device_t *device, uint32_t num_verts)
|
||||
{
|
||||
if (!device->cur_vertex_shader) {
|
||||
blog(LOG_ERROR, "No vertex shader specified");
|
||||
|
|
@ -903,7 +946,7 @@ static inline bool can_render(const gs_device_t *device)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!device->cur_vertex_buffer) {
|
||||
if (!device->cur_vertex_buffer && (num_verts == 0)) {
|
||||
blog(LOG_ERROR, "No vertex buffer specified");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -950,7 +993,7 @@ static inline struct gs_program *find_program(const struct gs_device *device)
|
|||
|
||||
while (program) {
|
||||
if (program->vertex_shader == device->cur_vertex_shader &&
|
||||
program->pixel_shader == device->cur_pixel_shader)
|
||||
program->pixel_shader == device->cur_pixel_shader)
|
||||
return program;
|
||||
|
||||
program = program->next;
|
||||
|
|
@ -970,14 +1013,15 @@ static inline struct gs_program *get_shader_program(struct gs_device *device)
|
|||
}
|
||||
|
||||
void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode,
|
||||
uint32_t start_vert, uint32_t num_verts)
|
||||
uint32_t start_vert, uint32_t num_verts)
|
||||
{
|
||||
struct gs_vertex_buffer *vb = device->cur_vertex_buffer;
|
||||
struct gs_index_buffer *ib = device->cur_index_buffer;
|
||||
GLenum topology = convert_gs_topology(draw_mode);
|
||||
GLenum topology = convert_gs_topology(draw_mode);
|
||||
gs_effect_t *effect = gs_get_effect();
|
||||
struct gs_program *program;
|
||||
|
||||
if (!can_render(device))
|
||||
if (!can_render(device, num_verts))
|
||||
goto fail;
|
||||
|
||||
if (effect)
|
||||
|
|
@ -987,7 +1031,10 @@ void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode,
|
|||
if (!program)
|
||||
goto fail;
|
||||
|
||||
load_vb_buffers(program, device->cur_vertex_buffer, ib);
|
||||
if (vb)
|
||||
load_vb_buffers(program, vb, ib);
|
||||
else
|
||||
gl_bind_vertex_array(device->empty_vao);
|
||||
|
||||
if (program != device->cur_program && device->cur_program) {
|
||||
glUseProgram(0);
|
||||
|
|
@ -1010,7 +1057,7 @@ void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode,
|
|||
if (num_verts == 0)
|
||||
num_verts = (uint32_t)device->cur_index_buffer->num;
|
||||
glDrawElements(topology, num_verts, ib->gl_type,
|
||||
(const GLvoid*)(start_vert * ib->width));
|
||||
(const GLvoid *)(start_vert * ib->width));
|
||||
if (!gl_success("glDrawElements"))
|
||||
goto fail;
|
||||
|
||||
|
|
@ -1035,7 +1082,7 @@ void device_end_scene(gs_device_t *device)
|
|||
}
|
||||
|
||||
void device_clear(gs_device_t *device, uint32_t clear_flags,
|
||||
const struct vec4 *color, float depth, uint8_t stencil)
|
||||
const struct vec4 *color, float depth, uint8_t stencil)
|
||||
{
|
||||
GLbitfield gl_flags = 0;
|
||||
|
||||
|
|
@ -1136,8 +1183,8 @@ void device_enable_stencil_write(gs_device_t *device, bool enable)
|
|||
UNUSED_PARAMETER(device);
|
||||
}
|
||||
|
||||
void device_enable_color(gs_device_t *device, bool red, bool green,
|
||||
bool blue, bool alpha)
|
||||
void device_enable_color(gs_device_t *device, bool red, bool green, bool blue,
|
||||
bool alpha)
|
||||
{
|
||||
glColorMask(red, green, blue, alpha);
|
||||
|
||||
|
|
@ -1145,7 +1192,7 @@ void device_enable_color(gs_device_t *device, bool red, bool green,
|
|||
}
|
||||
|
||||
void device_blend_function(gs_device_t *device, enum gs_blend_type src,
|
||||
enum gs_blend_type dest)
|
||||
enum gs_blend_type dest)
|
||||
{
|
||||
GLenum gl_src = convert_gs_blend_type(src);
|
||||
GLenum gl_dst = convert_gs_blend_type(dest);
|
||||
|
|
@ -1158,8 +1205,10 @@ void device_blend_function(gs_device_t *device, enum gs_blend_type src,
|
|||
}
|
||||
|
||||
void device_blend_function_separate(gs_device_t *device,
|
||||
enum gs_blend_type src_c, enum gs_blend_type dest_c,
|
||||
enum gs_blend_type src_a, enum gs_blend_type dest_a)
|
||||
enum gs_blend_type src_c,
|
||||
enum gs_blend_type dest_c,
|
||||
enum gs_blend_type src_a,
|
||||
enum gs_blend_type dest_a)
|
||||
{
|
||||
GLenum gl_src_c = convert_gs_blend_type(src_c);
|
||||
GLenum gl_dst_c = convert_gs_blend_type(dest_c);
|
||||
|
|
@ -1185,7 +1234,7 @@ void device_depth_function(gs_device_t *device, enum gs_depth_test test)
|
|||
}
|
||||
|
||||
void device_stencil_function(gs_device_t *device, enum gs_stencil_side side,
|
||||
enum gs_depth_test test)
|
||||
enum gs_depth_test test)
|
||||
{
|
||||
GLenum gl_side = convert_gs_stencil_side(side);
|
||||
GLenum gl_test = convert_gs_depth_test(test);
|
||||
|
|
@ -1198,11 +1247,12 @@ void device_stencil_function(gs_device_t *device, enum gs_stencil_side side,
|
|||
}
|
||||
|
||||
void device_stencil_op(gs_device_t *device, enum gs_stencil_side side,
|
||||
enum gs_stencil_op_type fail, enum gs_stencil_op_type zfail,
|
||||
enum gs_stencil_op_type zpass)
|
||||
enum gs_stencil_op_type fail,
|
||||
enum gs_stencil_op_type zfail,
|
||||
enum gs_stencil_op_type zpass)
|
||||
{
|
||||
GLenum gl_side = convert_gs_stencil_side(side);
|
||||
GLenum gl_fail = convert_gs_stencil_op(fail);
|
||||
GLenum gl_side = convert_gs_stencil_side(side);
|
||||
GLenum gl_fail = convert_gs_stencil_op(fail);
|
||||
GLenum gl_zfail = convert_gs_stencil_op(zfail);
|
||||
GLenum gl_zpass = convert_gs_stencil_op(zpass);
|
||||
|
||||
|
|
@ -1225,7 +1275,7 @@ static inline uint32_t get_target_height(const struct gs_device *device)
|
|||
}
|
||||
|
||||
void device_set_viewport(gs_device_t *device, int x, int y, int width,
|
||||
int height)
|
||||
int height)
|
||||
{
|
||||
uint32_t base_height = 0;
|
||||
int gl_y = 0;
|
||||
|
|
@ -1245,8 +1295,8 @@ void device_set_viewport(gs_device_t *device, int x, int y, int width,
|
|||
if (!gl_success("glViewport"))
|
||||
blog(LOG_ERROR, "device_set_viewport (GL) failed");
|
||||
|
||||
device->cur_viewport.x = x;
|
||||
device->cur_viewport.y = y;
|
||||
device->cur_viewport.x = x;
|
||||
device->cur_viewport.y = y;
|
||||
device->cur_viewport.cx = width;
|
||||
device->cur_viewport.cy = height;
|
||||
}
|
||||
|
|
@ -1272,55 +1322,55 @@ void device_set_scissor_rect(gs_device_t *device, const struct gs_rect *rect)
|
|||
blog(LOG_ERROR, "device_set_scissor_rect (GL) failed");
|
||||
}
|
||||
|
||||
void device_ortho(gs_device_t *device, float left, float right,
|
||||
float top, float bottom, float near, float far)
|
||||
void device_ortho(gs_device_t *device, float left, float right, float top,
|
||||
float bottom, float near, float far)
|
||||
{
|
||||
struct matrix4 *dst = &device->cur_proj;
|
||||
|
||||
float rml = right-left;
|
||||
float bmt = bottom-top;
|
||||
float fmn = far-near;
|
||||
float rml = right - left;
|
||||
float bmt = bottom - top;
|
||||
float fmn = far - near;
|
||||
|
||||
vec4_zero(&dst->x);
|
||||
vec4_zero(&dst->y);
|
||||
vec4_zero(&dst->z);
|
||||
vec4_zero(&dst->t);
|
||||
|
||||
dst->x.x = 2.0f / rml;
|
||||
dst->t.x = (left+right) / -rml;
|
||||
dst->x.x = 2.0f / rml;
|
||||
dst->t.x = (left + right) / -rml;
|
||||
|
||||
dst->y.y = 2.0f / -bmt;
|
||||
dst->t.y = (bottom+top) / bmt;
|
||||
dst->y.y = 2.0f / -bmt;
|
||||
dst->t.y = (bottom + top) / bmt;
|
||||
|
||||
dst->z.z = -2.0f / fmn;
|
||||
dst->t.z = (far+near) / -fmn;
|
||||
dst->z.z = -2.0f / fmn;
|
||||
dst->t.z = (far + near) / -fmn;
|
||||
|
||||
dst->t.w = 1.0f;
|
||||
}
|
||||
|
||||
void device_frustum(gs_device_t *device, float left, float right,
|
||||
float top, float bottom, float near, float far)
|
||||
void device_frustum(gs_device_t *device, float left, float right, float top,
|
||||
float bottom, float near, float far)
|
||||
{
|
||||
struct matrix4 *dst = &device->cur_proj;
|
||||
|
||||
float rml = right-left;
|
||||
float tmb = top-bottom;
|
||||
float nmf = near-far;
|
||||
float nearx2 = 2.0f*near;
|
||||
float rml = right - left;
|
||||
float tmb = top - bottom;
|
||||
float nmf = near - far;
|
||||
float nearx2 = 2.0f * near;
|
||||
|
||||
vec4_zero(&dst->x);
|
||||
vec4_zero(&dst->y);
|
||||
vec4_zero(&dst->z);
|
||||
vec4_zero(&dst->t);
|
||||
|
||||
dst->x.x = nearx2 / rml;
|
||||
dst->z.x = (left+right) / rml;
|
||||
|
||||
dst->y.y = nearx2 / tmb;
|
||||
dst->z.y = (bottom+top) / tmb;
|
||||
dst->x.x = nearx2 / rml;
|
||||
dst->z.x = (left + right) / rml;
|
||||
|
||||
dst->z.z = (far+near) / nmf;
|
||||
dst->t.z = 2.0f * (near*far) / nmf;
|
||||
dst->y.y = nearx2 / tmb;
|
||||
dst->z.y = (bottom + top) / tmb;
|
||||
|
||||
dst->z.z = (far + near) / nmf;
|
||||
dst->t.z = 2.0f * (near * far) / nmf;
|
||||
|
||||
dst->z.w = -1.0f;
|
||||
}
|
||||
|
|
@ -1341,8 +1391,8 @@ void device_projection_pop(gs_device_t *device)
|
|||
da_pop_back(device->proj_stack);
|
||||
}
|
||||
|
||||
void device_debug_marker_begin(gs_device_t *device,
|
||||
const char *markername, const float color[4])
|
||||
void device_debug_marker_begin(gs_device_t *device, const char *markername,
|
||||
const float color[4])
|
||||
{
|
||||
UNUSED_PARAMETER(device);
|
||||
UNUSED_PARAMETER(color);
|
||||
|
|
@ -1413,8 +1463,72 @@ void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
|
|||
if (samplerstate->device)
|
||||
for (int i = 0; i < GS_MAX_TEXTURES; i++)
|
||||
if (samplerstate->device->cur_samplers[i] ==
|
||||
samplerstate)
|
||||
samplerstate)
|
||||
samplerstate->device->cur_samplers[i] = NULL;
|
||||
|
||||
samplerstate_release(samplerstate);
|
||||
}
|
||||
|
||||
void gs_timer_destroy(gs_timer_t *timer)
|
||||
{
|
||||
if (!timer)
|
||||
return;
|
||||
|
||||
glDeleteQueries(2, timer->queries);
|
||||
gl_success("glDeleteQueries");
|
||||
|
||||
bfree(timer);
|
||||
}
|
||||
|
||||
void gs_timer_begin(gs_timer_t *timer)
|
||||
{
|
||||
glQueryCounter(timer->queries[0], GL_TIMESTAMP);
|
||||
gl_success("glQueryCounter");
|
||||
}
|
||||
|
||||
void gs_timer_end(gs_timer_t *timer)
|
||||
{
|
||||
glQueryCounter(timer->queries[1], GL_TIMESTAMP);
|
||||
gl_success("glQueryCounter");
|
||||
}
|
||||
|
||||
bool gs_timer_get_data(gs_timer_t *timer, uint64_t *ticks)
|
||||
{
|
||||
GLint available = 0;
|
||||
glGetQueryObjectiv(timer->queries[1], GL_QUERY_RESULT_AVAILABLE,
|
||||
&available);
|
||||
|
||||
GLuint64 begin, end;
|
||||
glGetQueryObjectui64v(timer->queries[0], GL_QUERY_RESULT, &begin);
|
||||
gl_success("glGetQueryObjectui64v");
|
||||
glGetQueryObjectui64v(timer->queries[1], GL_QUERY_RESULT, &end);
|
||||
gl_success("glGetQueryObjectui64v");
|
||||
|
||||
*ticks = end - begin;
|
||||
return true;
|
||||
}
|
||||
|
||||
void gs_timer_range_destroy(gs_timer_range_t *range)
|
||||
{
|
||||
UNUSED_PARAMETER(range);
|
||||
}
|
||||
|
||||
void gs_timer_range_begin(gs_timer_range_t *range)
|
||||
{
|
||||
UNUSED_PARAMETER(range);
|
||||
}
|
||||
|
||||
void gs_timer_range_end(gs_timer_range_t *range)
|
||||
{
|
||||
UNUSED_PARAMETER(range);
|
||||
}
|
||||
|
||||
bool gs_timer_range_get_data(gs_timer_range_t *range, bool *disjoint,
|
||||
uint64_t *frequency)
|
||||
{
|
||||
UNUSED_PARAMETER(range);
|
||||
|
||||
*disjoint = false;
|
||||
*frequency = 1000000000;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,34 +30,49 @@
|
|||
struct gl_platform;
|
||||
struct gl_windowinfo;
|
||||
|
||||
enum copy_type {
|
||||
COPY_TYPE_ARB,
|
||||
COPY_TYPE_NV,
|
||||
COPY_TYPE_FBO_BLIT
|
||||
};
|
||||
enum copy_type { COPY_TYPE_ARB, COPY_TYPE_NV, COPY_TYPE_FBO_BLIT };
|
||||
|
||||
static inline GLenum convert_gs_format(enum gs_color_format format)
|
||||
{
|
||||
switch (format) {
|
||||
case GS_A8: return GL_RED;
|
||||
case GS_R8: return GL_RED;
|
||||
case GS_RGBA: return GL_RGBA;
|
||||
case GS_BGRX: return GL_BGRA;
|
||||
case GS_BGRA: return GL_BGRA;
|
||||
case GS_R10G10B10A2: return GL_RGBA;
|
||||
case GS_RGBA16: return GL_RGBA;
|
||||
case GS_R16: return GL_RED;
|
||||
case GS_RGBA16F: return GL_RGBA;
|
||||
case GS_RGBA32F: return GL_RGBA;
|
||||
case GS_RG16F: return GL_RG;
|
||||
case GS_RG32F: return GL_RG;
|
||||
case GS_R8G8: return GL_RG;
|
||||
case GS_R16F: return GL_RED;
|
||||
case GS_R32F: return GL_RED;
|
||||
case GS_DXT1: return GL_RGB;
|
||||
case GS_DXT3: return GL_RGBA;
|
||||
case GS_DXT5: return GL_RGBA;
|
||||
case GS_UNKNOWN: return 0;
|
||||
case GS_A8:
|
||||
return GL_RED;
|
||||
case GS_R8:
|
||||
return GL_RED;
|
||||
case GS_RGBA:
|
||||
return GL_RGBA;
|
||||
case GS_BGRX:
|
||||
return GL_BGRA;
|
||||
case GS_BGRA:
|
||||
return GL_BGRA;
|
||||
case GS_R10G10B10A2:
|
||||
return GL_RGBA;
|
||||
case GS_RGBA16:
|
||||
return GL_RGBA;
|
||||
case GS_R16:
|
||||
return GL_RED;
|
||||
case GS_RGBA16F:
|
||||
return GL_RGBA;
|
||||
case GS_RGBA32F:
|
||||
return GL_RGBA;
|
||||
case GS_RG16F:
|
||||
return GL_RG;
|
||||
case GS_RG32F:
|
||||
return GL_RG;
|
||||
case GS_R8G8:
|
||||
return GL_RG;
|
||||
case GS_R16F:
|
||||
return GL_RED;
|
||||
case GS_R32F:
|
||||
return GL_RED;
|
||||
case GS_DXT1:
|
||||
return GL_RGB;
|
||||
case GS_DXT3:
|
||||
return GL_RGBA;
|
||||
case GS_DXT5:
|
||||
return GL_RGBA;
|
||||
case GS_UNKNOWN:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -66,25 +81,44 @@ static inline GLenum convert_gs_format(enum gs_color_format format)
|
|||
static inline GLenum convert_gs_internal_format(enum gs_color_format format)
|
||||
{
|
||||
switch (format) {
|
||||
case GS_A8: return GL_R8; /* NOTE: use GL_TEXTURE_SWIZZLE_x */
|
||||
case GS_R8: return GL_R8;
|
||||
case GS_RGBA: return GL_RGBA;
|
||||
case GS_BGRX: return GL_RGB;
|
||||
case GS_BGRA: return GL_RGBA;
|
||||
case GS_R10G10B10A2: return GL_RGB10_A2;
|
||||
case GS_RGBA16: return GL_RGBA16;
|
||||
case GS_R16: return GL_R16;
|
||||
case GS_RGBA16F: return GL_RGBA16F;
|
||||
case GS_RGBA32F: return GL_RGBA32F;
|
||||
case GS_RG16F: return GL_RG16F;
|
||||
case GS_RG32F: return GL_RG32F;
|
||||
case GS_R8G8: return GL_R16;
|
||||
case GS_R16F: return GL_R16F;
|
||||
case GS_R32F: return GL_R32F;
|
||||
case GS_DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case GS_DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case GS_DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case GS_UNKNOWN: return 0;
|
||||
case GS_A8:
|
||||
return GL_R8; /* NOTE: use GL_TEXTURE_SWIZZLE_x */
|
||||
case GS_R8:
|
||||
return GL_R8;
|
||||
case GS_RGBA:
|
||||
return GL_RGBA;
|
||||
case GS_BGRX:
|
||||
return GL_RGB;
|
||||
case GS_BGRA:
|
||||
return GL_RGBA;
|
||||
case GS_R10G10B10A2:
|
||||
return GL_RGB10_A2;
|
||||
case GS_RGBA16:
|
||||
return GL_RGBA16;
|
||||
case GS_R16:
|
||||
return GL_R16;
|
||||
case GS_RGBA16F:
|
||||
return GL_RGBA16F;
|
||||
case GS_RGBA32F:
|
||||
return GL_RGBA32F;
|
||||
case GS_RG16F:
|
||||
return GL_RG16F;
|
||||
case GS_RG32F:
|
||||
return GL_RG32F;
|
||||
case GS_R8G8:
|
||||
return GL_RG8;
|
||||
case GS_R16F:
|
||||
return GL_R16F;
|
||||
case GS_R32F:
|
||||
return GL_R32F;
|
||||
case GS_DXT1:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case GS_DXT3:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case GS_DXT5:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case GS_UNKNOWN:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -93,25 +127,44 @@ static inline GLenum convert_gs_internal_format(enum gs_color_format format)
|
|||
static inline GLenum get_gl_format_type(enum gs_color_format format)
|
||||
{
|
||||
switch (format) {
|
||||
case GS_A8: return GL_UNSIGNED_BYTE;
|
||||
case GS_R8: return GL_UNSIGNED_BYTE;
|
||||
case GS_RGBA: return GL_UNSIGNED_BYTE;
|
||||
case GS_BGRX: return GL_UNSIGNED_BYTE;
|
||||
case GS_BGRA: return GL_UNSIGNED_BYTE;
|
||||
case GS_R10G10B10A2: return GL_UNSIGNED_INT_10_10_10_2;
|
||||
case GS_RGBA16: return GL_UNSIGNED_SHORT;
|
||||
case GS_R16: return GL_UNSIGNED_SHORT;
|
||||
case GS_RGBA16F: return GL_UNSIGNED_SHORT;
|
||||
case GS_RGBA32F: return GL_FLOAT;
|
||||
case GS_RG16F: return GL_UNSIGNED_SHORT;
|
||||
case GS_RG32F: return GL_FLOAT;
|
||||
case GS_R8G8: return GL_UNSIGNED_SHORT;
|
||||
case GS_R16F: return GL_UNSIGNED_SHORT;
|
||||
case GS_R32F: return GL_FLOAT;
|
||||
case GS_DXT1: return GL_UNSIGNED_BYTE;
|
||||
case GS_DXT3: return GL_UNSIGNED_BYTE;
|
||||
case GS_DXT5: return GL_UNSIGNED_BYTE;
|
||||
case GS_UNKNOWN: return 0;
|
||||
case GS_A8:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_R8:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_RGBA:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_BGRX:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_BGRA:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_R10G10B10A2:
|
||||
return GL_UNSIGNED_INT_10_10_10_2;
|
||||
case GS_RGBA16:
|
||||
return GL_UNSIGNED_SHORT;
|
||||
case GS_R16:
|
||||
return GL_UNSIGNED_SHORT;
|
||||
case GS_RGBA16F:
|
||||
return GL_UNSIGNED_SHORT;
|
||||
case GS_RGBA32F:
|
||||
return GL_FLOAT;
|
||||
case GS_RG16F:
|
||||
return GL_UNSIGNED_SHORT;
|
||||
case GS_RG32F:
|
||||
return GL_FLOAT;
|
||||
case GS_R8G8:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_R16F:
|
||||
return GL_UNSIGNED_SHORT;
|
||||
case GS_R32F:
|
||||
return GL_FLOAT;
|
||||
case GS_DXT1:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_DXT3:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_DXT5:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case GS_UNKNOWN:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return GL_UNSIGNED_BYTE;
|
||||
|
|
@ -120,11 +173,16 @@ static inline GLenum get_gl_format_type(enum gs_color_format format)
|
|||
static inline GLenum convert_zstencil_format(enum gs_zstencil_format format)
|
||||
{
|
||||
switch (format) {
|
||||
case GS_Z16: return GL_DEPTH_COMPONENT16;
|
||||
case GS_Z24_S8: return GL_DEPTH24_STENCIL8;
|
||||
case GS_Z32F: return GL_DEPTH_COMPONENT32F;
|
||||
case GS_Z32F_S8X24: return GL_DEPTH32F_STENCIL8;
|
||||
case GS_ZS_NONE: return 0;
|
||||
case GS_Z16:
|
||||
return GL_DEPTH_COMPONENT16;
|
||||
case GS_Z24_S8:
|
||||
return GL_DEPTH24_STENCIL8;
|
||||
case GS_Z32F:
|
||||
return GL_DEPTH_COMPONENT32F;
|
||||
case GS_Z32F_S8X24:
|
||||
return GL_DEPTH32F_STENCIL8;
|
||||
case GS_ZS_NONE:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -133,14 +191,22 @@ static inline GLenum convert_zstencil_format(enum gs_zstencil_format format)
|
|||
static inline GLenum convert_gs_depth_test(enum gs_depth_test test)
|
||||
{
|
||||
switch (test) {
|
||||
case GS_NEVER: return GL_NEVER;
|
||||
case GS_LESS: return GL_LESS;
|
||||
case GS_LEQUAL: return GL_LEQUAL;
|
||||
case GS_EQUAL: return GL_EQUAL;
|
||||
case GS_GEQUAL: return GL_GEQUAL;
|
||||
case GS_GREATER: return GL_GREATER;
|
||||
case GS_NOTEQUAL: return GL_NOTEQUAL;
|
||||
case GS_ALWAYS: return GL_ALWAYS;
|
||||
case GS_NEVER:
|
||||
return GL_NEVER;
|
||||
case GS_LESS:
|
||||
return GL_LESS;
|
||||
case GS_LEQUAL:
|
||||
return GL_LEQUAL;
|
||||
case GS_EQUAL:
|
||||
return GL_EQUAL;
|
||||
case GS_GEQUAL:
|
||||
return GL_GEQUAL;
|
||||
case GS_GREATER:
|
||||
return GL_GREATER;
|
||||
case GS_NOTEQUAL:
|
||||
return GL_NOTEQUAL;
|
||||
case GS_ALWAYS:
|
||||
return GL_ALWAYS;
|
||||
}
|
||||
|
||||
return GL_NEVER;
|
||||
|
|
@ -149,12 +215,18 @@ static inline GLenum convert_gs_depth_test(enum gs_depth_test test)
|
|||
static inline GLenum convert_gs_stencil_op(enum gs_stencil_op_type op)
|
||||
{
|
||||
switch (op) {
|
||||
case GS_KEEP: return GL_KEEP;
|
||||
case GS_ZERO: return GL_ZERO;
|
||||
case GS_REPLACE: return GL_REPLACE;
|
||||
case GS_INCR: return GL_INCR;
|
||||
case GS_DECR: return GL_DECR;
|
||||
case GS_INVERT: return GL_INVERT;
|
||||
case GS_KEEP:
|
||||
return GL_KEEP;
|
||||
case GS_ZERO:
|
||||
return GL_ZERO;
|
||||
case GS_REPLACE:
|
||||
return GL_REPLACE;
|
||||
case GS_INCR:
|
||||
return GL_INCR;
|
||||
case GS_DECR:
|
||||
return GL_DECR;
|
||||
case GS_INVERT:
|
||||
return GL_INVERT;
|
||||
}
|
||||
|
||||
return GL_KEEP;
|
||||
|
|
@ -163,9 +235,12 @@ static inline GLenum convert_gs_stencil_op(enum gs_stencil_op_type op)
|
|||
static inline GLenum convert_gs_stencil_side(enum gs_stencil_side side)
|
||||
{
|
||||
switch (side) {
|
||||
case GS_STENCIL_FRONT: return GL_FRONT;
|
||||
case GS_STENCIL_BACK: return GL_BACK;
|
||||
case GS_STENCIL_BOTH: return GL_FRONT_AND_BACK;
|
||||
case GS_STENCIL_FRONT:
|
||||
return GL_FRONT;
|
||||
case GS_STENCIL_BACK:
|
||||
return GL_BACK;
|
||||
case GS_STENCIL_BOTH:
|
||||
return GL_FRONT_AND_BACK;
|
||||
}
|
||||
|
||||
return GL_FRONT;
|
||||
|
|
@ -174,17 +249,28 @@ static inline GLenum convert_gs_stencil_side(enum gs_stencil_side side)
|
|||
static inline GLenum convert_gs_blend_type(enum gs_blend_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case GS_BLEND_ZERO: return GL_ZERO;
|
||||
case GS_BLEND_ONE: return GL_ONE;
|
||||
case GS_BLEND_SRCCOLOR: return GL_SRC_COLOR;
|
||||
case GS_BLEND_INVSRCCOLOR: return GL_ONE_MINUS_SRC_COLOR;
|
||||
case GS_BLEND_SRCALPHA: return GL_SRC_ALPHA;
|
||||
case GS_BLEND_INVSRCALPHA: return GL_ONE_MINUS_SRC_ALPHA;
|
||||
case GS_BLEND_DSTCOLOR: return GL_DST_COLOR;
|
||||
case GS_BLEND_INVDSTCOLOR: return GL_ONE_MINUS_DST_COLOR;
|
||||
case GS_BLEND_DSTALPHA: return GL_DST_ALPHA;
|
||||
case GS_BLEND_INVDSTALPHA: return GL_ONE_MINUS_DST_ALPHA;
|
||||
case GS_BLEND_SRCALPHASAT: return GL_SRC_ALPHA_SATURATE;
|
||||
case GS_BLEND_ZERO:
|
||||
return GL_ZERO;
|
||||
case GS_BLEND_ONE:
|
||||
return GL_ONE;
|
||||
case GS_BLEND_SRCCOLOR:
|
||||
return GL_SRC_COLOR;
|
||||
case GS_BLEND_INVSRCCOLOR:
|
||||
return GL_ONE_MINUS_SRC_COLOR;
|
||||
case GS_BLEND_SRCALPHA:
|
||||
return GL_SRC_ALPHA;
|
||||
case GS_BLEND_INVSRCALPHA:
|
||||
return GL_ONE_MINUS_SRC_ALPHA;
|
||||
case GS_BLEND_DSTCOLOR:
|
||||
return GL_DST_COLOR;
|
||||
case GS_BLEND_INVDSTCOLOR:
|
||||
return GL_ONE_MINUS_DST_COLOR;
|
||||
case GS_BLEND_DSTALPHA:
|
||||
return GL_DST_ALPHA;
|
||||
case GS_BLEND_INVDSTALPHA:
|
||||
return GL_ONE_MINUS_DST_ALPHA;
|
||||
case GS_BLEND_SRCALPHASAT:
|
||||
return GL_SRC_ALPHA_SATURATE;
|
||||
}
|
||||
|
||||
return GL_ONE;
|
||||
|
|
@ -193,15 +279,17 @@ static inline GLenum convert_gs_blend_type(enum gs_blend_type type)
|
|||
static inline GLenum convert_shader_type(enum gs_shader_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case GS_SHADER_VERTEX: return GL_VERTEX_SHADER;
|
||||
case GS_SHADER_PIXEL: return GL_FRAGMENT_SHADER;
|
||||
case GS_SHADER_VERTEX:
|
||||
return GL_VERTEX_SHADER;
|
||||
case GS_SHADER_PIXEL:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
}
|
||||
|
||||
return GL_VERTEX_SHADER;
|
||||
}
|
||||
|
||||
static inline void convert_filter(enum gs_sample_filter filter,
|
||||
GLint *min_filter, GLint *mag_filter)
|
||||
GLint *min_filter, GLint *mag_filter)
|
||||
{
|
||||
switch (filter) {
|
||||
case GS_FILTER_POINT:
|
||||
|
|
@ -249,11 +337,16 @@ static inline void convert_filter(enum gs_sample_filter filter,
|
|||
static inline GLint convert_address_mode(enum gs_address_mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case GS_ADDRESS_WRAP: return GL_REPEAT;
|
||||
case GS_ADDRESS_CLAMP: return GL_CLAMP_TO_EDGE;
|
||||
case GS_ADDRESS_MIRROR: return GL_MIRRORED_REPEAT;
|
||||
case GS_ADDRESS_BORDER: return GL_CLAMP_TO_BORDER;
|
||||
case GS_ADDRESS_MIRRORONCE: return GL_MIRROR_CLAMP_EXT;
|
||||
case GS_ADDRESS_WRAP:
|
||||
return GL_REPEAT;
|
||||
case GS_ADDRESS_CLAMP:
|
||||
return GL_CLAMP_TO_EDGE;
|
||||
case GS_ADDRESS_MIRROR:
|
||||
return GL_MIRRORED_REPEAT;
|
||||
case GS_ADDRESS_BORDER:
|
||||
return GL_CLAMP_TO_BORDER;
|
||||
case GS_ADDRESS_MIRRORONCE:
|
||||
return GL_MIRROR_CLAMP_EXT;
|
||||
}
|
||||
|
||||
return GL_REPEAT;
|
||||
|
|
@ -262,29 +355,34 @@ static inline GLint convert_address_mode(enum gs_address_mode mode)
|
|||
static inline GLenum convert_gs_topology(enum gs_draw_mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case GS_POINTS: return GL_POINTS;
|
||||
case GS_LINES: return GL_LINES;
|
||||
case GS_LINESTRIP: return GL_LINE_STRIP;
|
||||
case GS_TRIS: return GL_TRIANGLES;
|
||||
case GS_TRISTRIP: return GL_TRIANGLE_STRIP;
|
||||
case GS_POINTS:
|
||||
return GL_POINTS;
|
||||
case GS_LINES:
|
||||
return GL_LINES;
|
||||
case GS_LINESTRIP:
|
||||
return GL_LINE_STRIP;
|
||||
case GS_TRIS:
|
||||
return GL_TRIANGLES;
|
||||
case GS_TRISTRIP:
|
||||
return GL_TRIANGLE_STRIP;
|
||||
}
|
||||
|
||||
return GL_POINTS;
|
||||
}
|
||||
|
||||
extern void convert_sampler_info(struct gs_sampler_state *sampler,
|
||||
const struct gs_sampler_info *info);
|
||||
const struct gs_sampler_info *info);
|
||||
|
||||
struct gs_sampler_state {
|
||||
gs_device_t *device;
|
||||
volatile long ref;
|
||||
gs_device_t *device;
|
||||
volatile long ref;
|
||||
|
||||
GLint min_filter;
|
||||
GLint mag_filter;
|
||||
GLint address_u;
|
||||
GLint address_v;
|
||||
GLint address_w;
|
||||
GLint max_anisotropy;
|
||||
GLint min_filter;
|
||||
GLint mag_filter;
|
||||
GLint address_u;
|
||||
GLint address_v;
|
||||
GLint address_w;
|
||||
GLint max_anisotropy;
|
||||
};
|
||||
|
||||
static inline void samplerstate_addref(gs_samplerstate_t *ss)
|
||||
|
|
@ -298,21 +396,25 @@ static inline void samplerstate_release(gs_samplerstate_t *ss)
|
|||
bfree(ss);
|
||||
}
|
||||
|
||||
struct gs_timer {
|
||||
GLuint queries[2];
|
||||
};
|
||||
|
||||
struct gs_shader_param {
|
||||
enum gs_shader_param_type type;
|
||||
|
||||
char *name;
|
||||
gs_shader_t *shader;
|
||||
gs_samplerstate_t *next_sampler;
|
||||
GLint texture_id;
|
||||
size_t sampler_id;
|
||||
int array_count;
|
||||
char *name;
|
||||
gs_shader_t *shader;
|
||||
gs_samplerstate_t *next_sampler;
|
||||
GLint texture_id;
|
||||
size_t sampler_id;
|
||||
int array_count;
|
||||
|
||||
struct gs_texture *texture;
|
||||
struct gs_texture *texture;
|
||||
|
||||
DARRAY(uint8_t) cur_value;
|
||||
DARRAY(uint8_t) def_value;
|
||||
bool changed;
|
||||
DARRAY(uint8_t) cur_value;
|
||||
DARRAY(uint8_t) def_value;
|
||||
bool changed;
|
||||
};
|
||||
|
||||
enum attrib_type {
|
||||
|
|
@ -325,40 +427,40 @@ enum attrib_type {
|
|||
};
|
||||
|
||||
struct shader_attrib {
|
||||
char *name;
|
||||
size_t index;
|
||||
enum attrib_type type;
|
||||
char *name;
|
||||
size_t index;
|
||||
enum attrib_type type;
|
||||
};
|
||||
|
||||
struct gs_shader {
|
||||
gs_device_t *device;
|
||||
enum gs_shader_type type;
|
||||
GLuint obj;
|
||||
gs_device_t *device;
|
||||
enum gs_shader_type type;
|
||||
GLuint obj;
|
||||
|
||||
struct gs_shader_param *viewproj;
|
||||
struct gs_shader_param *world;
|
||||
struct gs_shader_param *viewproj;
|
||||
struct gs_shader_param *world;
|
||||
|
||||
DARRAY(struct shader_attrib) attribs;
|
||||
DARRAY(struct shader_attrib) attribs;
|
||||
DARRAY(struct gs_shader_param) params;
|
||||
DARRAY(gs_samplerstate_t*) samplers;
|
||||
DARRAY(gs_samplerstate_t *) samplers;
|
||||
};
|
||||
|
||||
struct program_param {
|
||||
GLint obj;
|
||||
GLint obj;
|
||||
struct gs_shader_param *param;
|
||||
};
|
||||
|
||||
struct gs_program {
|
||||
gs_device_t *device;
|
||||
GLuint obj;
|
||||
struct gs_shader *vertex_shader;
|
||||
struct gs_shader *pixel_shader;
|
||||
gs_device_t *device;
|
||||
GLuint obj;
|
||||
struct gs_shader *vertex_shader;
|
||||
struct gs_shader *pixel_shader;
|
||||
|
||||
DARRAY(struct program_param) params;
|
||||
DARRAY(GLint) attribs;
|
||||
DARRAY(GLint) attribs;
|
||||
|
||||
struct gs_program **prev_next;
|
||||
struct gs_program *next;
|
||||
struct gs_program **prev_next;
|
||||
struct gs_program *next;
|
||||
};
|
||||
|
||||
extern struct gs_program *gs_program_create(struct gs_device *device);
|
||||
|
|
@ -366,106 +468,107 @@ extern void gs_program_destroy(struct gs_program *program);
|
|||
extern void program_update_params(struct gs_program *shader);
|
||||
|
||||
struct gs_vertex_buffer {
|
||||
GLuint vao;
|
||||
GLuint vertex_buffer;
|
||||
GLuint normal_buffer;
|
||||
GLuint tangent_buffer;
|
||||
GLuint color_buffer;
|
||||
DARRAY(GLuint) uv_buffers;
|
||||
DARRAY(size_t) uv_sizes;
|
||||
GLuint vao;
|
||||
GLuint vertex_buffer;
|
||||
GLuint normal_buffer;
|
||||
GLuint tangent_buffer;
|
||||
GLuint color_buffer;
|
||||
DARRAY(GLuint) uv_buffers;
|
||||
DARRAY(size_t) uv_sizes;
|
||||
|
||||
gs_device_t *device;
|
||||
size_t num;
|
||||
bool dynamic;
|
||||
struct gs_vb_data *data;
|
||||
gs_device_t *device;
|
||||
size_t num;
|
||||
bool dynamic;
|
||||
struct gs_vb_data *data;
|
||||
};
|
||||
|
||||
extern bool load_vb_buffers(struct gs_program *program,
|
||||
struct gs_vertex_buffer *vb, struct gs_index_buffer *ib);
|
||||
struct gs_vertex_buffer *vb,
|
||||
struct gs_index_buffer *ib);
|
||||
|
||||
struct gs_index_buffer {
|
||||
GLuint buffer;
|
||||
enum gs_index_type type;
|
||||
GLuint gl_type;
|
||||
GLuint buffer;
|
||||
enum gs_index_type type;
|
||||
GLuint gl_type;
|
||||
|
||||
gs_device_t *device;
|
||||
void *data;
|
||||
size_t num;
|
||||
size_t width;
|
||||
size_t size;
|
||||
bool dynamic;
|
||||
gs_device_t *device;
|
||||
void *data;
|
||||
size_t num;
|
||||
size_t width;
|
||||
size_t size;
|
||||
bool dynamic;
|
||||
};
|
||||
|
||||
struct gs_texture {
|
||||
gs_device_t *device;
|
||||
gs_device_t *device;
|
||||
enum gs_texture_type type;
|
||||
enum gs_color_format format;
|
||||
GLenum gl_format;
|
||||
GLenum gl_target;
|
||||
GLenum gl_internal_format;
|
||||
GLenum gl_type;
|
||||
GLuint texture;
|
||||
uint32_t levels;
|
||||
bool is_dynamic;
|
||||
bool is_render_target;
|
||||
bool is_dummy;
|
||||
bool gen_mipmaps;
|
||||
GLenum gl_format;
|
||||
GLenum gl_target;
|
||||
GLenum gl_internal_format;
|
||||
GLenum gl_type;
|
||||
GLuint texture;
|
||||
uint32_t levels;
|
||||
bool is_dynamic;
|
||||
bool is_render_target;
|
||||
bool is_dummy;
|
||||
bool gen_mipmaps;
|
||||
|
||||
gs_samplerstate_t *cur_sampler;
|
||||
struct fbo_info *fbo;
|
||||
gs_samplerstate_t *cur_sampler;
|
||||
struct fbo_info *fbo;
|
||||
};
|
||||
|
||||
struct gs_texture_2d {
|
||||
struct gs_texture base;
|
||||
struct gs_texture base;
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
bool gen_mipmaps;
|
||||
GLuint unpack_buffer;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
bool gen_mipmaps;
|
||||
GLuint unpack_buffer;
|
||||
};
|
||||
|
||||
struct gs_texture_cube {
|
||||
struct gs_texture base;
|
||||
struct gs_texture base;
|
||||
|
||||
uint32_t size;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
struct gs_stage_surface {
|
||||
gs_device_t *device;
|
||||
gs_device_t *device;
|
||||
|
||||
enum gs_color_format format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
uint32_t bytes_per_pixel;
|
||||
GLenum gl_format;
|
||||
GLint gl_internal_format;
|
||||
GLenum gl_type;
|
||||
GLuint pack_buffer;
|
||||
uint32_t bytes_per_pixel;
|
||||
GLenum gl_format;
|
||||
GLint gl_internal_format;
|
||||
GLenum gl_type;
|
||||
GLuint pack_buffer;
|
||||
};
|
||||
|
||||
struct gs_zstencil_buffer {
|
||||
gs_device_t *device;
|
||||
GLuint buffer;
|
||||
GLuint attachment;
|
||||
GLenum format;
|
||||
gs_device_t *device;
|
||||
GLuint buffer;
|
||||
GLuint attachment;
|
||||
GLenum format;
|
||||
};
|
||||
|
||||
struct gs_swap_chain {
|
||||
gs_device_t *device;
|
||||
gs_device_t *device;
|
||||
struct gl_windowinfo *wi;
|
||||
struct gs_init_data info;
|
||||
struct gs_init_data info;
|
||||
};
|
||||
|
||||
struct fbo_info {
|
||||
GLuint fbo;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
GLuint fbo;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
enum gs_color_format format;
|
||||
|
||||
gs_texture_t *cur_render_target;
|
||||
int cur_render_side;
|
||||
gs_zstencil_t *cur_zstencil_buffer;
|
||||
gs_texture_t *cur_render_target;
|
||||
int cur_render_side;
|
||||
gs_zstencil_t *cur_zstencil_buffer;
|
||||
};
|
||||
|
||||
static inline void fbo_info_destroy(struct fbo_info *fbo)
|
||||
|
|
@ -479,51 +582,52 @@ static inline void fbo_info_destroy(struct fbo_info *fbo)
|
|||
}
|
||||
|
||||
struct gs_device {
|
||||
struct gl_platform *plat;
|
||||
enum copy_type copy_type;
|
||||
struct gl_platform *plat;
|
||||
enum copy_type copy_type;
|
||||
|
||||
gs_texture_t *cur_render_target;
|
||||
gs_zstencil_t *cur_zstencil_buffer;
|
||||
int cur_render_side;
|
||||
gs_texture_t *cur_textures[GS_MAX_TEXTURES];
|
||||
gs_samplerstate_t *cur_samplers[GS_MAX_TEXTURES];
|
||||
gs_vertbuffer_t *cur_vertex_buffer;
|
||||
gs_indexbuffer_t *cur_index_buffer;
|
||||
gs_shader_t *cur_vertex_shader;
|
||||
gs_shader_t *cur_pixel_shader;
|
||||
gs_swapchain_t *cur_swap;
|
||||
struct gs_program *cur_program;
|
||||
GLuint empty_vao;
|
||||
|
||||
struct gs_program *first_program;
|
||||
gs_texture_t *cur_render_target;
|
||||
gs_zstencil_t *cur_zstencil_buffer;
|
||||
int cur_render_side;
|
||||
gs_texture_t *cur_textures[GS_MAX_TEXTURES];
|
||||
gs_samplerstate_t *cur_samplers[GS_MAX_TEXTURES];
|
||||
gs_vertbuffer_t *cur_vertex_buffer;
|
||||
gs_indexbuffer_t *cur_index_buffer;
|
||||
gs_shader_t *cur_vertex_shader;
|
||||
gs_shader_t *cur_pixel_shader;
|
||||
gs_swapchain_t *cur_swap;
|
||||
struct gs_program *cur_program;
|
||||
|
||||
enum gs_cull_mode cur_cull_mode;
|
||||
struct gs_rect cur_viewport;
|
||||
struct gs_program *first_program;
|
||||
|
||||
struct matrix4 cur_proj;
|
||||
struct matrix4 cur_view;
|
||||
struct matrix4 cur_viewproj;
|
||||
enum gs_cull_mode cur_cull_mode;
|
||||
struct gs_rect cur_viewport;
|
||||
|
||||
DARRAY(struct matrix4) proj_stack;
|
||||
struct matrix4 cur_proj;
|
||||
struct matrix4 cur_view;
|
||||
struct matrix4 cur_viewproj;
|
||||
|
||||
struct fbo_info *cur_fbo;
|
||||
DARRAY(struct matrix4) proj_stack;
|
||||
|
||||
struct fbo_info *cur_fbo;
|
||||
};
|
||||
|
||||
extern struct fbo_info *get_fbo(gs_texture_t *tex, uint32_t width,
|
||||
uint32_t height);
|
||||
uint32_t height);
|
||||
|
||||
extern void gl_update(gs_device_t *device);
|
||||
extern void gl_update(gs_device_t *device);
|
||||
|
||||
extern struct gl_platform *gl_platform_create(gs_device_t *device,
|
||||
uint32_t adapter);
|
||||
extern void gl_platform_destroy(struct gl_platform *platform);
|
||||
extern struct gl_platform *gl_platform_create(gs_device_t *device,
|
||||
uint32_t adapter);
|
||||
extern void gl_platform_destroy(struct gl_platform *platform);
|
||||
|
||||
extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap);
|
||||
extern void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap);
|
||||
|
||||
extern struct gl_windowinfo *gl_windowinfo_create(
|
||||
const struct gs_init_data *info);
|
||||
extern void gl_windowinfo_destroy(struct gl_windowinfo *wi);
|
||||
extern struct gl_windowinfo *
|
||||
gl_windowinfo_create(const struct gs_init_data *info);
|
||||
extern void gl_windowinfo_destroy(struct gl_windowinfo *wi);
|
||||
|
||||
extern void gl_getclientsize(const struct gs_swap_chain *swap,
|
||||
uint32_t *width,
|
||||
uint32_t *height);
|
||||
extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width,
|
||||
uint32_t *height);
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@
|
|||
|
||||
static bool upload_texture_2d(struct gs_texture_2d *tex, const uint8_t **data)
|
||||
{
|
||||
uint32_t row_size = tex->width * gs_get_format_bpp(tex->base.format);
|
||||
uint32_t tex_size = tex->height * row_size / 8;
|
||||
uint32_t row_size = tex->width * gs_get_format_bpp(tex->base.format);
|
||||
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);
|
||||
bool success;
|
||||
bool compressed = gs_is_compressed_format(tex->base.format);
|
||||
bool success;
|
||||
|
||||
if (!num_levels)
|
||||
num_levels = gs_get_total_levels(tex->width, tex->height);
|
||||
|
|
@ -32,10 +32,12 @@ static bool upload_texture_2d(struct gs_texture_2d *tex, const uint8_t **data)
|
|||
return false;
|
||||
|
||||
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);
|
||||
tex->base.gl_format,
|
||||
tex->base.gl_internal_format, compressed,
|
||||
tex->width, tex->height, tex_size, &data);
|
||||
|
||||
if (!gl_tex_param_i(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, num_levels-1))
|
||||
if (!gl_tex_param_i(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,
|
||||
num_levels - 1))
|
||||
success = false;
|
||||
if (!gl_bind_texture(GL_TEXTURE_2D, 0))
|
||||
success = false;
|
||||
|
|
@ -57,7 +59,7 @@ static bool create_pixel_unpack_buffer(struct gs_texture_2d *tex)
|
|||
size = tex->width * gs_get_format_bpp(tex->base.format);
|
||||
if (!gs_is_compressed_format(tex->base.format)) {
|
||||
size /= 8;
|
||||
size = (size+3) & 0xFFFFFFFC;
|
||||
size = (size + 3) & 0xFFFFFFFC;
|
||||
size *= tex->height;
|
||||
} else {
|
||||
size *= tex->height;
|
||||
|
|
@ -75,24 +77,26 @@ static bool create_pixel_unpack_buffer(struct gs_texture_2d *tex)
|
|||
}
|
||||
|
||||
gs_texture_t *device_texture_create(gs_device_t *device, uint32_t width,
|
||||
uint32_t height, enum gs_color_format color_format,
|
||||
uint32_t levels, const uint8_t **data, uint32_t flags)
|
||||
uint32_t height,
|
||||
enum gs_color_format color_format,
|
||||
uint32_t levels, const uint8_t **data,
|
||||
uint32_t flags)
|
||||
{
|
||||
struct gs_texture_2d *tex = bzalloc(sizeof(struct gs_texture_2d));
|
||||
tex->base.device = device;
|
||||
tex->base.type = GS_TEXTURE_2D;
|
||||
tex->base.format = color_format;
|
||||
tex->base.levels = levels;
|
||||
tex->base.gl_format = convert_gs_format(color_format);
|
||||
tex->base.device = device;
|
||||
tex->base.type = GS_TEXTURE_2D;
|
||||
tex->base.format = color_format;
|
||||
tex->base.levels = levels;
|
||||
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.gl_target = GL_TEXTURE_2D;
|
||||
tex->base.is_dynamic = (flags & GS_DYNAMIC) != 0;
|
||||
tex->base.is_render_target = (flags & GS_RENDER_TARGET) != 0;
|
||||
tex->base.is_dummy = (flags & GS_GL_DUMMYTEX) != 0;
|
||||
tex->base.gen_mipmaps = (flags & GS_BUILD_MIPMAPS) != 0;
|
||||
tex->width = width;
|
||||
tex->height = height;
|
||||
tex->base.gl_type = get_gl_format_type(color_format);
|
||||
tex->base.gl_target = GL_TEXTURE_2D;
|
||||
tex->base.is_dynamic = (flags & GS_DYNAMIC) != 0;
|
||||
tex->base.is_render_target = (flags & GS_RENDER_TARGET) != 0;
|
||||
tex->base.is_dummy = (flags & GS_GL_DUMMYTEX) != 0;
|
||||
tex->base.gen_mipmaps = (flags & GS_BUILD_MIPMAPS) != 0;
|
||||
tex->width = width;
|
||||
tex->height = height;
|
||||
|
||||
if (!gl_gen_textures(1, &tex->base.texture))
|
||||
goto fail;
|
||||
|
|
@ -102,12 +106,31 @@ gs_texture_t *device_texture_create(gs_device_t *device, uint32_t width,
|
|||
goto fail;
|
||||
if (!upload_texture_2d(tex, data))
|
||||
goto fail;
|
||||
} else {
|
||||
if (!gl_bind_texture(GL_TEXTURE_2D, tex->base.texture))
|
||||
goto fail;
|
||||
|
||||
uint32_t row_size =
|
||||
tex->width * gs_get_format_bpp(tex->base.format);
|
||||
uint32_t tex_size = tex->height * row_size / 8;
|
||||
bool compressed = gs_is_compressed_format(tex->base.format);
|
||||
bool did_init = gl_init_face(GL_TEXTURE_2D, tex->base.gl_type,
|
||||
1, tex->base.gl_format,
|
||||
tex->base.gl_internal_format,
|
||||
compressed, tex->width,
|
||||
tex->height, tex_size, NULL);
|
||||
did_init =
|
||||
gl_tex_param_i(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
|
||||
bool did_unbind = gl_bind_texture(GL_TEXTURE_2D, 0);
|
||||
if (!did_init || !did_unbind)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return (gs_texture_t*)tex;
|
||||
return (gs_texture_t *)tex;
|
||||
|
||||
fail:
|
||||
gs_texture_destroy((gs_texture_t*)tex);
|
||||
gs_texture_destroy((gs_texture_t *)tex);
|
||||
blog(LOG_ERROR, "device_texture_create (GL) failed");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -122,7 +145,7 @@ static inline bool is_texture_2d(const gs_texture_t *tex, const char *func)
|
|||
|
||||
void gs_texture_destroy(gs_texture_t *tex)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)tex;
|
||||
if (!tex)
|
||||
return;
|
||||
|
||||
|
|
@ -146,7 +169,7 @@ void gs_texture_destroy(gs_texture_t *tex)
|
|||
|
||||
uint32_t gs_texture_get_width(const gs_texture_t *tex)
|
||||
{
|
||||
const struct gs_texture_2d *tex2d = (const struct gs_texture_2d*)tex;
|
||||
const struct gs_texture_2d *tex2d = (const struct gs_texture_2d *)tex;
|
||||
if (!is_texture_2d(tex, "gs_texture_get_width"))
|
||||
return 0;
|
||||
|
||||
|
|
@ -155,7 +178,7 @@ uint32_t gs_texture_get_width(const gs_texture_t *tex)
|
|||
|
||||
uint32_t gs_texture_get_height(const gs_texture_t *tex)
|
||||
{
|
||||
const struct gs_texture_2d *tex2d = (const struct gs_texture_2d*)tex;
|
||||
const struct gs_texture_2d *tex2d = (const struct gs_texture_2d *)tex;
|
||||
if (!is_texture_2d(tex, "gs_texture_get_height"))
|
||||
return 0;
|
||||
|
||||
|
|
@ -169,7 +192,7 @@ enum gs_color_format gs_texture_get_color_format(const gs_texture_t *tex)
|
|||
|
||||
bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr, uint32_t *linesize)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)tex;
|
||||
|
||||
if (!is_texture_2d(tex, "gs_texture_map"))
|
||||
goto fail;
|
||||
|
|
@ -199,7 +222,7 @@ fail:
|
|||
|
||||
void gs_texture_unmap(gs_texture_t *tex)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)tex;
|
||||
if (!is_texture_2d(tex, "gs_texture_unmap"))
|
||||
goto failed;
|
||||
|
||||
|
|
@ -213,9 +236,8 @@ void gs_texture_unmap(gs_texture_t *tex)
|
|||
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);
|
||||
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;
|
||||
|
||||
|
|
@ -231,7 +253,7 @@ failed:
|
|||
|
||||
bool gs_texture_is_rect(const gs_texture_t *tex)
|
||||
{
|
||||
const struct gs_texture_2d *tex2d = (const struct gs_texture_2d*)tex;
|
||||
const struct gs_texture_2d *tex2d = (const struct gs_texture_2d *)tex;
|
||||
if (!is_texture_2d(tex, "gs_texture_unmap")) {
|
||||
blog(LOG_ERROR, "gs_texture_is_rect (GL) failed");
|
||||
return false;
|
||||
|
|
@ -242,7 +264,7 @@ bool gs_texture_is_rect(const gs_texture_t *tex)
|
|||
|
||||
void *gs_texture_get_obj(gs_texture_t *tex)
|
||||
{
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d*)tex;
|
||||
struct gs_texture_2d *tex2d = (struct gs_texture_2d *)tex;
|
||||
if (!is_texture_2d(tex, "gs_texture_unmap")) {
|
||||
blog(LOG_ERROR, "gs_texture_get_obj (GL) failed");
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@
|
|||
#include "gl-subsystem.h"
|
||||
|
||||
static inline bool upload_texture_cube(struct gs_texture_cube *tex,
|
||||
const uint8_t **data)
|
||||
const uint8_t **data)
|
||||
{
|
||||
uint32_t row_size = tex->size * gs_get_format_bpp(tex->base.format);
|
||||
uint32_t tex_size = tex->size * row_size / 8;
|
||||
uint32_t row_size = tex->size * gs_get_format_bpp(tex->base.format);
|
||||
uint32_t tex_size = tex->size * 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 = true;
|
||||
bool compressed = gs_is_compressed_format(tex->base.format);
|
||||
GLenum gl_type = get_gl_format_type(tex->base.format);
|
||||
bool success = true;
|
||||
uint32_t i;
|
||||
|
||||
if (!num_levels)
|
||||
|
|
@ -38,10 +38,9 @@ static inline bool upload_texture_cube(struct gs_texture_cube *tex,
|
|||
success = false;
|
||||
|
||||
if (!gl_init_face(target, gl_type, num_levels,
|
||||
tex->base.gl_format,
|
||||
tex->base.gl_internal_format,
|
||||
compressed, tex->size, tex->size,
|
||||
tex_size, &data))
|
||||
tex->base.gl_format,
|
||||
tex->base.gl_internal_format, compressed,
|
||||
tex->size, tex->size, tex_size, &data))
|
||||
success = false;
|
||||
|
||||
if (!gl_bind_texture(target, 0))
|
||||
|
|
@ -59,30 +58,31 @@ static inline bool upload_texture_cube(struct gs_texture_cube *tex,
|
|||
}
|
||||
|
||||
gs_texture_t *device_cubetexture_create(gs_device_t *device, uint32_t size,
|
||||
enum gs_color_format color_format, uint32_t levels,
|
||||
const uint8_t **data, uint32_t flags)
|
||||
enum gs_color_format color_format,
|
||||
uint32_t levels, const uint8_t **data,
|
||||
uint32_t flags)
|
||||
{
|
||||
struct gs_texture_cube *tex = bzalloc(sizeof(struct gs_texture_cube));
|
||||
tex->base.device = device;
|
||||
tex->base.type = GS_TEXTURE_CUBE;
|
||||
tex->base.format = color_format;
|
||||
tex->base.levels = levels;
|
||||
tex->base.gl_format = convert_gs_format(color_format);
|
||||
tex->base.device = device;
|
||||
tex->base.type = GS_TEXTURE_CUBE;
|
||||
tex->base.format = color_format;
|
||||
tex->base.levels = levels;
|
||||
tex->base.gl_format = convert_gs_format(color_format);
|
||||
tex->base.gl_internal_format = convert_gs_internal_format(color_format);
|
||||
tex->base.gl_target = GL_TEXTURE_CUBE_MAP;
|
||||
tex->base.is_render_target = (flags & GS_RENDER_TARGET) != 0;
|
||||
tex->base.gen_mipmaps = (flags & GS_BUILD_MIPMAPS) != 0;
|
||||
tex->size = size;
|
||||
tex->base.gl_target = GL_TEXTURE_CUBE_MAP;
|
||||
tex->base.is_render_target = (flags & GS_RENDER_TARGET) != 0;
|
||||
tex->base.gen_mipmaps = (flags & GS_BUILD_MIPMAPS) != 0;
|
||||
tex->size = size;
|
||||
|
||||
if (!gl_gen_textures(1, &tex->base.texture))
|
||||
goto fail;
|
||||
if (!upload_texture_cube(tex, data))
|
||||
goto fail;
|
||||
|
||||
return (gs_texture_t*)tex;
|
||||
return (gs_texture_t *)tex;
|
||||
|
||||
fail:
|
||||
gs_cubetexture_destroy((gs_texture_t*)tex);
|
||||
gs_cubetexture_destroy((gs_texture_t *)tex);
|
||||
blog(LOG_ERROR, "device_cubetexture_create (GL) failed");
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ static inline bool is_texture_cube(const gs_texture_t *tex, const char *func)
|
|||
uint32_t gs_cubetexture_get_size(const gs_texture_t *cubetex)
|
||||
{
|
||||
const struct gs_texture_cube *cube =
|
||||
(const struct gs_texture_cube*)cubetex;
|
||||
(const struct gs_texture_cube *)cubetex;
|
||||
|
||||
if (!is_texture_cube(cubetex, "gs_cubetexture_get_size"))
|
||||
return 0;
|
||||
|
|
@ -120,8 +120,8 @@ uint32_t gs_cubetexture_get_size(const gs_texture_t *cubetex)
|
|||
return cube->size;
|
||||
}
|
||||
|
||||
enum gs_color_format gs_cubetexture_get_color_format(
|
||||
const gs_texture_t *cubetex)
|
||||
enum gs_color_format
|
||||
gs_cubetexture_get_color_format(const gs_texture_t *cubetex)
|
||||
{
|
||||
return cubetex->format;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,45 +24,45 @@ static bool create_buffers(struct gs_vertex_buffer *vb)
|
|||
size_t i;
|
||||
|
||||
if (!gl_create_buffer(GL_ARRAY_BUFFER, &vb->vertex_buffer,
|
||||
vb->data->num * sizeof(struct vec3),
|
||||
vb->data->points, usage))
|
||||
vb->data->num * sizeof(struct vec3),
|
||||
vb->data->points, usage))
|
||||
return false;
|
||||
|
||||
if (vb->data->normals) {
|
||||
if (!gl_create_buffer(GL_ARRAY_BUFFER, &vb->normal_buffer,
|
||||
vb->data->num * sizeof(struct vec3),
|
||||
vb->data->normals, usage))
|
||||
vb->data->num * sizeof(struct vec3),
|
||||
vb->data->normals, usage))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vb->data->tangents) {
|
||||
if (!gl_create_buffer(GL_ARRAY_BUFFER, &vb->tangent_buffer,
|
||||
vb->data->num * sizeof(struct vec3),
|
||||
vb->data->tangents, usage))
|
||||
vb->data->num * sizeof(struct vec3),
|
||||
vb->data->tangents, usage))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vb->data->colors) {
|
||||
if (!gl_create_buffer(GL_ARRAY_BUFFER, &vb->color_buffer,
|
||||
vb->data->num * sizeof(uint32_t),
|
||||
vb->data->colors, usage))
|
||||
vb->data->num * sizeof(uint32_t),
|
||||
vb->data->colors, usage))
|
||||
return false;
|
||||
}
|
||||
|
||||
da_reserve(vb->uv_buffers, vb->data->num_tex);
|
||||
da_reserve(vb->uv_sizes, vb->data->num_tex);
|
||||
da_reserve(vb->uv_sizes, vb->data->num_tex);
|
||||
|
||||
for (i = 0; i < vb->data->num_tex; i++) {
|
||||
GLuint tex_buffer;
|
||||
struct gs_tvertarray *tv = vb->data->tvarray+i;
|
||||
struct gs_tvertarray *tv = vb->data->tvarray + i;
|
||||
size_t size = vb->data->num * sizeof(float) * tv->width;
|
||||
|
||||
if (!gl_create_buffer(GL_ARRAY_BUFFER, &tex_buffer, size,
|
||||
tv->array, usage))
|
||||
tv->array, usage))
|
||||
return false;
|
||||
|
||||
da_push_back(vb->uv_buffers, &tex_buffer);
|
||||
da_push_back(vb->uv_sizes, &tv->width);
|
||||
da_push_back(vb->uv_sizes, &tv->width);
|
||||
}
|
||||
|
||||
if (!vb->dynamic) {
|
||||
|
|
@ -77,12 +77,13 @@ static bool create_buffers(struct gs_vertex_buffer *vb)
|
|||
}
|
||||
|
||||
gs_vertbuffer_t *device_vertexbuffer_create(gs_device_t *device,
|
||||
struct gs_vb_data *data, uint32_t flags)
|
||||
struct gs_vb_data *data,
|
||||
uint32_t flags)
|
||||
{
|
||||
struct gs_vertex_buffer *vb = bzalloc(sizeof(struct gs_vertex_buffer));
|
||||
vb->device = device;
|
||||
vb->data = data;
|
||||
vb->num = data->num;
|
||||
vb->device = device;
|
||||
vb->data = data;
|
||||
vb->num = data->num;
|
||||
vb->dynamic = flags & GS_DYNAMIC;
|
||||
|
||||
if (!create_buffers(vb)) {
|
||||
|
|
@ -107,7 +108,7 @@ void gs_vertexbuffer_destroy(gs_vertbuffer_t *vb)
|
|||
gl_delete_buffers(1, &vb->color_buffer);
|
||||
if (vb->uv_buffers.num)
|
||||
gl_delete_buffers((GLsizei)vb->uv_buffers.num,
|
||||
vb->uv_buffers.array);
|
||||
vb->uv_buffers.array);
|
||||
|
||||
if (vb->vao)
|
||||
gl_delete_vertex_arrays(1, &vb->vao);
|
||||
|
|
@ -121,12 +122,11 @@ void gs_vertexbuffer_destroy(gs_vertbuffer_t *vb)
|
|||
}
|
||||
|
||||
static inline void gs_vertexbuffer_flush_internal(gs_vertbuffer_t *vb,
|
||||
const struct gs_vb_data *data)
|
||||
const struct gs_vb_data *data)
|
||||
{
|
||||
size_t i;
|
||||
size_t num_tex = data->num_tex < vb->data->num_tex
|
||||
? data->num_tex
|
||||
: vb->data->num_tex;
|
||||
size_t num_tex = data->num_tex < vb->data->num_tex ? data->num_tex
|
||||
: vb->data->num_tex;
|
||||
|
||||
if (!vb->dynamic) {
|
||||
blog(LOG_ERROR, "vertex buffer is not dynamic");
|
||||
|
|
@ -135,35 +135,34 @@ static inline void gs_vertexbuffer_flush_internal(gs_vertbuffer_t *vb,
|
|||
|
||||
if (data->points) {
|
||||
if (!update_buffer(GL_ARRAY_BUFFER, vb->vertex_buffer,
|
||||
data->points,
|
||||
data->num * sizeof(struct vec3)))
|
||||
data->points,
|
||||
data->num * sizeof(struct vec3)))
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (vb->normal_buffer && data->normals) {
|
||||
if (!update_buffer(GL_ARRAY_BUFFER, vb->normal_buffer,
|
||||
data->normals,
|
||||
data->num * sizeof(struct vec3)))
|
||||
data->normals,
|
||||
data->num * sizeof(struct vec3)))
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (vb->tangent_buffer && data->tangents) {
|
||||
if (!update_buffer(GL_ARRAY_BUFFER, vb->tangent_buffer,
|
||||
data->tangents,
|
||||
data->num * sizeof(struct vec3)))
|
||||
data->tangents,
|
||||
data->num * sizeof(struct vec3)))
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (vb->color_buffer && data->colors) {
|
||||
if (!update_buffer(GL_ARRAY_BUFFER, vb->color_buffer,
|
||||
data->colors,
|
||||
data->num * sizeof(uint32_t)))
|
||||
data->colors, data->num * sizeof(uint32_t)))
|
||||
goto failed;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_tex; i++) {
|
||||
GLuint buffer = vb->uv_buffers.array[i];
|
||||
struct gs_tvertarray *tv = data->tvarray+i;
|
||||
struct gs_tvertarray *tv = data->tvarray + i;
|
||||
size_t size = data->num * tv->width * sizeof(float);
|
||||
|
||||
if (!update_buffer(GL_ARRAY_BUFFER, buffer, tv->array, size))
|
||||
|
|
@ -182,7 +181,7 @@ void gs_vertexbuffer_flush(gs_vertbuffer_t *vb)
|
|||
}
|
||||
|
||||
void gs_vertexbuffer_flush_direct(gs_vertbuffer_t *vb,
|
||||
const struct gs_vb_data *data)
|
||||
const struct gs_vb_data *data)
|
||||
{
|
||||
gs_vertexbuffer_flush_internal(vb, data);
|
||||
}
|
||||
|
|
@ -193,11 +192,11 @@ struct gs_vb_data *gs_vertexbuffer_get_data(const gs_vertbuffer_t *vb)
|
|||
}
|
||||
|
||||
static inline GLuint get_vb_buffer(struct gs_vertex_buffer *vb,
|
||||
enum attrib_type type, size_t index, GLint *width,
|
||||
GLenum *gl_type)
|
||||
enum attrib_type type, size_t index,
|
||||
GLint *width, GLenum *gl_type)
|
||||
{
|
||||
*gl_type = GL_FLOAT;
|
||||
*width = 4;
|
||||
*width = 4;
|
||||
|
||||
if (type == ATTRIB_POSITION) {
|
||||
return vb->vertex_buffer;
|
||||
|
|
@ -220,7 +219,7 @@ static inline GLuint get_vb_buffer(struct gs_vertex_buffer *vb,
|
|||
}
|
||||
|
||||
static bool load_vb_buffer(struct shader_attrib *attrib,
|
||||
struct gs_vertex_buffer *vb, GLint id)
|
||||
struct gs_vertex_buffer *vb, GLint id)
|
||||
{
|
||||
GLenum type;
|
||||
GLint width;
|
||||
|
|
@ -230,7 +229,7 @@ static bool load_vb_buffer(struct shader_attrib *attrib,
|
|||
buffer = get_vb_buffer(vb, attrib->type, attrib->index, &width, &type);
|
||||
if (!buffer) {
|
||||
blog(LOG_ERROR, "Vertex buffer does not have the required "
|
||||
"inputs for vertex shader");
|
||||
"inputs for vertex shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +251,7 @@ static bool load_vb_buffer(struct shader_attrib *attrib,
|
|||
}
|
||||
|
||||
bool load_vb_buffers(struct gs_program *program, struct gs_vertex_buffer *vb,
|
||||
struct gs_index_buffer *ib)
|
||||
struct gs_index_buffer *ib)
|
||||
{
|
||||
struct gs_shader *shader = program->vertex_shader;
|
||||
size_t i;
|
||||
|
|
@ -261,7 +260,7 @@ bool load_vb_buffers(struct gs_program *program, struct gs_vertex_buffer *vb,
|
|||
return false;
|
||||
|
||||
for (i = 0; i < shader->attribs.num; i++) {
|
||||
struct shader_attrib *attrib = shader->attribs.array+i;
|
||||
struct shader_attrib *attrib = shader->attribs.array + i;
|
||||
if (!load_vb_buffer(attrib, vb, program->attribs.array[i]))
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
* super basic stuff */
|
||||
struct gl_windowinfo {
|
||||
HWND hwnd;
|
||||
HDC hdc;
|
||||
HDC hdc;
|
||||
};
|
||||
|
||||
/* Like the other subsystems, the GL subsystem has one swap chain created by
|
||||
|
|
@ -73,24 +73,24 @@ static inline int get_stencil_format_bits(enum gs_zstencil_format zsformat)
|
|||
static inline void init_dummy_pixel_format(PIXELFORMATDESCRIPTOR *pfd)
|
||||
{
|
||||
memset(pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd->nSize = sizeof(pfd);
|
||||
pfd->nVersion = 1;
|
||||
pfd->iPixelType = PFD_TYPE_RGBA;
|
||||
pfd->cColorBits = 32;
|
||||
pfd->cDepthBits = 24;
|
||||
pfd->nSize = sizeof(pfd);
|
||||
pfd->nVersion = 1;
|
||||
pfd->iPixelType = PFD_TYPE_RGBA;
|
||||
pfd->cColorBits = 32;
|
||||
pfd->cDepthBits = 24;
|
||||
pfd->cStencilBits = 8;
|
||||
pfd->iLayerType = PFD_MAIN_PLANE;
|
||||
pfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
|
||||
PFD_DOUBLEBUFFER;
|
||||
pfd->iLayerType = PFD_MAIN_PLANE;
|
||||
pfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
|
||||
PFD_DOUBLEBUFFER;
|
||||
}
|
||||
|
||||
static const char *dummy_window_class = "GLDummyWindow";
|
||||
static bool registered_dummy_window_class = false;
|
||||
|
||||
struct dummy_context {
|
||||
HWND hwnd;
|
||||
HWND hwnd;
|
||||
HGLRC hrc;
|
||||
HDC hdc;
|
||||
HDC hdc;
|
||||
};
|
||||
|
||||
/* Need a dummy window for the dummy context */
|
||||
|
|
@ -118,9 +118,8 @@ static bool gl_register_dummy_window_class(void)
|
|||
static inline HWND gl_create_dummy_window(void)
|
||||
{
|
||||
HWND hwnd = CreateWindowExA(0, dummy_window_class, "Dummy GL Window",
|
||||
WS_POPUP,
|
||||
0, 0, 2, 2,
|
||||
NULL, NULL, GetModuleHandle(NULL), NULL);
|
||||
WS_POPUP, 0, 0, 2, 2, NULL, NULL,
|
||||
GetModuleHandle(NULL), NULL);
|
||||
if (!hwnd)
|
||||
blog(LOG_ERROR, "Could not create dummy context window");
|
||||
|
||||
|
|
@ -131,8 +130,10 @@ static inline bool wgl_make_current(HDC hdc, HGLRC hglrc)
|
|||
{
|
||||
bool success = wglMakeCurrent(hdc, hglrc);
|
||||
if (!success)
|
||||
blog(LOG_ERROR, "wglMakeCurrent failed, GetLastError "
|
||||
"returned %lu", GetLastError());
|
||||
blog(LOG_ERROR,
|
||||
"wglMakeCurrent failed, GetLastError "
|
||||
"returned %lu",
|
||||
GetLastError());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
@ -153,14 +154,11 @@ static inline HGLRC gl_init_basic_context(HDC hdc)
|
|||
return hglrc;
|
||||
}
|
||||
|
||||
static const int attribs[] =
|
||||
{
|
||||
static const int attribs[] = {
|
||||
#ifdef _DEBUG
|
||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||
#endif
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
0, 0
|
||||
};
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0, 0};
|
||||
|
||||
static inline HGLRC gl_init_context(HDC hdc)
|
||||
{
|
||||
|
|
@ -168,8 +166,10 @@ static inline HGLRC gl_init_context(HDC hdc)
|
|||
if (GLAD_WGL_ARB_create_context) {
|
||||
HGLRC hglrc = wglCreateContextAttribsARB(hdc, 0, attribs);
|
||||
if (!hglrc) {
|
||||
blog(LOG_ERROR, "wglCreateContextAttribsARB failed, "
|
||||
"%lu", GetLastError());
|
||||
blog(LOG_ERROR,
|
||||
"wglCreateContextAttribsARB failed, "
|
||||
"%lu",
|
||||
GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -203,13 +203,13 @@ static bool gl_dummy_context_init(struct dummy_context *dummy)
|
|||
format_index = ChoosePixelFormat(dummy->hdc, &pfd);
|
||||
if (!format_index) {
|
||||
blog(LOG_ERROR, "Dummy ChoosePixelFormat failed, %lu",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SetPixelFormat(dummy->hdc, format_index, &pfd)) {
|
||||
blog(LOG_ERROR, "Dummy SetPixelFormat failed, %lu",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -270,8 +270,8 @@ static inline void add_attrib(struct darray *list, int attrib, int val)
|
|||
static int gl_choose_pixel_format(HDC hdc, const struct gs_init_data *info)
|
||||
{
|
||||
struct darray attribs;
|
||||
int color_bits = get_color_format_bits(info->format);
|
||||
int depth_bits = get_depth_format_bits(info->zsformat);
|
||||
int color_bits = get_color_format_bits(info->format);
|
||||
int depth_bits = get_depth_format_bits(info->zsformat);
|
||||
int stencil_bits = get_stencil_format_bits(info->zsformat);
|
||||
UINT num_formats;
|
||||
BOOL success;
|
||||
|
|
@ -279,26 +279,26 @@ static int gl_choose_pixel_format(HDC hdc, const struct gs_init_data *info)
|
|||
|
||||
if (!color_bits) {
|
||||
blog(LOG_ERROR, "gl_init_pixel_format: color format not "
|
||||
"supported");
|
||||
"supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
darray_init(&attribs);
|
||||
add_attrib(&attribs, WGL_DRAW_TO_WINDOW_ARB, GL_TRUE);
|
||||
add_attrib(&attribs, WGL_SUPPORT_OPENGL_ARB, GL_TRUE);
|
||||
add_attrib(&attribs, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB);
|
||||
add_attrib(&attribs, WGL_DOUBLE_BUFFER_ARB, GL_TRUE);
|
||||
add_attrib(&attribs, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB);
|
||||
add_attrib(&attribs, WGL_COLOR_BITS_ARB, color_bits);
|
||||
add_attrib(&attribs, WGL_DEPTH_BITS_ARB, depth_bits);
|
||||
add_attrib(&attribs, WGL_STENCIL_BITS_ARB, stencil_bits);
|
||||
add_attrib(&attribs, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB);
|
||||
add_attrib(&attribs, WGL_DOUBLE_BUFFER_ARB, GL_TRUE);
|
||||
add_attrib(&attribs, WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB);
|
||||
add_attrib(&attribs, WGL_COLOR_BITS_ARB, color_bits);
|
||||
add_attrib(&attribs, WGL_DEPTH_BITS_ARB, depth_bits);
|
||||
add_attrib(&attribs, WGL_STENCIL_BITS_ARB, stencil_bits);
|
||||
add_attrib(&attribs, 0, 0);
|
||||
|
||||
success = wglChoosePixelFormatARB(hdc, attribs.array, NULL, 1, &format,
|
||||
&num_formats);
|
||||
&num_formats);
|
||||
if (!success || !num_formats) {
|
||||
blog(LOG_ERROR, "wglChoosePixelFormatARB failed, %lu",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
format = 0;
|
||||
}
|
||||
|
||||
|
|
@ -308,7 +308,7 @@ static int gl_choose_pixel_format(HDC hdc, const struct gs_init_data *info)
|
|||
}
|
||||
|
||||
static inline bool gl_getpixelformat(HDC hdc, const struct gs_init_data *info,
|
||||
int *format, PIXELFORMATDESCRIPTOR *pfd)
|
||||
int *format, PIXELFORMATDESCRIPTOR *pfd)
|
||||
{
|
||||
if (!format)
|
||||
return false;
|
||||
|
|
@ -317,7 +317,7 @@ static inline bool gl_getpixelformat(HDC hdc, const struct gs_init_data *info,
|
|||
|
||||
if (!DescribePixelFormat(hdc, *format, sizeof(*pfd), pfd)) {
|
||||
blog(LOG_ERROR, "DescribePixelFormat failed, %lu",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -325,7 +325,7 @@ static inline bool gl_getpixelformat(HDC hdc, const struct gs_init_data *info,
|
|||
}
|
||||
|
||||
static inline bool gl_setpixelformat(HDC hdc, int format,
|
||||
PIXELFORMATDESCRIPTOR *pfd)
|
||||
PIXELFORMATDESCRIPTOR *pfd)
|
||||
{
|
||||
if (!SetPixelFormat(hdc, format, pfd)) {
|
||||
blog(LOG_ERROR, "SetPixelFormat failed, %lu", GetLastError());
|
||||
|
|
@ -339,7 +339,7 @@ static struct gl_windowinfo *gl_windowinfo_bare(const struct gs_init_data *info)
|
|||
{
|
||||
struct gl_windowinfo *wi = bzalloc(sizeof(struct gl_windowinfo));
|
||||
wi->hwnd = info->window.hwnd;
|
||||
wi->hdc = GetDC(wi->hwnd);
|
||||
wi->hdc = GetDC(wi->hwnd);
|
||||
|
||||
if (!wi->hdc) {
|
||||
blog(LOG_ERROR, "Unable to get device context from window");
|
||||
|
|
@ -356,10 +356,10 @@ static bool register_dummy_class(void)
|
|||
{
|
||||
static bool created = false;
|
||||
|
||||
WNDCLASSA wc = {0};
|
||||
wc.style = CS_OWNDC;
|
||||
wc.hInstance = GetModuleHandleW(NULL);
|
||||
wc.lpfnWndProc = (WNDPROC)DefWindowProcA;
|
||||
WNDCLASSA wc = {0};
|
||||
wc.style = CS_OWNDC;
|
||||
wc.hInstance = GetModuleHandleW(NULL);
|
||||
wc.lpfnWndProc = (WNDPROC)DefWindowProcA;
|
||||
wc.lpszClassName = DUMMY_WNDCLASS;
|
||||
|
||||
if (created)
|
||||
|
|
@ -367,7 +367,7 @@ static bool register_dummy_class(void)
|
|||
|
||||
if (!RegisterClassA(&wc)) {
|
||||
blog(LOG_ERROR, "Failed to register dummy GL window class, %lu",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -378,18 +378,19 @@ static bool register_dummy_class(void)
|
|||
static bool create_dummy_window(struct gl_platform *plat)
|
||||
{
|
||||
plat->window.hwnd = CreateWindowExA(0, DUMMY_WNDCLASS,
|
||||
"OpenGL Dummy Window", WS_POPUP, 0, 0, 1, 1,
|
||||
NULL, NULL, GetModuleHandleW(NULL), NULL);
|
||||
"OpenGL Dummy Window", WS_POPUP, 0,
|
||||
0, 1, 1, NULL, NULL,
|
||||
GetModuleHandleW(NULL), NULL);
|
||||
if (!plat->window.hwnd) {
|
||||
blog(LOG_ERROR, "Failed to create dummy GL window, %lu",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
plat->window.hdc = GetDC(plat->window.hwnd);
|
||||
if (!plat->window.hdc) {
|
||||
blog(LOG_ERROR, "Failed to get dummy GL window DC (%lu)",
|
||||
GetLastError());
|
||||
GetLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +398,7 @@ static bool create_dummy_window(struct gl_platform *plat)
|
|||
}
|
||||
|
||||
static bool init_default_swap(struct gl_platform *plat, gs_device_t *device,
|
||||
int pixel_format, PIXELFORMATDESCRIPTOR *pfd)
|
||||
int pixel_format, PIXELFORMATDESCRIPTOR *pfd)
|
||||
{
|
||||
if (!gl_setpixelformat(plat->window.hdc, pixel_format, pfd))
|
||||
return false;
|
||||
|
|
@ -541,6 +542,11 @@ void device_leave_context(gs_device_t *device)
|
|||
UNUSED_PARAMETER(device);
|
||||
}
|
||||
|
||||
void *device_get_device_obj(gs_device_t *device)
|
||||
{
|
||||
return device->plat->hrc;
|
||||
}
|
||||
|
||||
void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
|
||||
{
|
||||
HDC hdc = device->plat->window.hdc;
|
||||
|
|
@ -561,19 +567,21 @@ void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
|
|||
void device_present(gs_device_t *device)
|
||||
{
|
||||
if (!SwapBuffers(device->cur_swap->wi->hdc)) {
|
||||
blog(LOG_ERROR, "SwapBuffers failed, GetLastError "
|
||||
"returned %lu", GetLastError());
|
||||
blog(LOG_ERROR,
|
||||
"SwapBuffers failed, GetLastError "
|
||||
"returned %lu",
|
||||
GetLastError());
|
||||
blog(LOG_ERROR, "device_present (GL) failed");
|
||||
}
|
||||
}
|
||||
|
||||
extern void gl_getclientsize(const struct gs_swap_chain *swap,
|
||||
uint32_t *width, uint32_t *height)
|
||||
extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width,
|
||||
uint32_t *height)
|
||||
{
|
||||
RECT rc;
|
||||
if (swap) {
|
||||
GetClientRect(swap->wi->hwnd, &rc);
|
||||
*width = rc.right;
|
||||
*width = rc.right;
|
||||
*height = rc.bottom;
|
||||
} else {
|
||||
*width = 0;
|
||||
|
|
|
|||
|
|
@ -42,28 +42,34 @@
|
|||
|
||||
static const int ctx_attribs[] = {
|
||||
#ifdef _DEBUG
|
||||
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
|
||||
GLX_CONTEXT_FLAGS_ARB,
|
||||
GLX_CONTEXT_DEBUG_BIT_ARB,
|
||||
#endif
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2,
|
||||
GLX_CONTEXT_PROFILE_MASK_ARB,
|
||||
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB,
|
||||
3,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB,
|
||||
2,
|
||||
None,
|
||||
};
|
||||
|
||||
static int ctx_pbuffer_attribs[] = {
|
||||
GLX_PBUFFER_WIDTH, 2,
|
||||
GLX_PBUFFER_HEIGHT, 2,
|
||||
None
|
||||
};
|
||||
static int ctx_pbuffer_attribs[] = {GLX_PBUFFER_WIDTH, 2, GLX_PBUFFER_HEIGHT, 2,
|
||||
None};
|
||||
|
||||
static int ctx_visual_attribs[] = {
|
||||
GLX_STENCIL_SIZE, 0,
|
||||
GLX_DEPTH_SIZE, 0,
|
||||
GLX_BUFFER_SIZE, 32,
|
||||
GLX_ALPHA_SIZE, 8,
|
||||
GLX_DOUBLEBUFFER, true,
|
||||
GLX_X_RENDERABLE, true,
|
||||
None
|
||||
};
|
||||
static int ctx_visual_attribs[] = {GLX_STENCIL_SIZE,
|
||||
0,
|
||||
GLX_DEPTH_SIZE,
|
||||
0,
|
||||
GLX_BUFFER_SIZE,
|
||||
32,
|
||||
GLX_ALPHA_SIZE,
|
||||
8,
|
||||
GLX_DOUBLEBUFFER,
|
||||
true,
|
||||
GLX_X_RENDERABLE,
|
||||
true,
|
||||
None};
|
||||
|
||||
struct gl_windowinfo {
|
||||
/* We store this value since we can fetch a lot
|
||||
|
|
@ -91,17 +97,14 @@ struct gl_platform {
|
|||
|
||||
static void print_info_stuff(const struct gs_init_data *info)
|
||||
{
|
||||
blog( LOG_INFO,
|
||||
"X and Y: %i %i\n"
|
||||
"Backbuffers: %i\n"
|
||||
"Color Format: %i\n"
|
||||
"ZStencil Format: %i\n"
|
||||
"Adapter: %i\n",
|
||||
info->cx, info->cy,
|
||||
info->num_backbuffers,
|
||||
info->format, info->zsformat,
|
||||
info->adapter
|
||||
);
|
||||
blog(LOG_INFO,
|
||||
"X and Y: %i %i\n"
|
||||
"Backbuffers: %i\n"
|
||||
"Color Format: %i\n"
|
||||
"ZStencil Format: %i\n"
|
||||
"Adapter: %i\n",
|
||||
info->cx, info->cy, info->num_backbuffers, info->format,
|
||||
info->zsformat, info->adapter);
|
||||
}
|
||||
/* The following utility functions are copied verbatim from WGL code.
|
||||
* GLX and WGL are more similar than most people realize. */
|
||||
|
|
@ -150,7 +153,7 @@ static inline int get_stencil_format_bits(enum gs_zstencil_format zsformat)
|
|||
|
||||
/* Returns -1 on invalid screen. */
|
||||
static int get_screen_num_from_xcb_screen(xcb_connection_t *xcb_conn,
|
||||
xcb_screen_t *screen)
|
||||
xcb_screen_t *screen)
|
||||
{
|
||||
xcb_screen_iterator_t iter =
|
||||
xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
|
||||
|
|
@ -164,7 +167,7 @@ static int get_screen_num_from_xcb_screen(xcb_connection_t *xcb_conn,
|
|||
}
|
||||
|
||||
static xcb_screen_t *get_screen_from_root(xcb_connection_t *xcb_conn,
|
||||
xcb_window_t root)
|
||||
xcb_window_t root)
|
||||
{
|
||||
xcb_screen_iterator_t iter =
|
||||
xcb_setup_roots_iterator(xcb_get_setup(xcb_conn));
|
||||
|
|
@ -180,17 +183,18 @@ static xcb_screen_t *get_screen_from_root(xcb_connection_t *xcb_conn,
|
|||
}
|
||||
|
||||
static inline int get_screen_num_from_root(xcb_connection_t *xcb_conn,
|
||||
xcb_window_t root)
|
||||
xcb_window_t root)
|
||||
{
|
||||
xcb_screen_t *screen = get_screen_from_root(xcb_conn, root);
|
||||
|
||||
if (!screen) return -1;
|
||||
if (!screen)
|
||||
return -1;
|
||||
|
||||
return get_screen_num_from_xcb_screen(xcb_conn, screen);
|
||||
}
|
||||
|
||||
static xcb_get_geometry_reply_t* get_window_geometry(
|
||||
xcb_connection_t *xcb_conn, xcb_drawable_t drawable)
|
||||
static xcb_get_geometry_reply_t *get_window_geometry(xcb_connection_t *xcb_conn,
|
||||
xcb_drawable_t drawable)
|
||||
{
|
||||
xcb_get_geometry_cookie_t cookie;
|
||||
xcb_generic_error_t *error;
|
||||
|
|
@ -224,14 +228,14 @@ static bool gl_context_create(struct gl_platform *plat)
|
|||
}
|
||||
|
||||
config = glXChooseFBConfig(display, DefaultScreen(display),
|
||||
ctx_visual_attribs, &frame_buf_config_count);
|
||||
ctx_visual_attribs, &frame_buf_config_count);
|
||||
if (!config) {
|
||||
blog(LOG_ERROR, "Failed to create OpenGL frame buffer config");
|
||||
return false;
|
||||
}
|
||||
|
||||
context = glXCreateContextAttribsARB(display, config[0], NULL,
|
||||
true, ctx_attribs);
|
||||
context = glXCreateContextAttribsARB(display, config[0], NULL, true,
|
||||
ctx_attribs);
|
||||
if (!context) {
|
||||
blog(LOG_ERROR, "Failed to create OpenGL context.");
|
||||
goto error;
|
||||
|
|
@ -240,8 +244,8 @@ static bool gl_context_create(struct gl_platform *plat)
|
|||
plat->context = context;
|
||||
plat->display = display;
|
||||
|
||||
plat->pbuffer = glXCreatePbuffer(display, config[0],
|
||||
ctx_pbuffer_attribs);
|
||||
plat->pbuffer =
|
||||
glXCreatePbuffer(display, config[0], ctx_pbuffer_attribs);
|
||||
if (!plat->pbuffer) {
|
||||
blog(LOG_ERROR, "Failed to create OpenGL pbuffer");
|
||||
goto error;
|
||||
|
|
@ -264,7 +268,8 @@ static void gl_context_destroy(struct gl_platform *plat)
|
|||
bfree(plat);
|
||||
}
|
||||
|
||||
extern struct gl_windowinfo *gl_windowinfo_create(const struct gs_init_data *info)
|
||||
extern struct gl_windowinfo *
|
||||
gl_windowinfo_create(const struct gs_init_data *info)
|
||||
{
|
||||
UNUSED_PARAMETER(info);
|
||||
return bmalloc(sizeof(struct gl_windowinfo));
|
||||
|
|
@ -330,20 +335,21 @@ static int x_error_handler(Display *display, XErrorEvent *error)
|
|||
XGetErrorText(display, error->request_code, str2, sizeof(str2));
|
||||
XGetErrorText(display, error->minor_code, str3, sizeof(str3));
|
||||
|
||||
blog(LOG_ERROR, "X Error: %s, Major opcode: %s, "
|
||||
"Minor opcode: %s, Serial: %lu",
|
||||
str1, str2, str3, error->serial);
|
||||
blog(LOG_ERROR,
|
||||
"X Error: %s, Major opcode: %s, "
|
||||
"Minor opcode: %s, Serial: %lu",
|
||||
str1, str2, str3, error->serial);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern struct gl_platform *gl_platform_create(gs_device_t *device,
|
||||
uint32_t adapter)
|
||||
uint32_t adapter)
|
||||
{
|
||||
/* There's some trickery here... we're mixing libX11, xcb, and GLX
|
||||
For an explanation see here: http://xcb.freedesktop.org/MixingCalls/
|
||||
Essentially, GLX requires Xlib. Everything else we use xcb. */
|
||||
struct gl_platform * plat = bmalloc(sizeof(struct gl_platform));
|
||||
Display * display = open_windowless_display();
|
||||
struct gl_platform *plat = bmalloc(sizeof(struct gl_platform));
|
||||
Display *display = open_windowless_display();
|
||||
|
||||
if (!display) {
|
||||
goto fail_display_open;
|
||||
|
|
@ -363,7 +369,7 @@ extern struct gl_platform *gl_platform_create(gs_device_t *device,
|
|||
}
|
||||
|
||||
if (!glXMakeContextCurrent(plat->display, plat->pbuffer, plat->pbuffer,
|
||||
plat->context)) {
|
||||
plat->context)) {
|
||||
blog(LOG_ERROR, "Failed to make context current.");
|
||||
goto fail_make_current;
|
||||
}
|
||||
|
|
@ -410,7 +416,8 @@ extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
|
|||
int visual;
|
||||
GLXFBConfig *fb_config;
|
||||
|
||||
if (!geometry) goto fail_geometry_request;
|
||||
if (!geometry)
|
||||
goto fail_geometry_request;
|
||||
|
||||
screen_num = get_screen_num_from_root(xcb_conn, geometry->root);
|
||||
if (screen_num == -1) {
|
||||
|
|
@ -421,7 +428,7 @@ extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
|
|||
{
|
||||
int num_configs;
|
||||
fb_config = glXChooseFBConfig(display, screen_num,
|
||||
ctx_visual_attribs, &num_configs);
|
||||
ctx_visual_attribs, &num_configs);
|
||||
|
||||
if (!fb_config || !num_configs) {
|
||||
blog(LOG_ERROR, "Failed to find FBConfig!");
|
||||
|
|
@ -431,7 +438,8 @@ extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
|
|||
|
||||
/* ...then fetch matching visual info for xcb. */
|
||||
{
|
||||
int error = glXGetFBConfigAttrib(display, fb_config[0], GLX_VISUAL_ID, &visual);
|
||||
int error = glXGetFBConfigAttrib(display, fb_config[0],
|
||||
GLX_VISUAL_ID, &visual);
|
||||
|
||||
if (error) {
|
||||
blog(LOG_ERROR, "Bad call to GetFBConfigAttrib!");
|
||||
|
|
@ -439,27 +447,16 @@ extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
xcb_colormap_t colormap = xcb_generate_id(xcb_conn);
|
||||
uint32_t mask = XCB_CW_BORDER_PIXEL | XCB_CW_COLORMAP;
|
||||
uint32_t mask_values[] = { 0, colormap, 0 };
|
||||
uint32_t mask_values[] = {0, colormap, 0};
|
||||
|
||||
xcb_create_colormap(xcb_conn,
|
||||
XCB_COLORMAP_ALLOC_NONE,
|
||||
colormap,
|
||||
parent,
|
||||
visual
|
||||
);
|
||||
xcb_create_colormap(xcb_conn, XCB_COLORMAP_ALLOC_NONE, colormap, parent,
|
||||
visual);
|
||||
|
||||
xcb_create_window(
|
||||
xcb_conn, 24 /* Hardcoded? */,
|
||||
wid, parent,
|
||||
0, 0,
|
||||
geometry->width,
|
||||
geometry->height,
|
||||
0, 0,
|
||||
visual, mask, mask_values
|
||||
);
|
||||
xcb_create_window(xcb_conn, 24 /* Hardcoded? */, wid, parent, 0, 0,
|
||||
geometry->width, geometry->height, 0, 0, visual, mask,
|
||||
mask_values);
|
||||
|
||||
swap->wi->config = fb_config[0];
|
||||
swap->wi->window = wid;
|
||||
|
|
@ -513,15 +510,22 @@ extern void device_leave_context(gs_device_t *device)
|
|||
}
|
||||
}
|
||||
|
||||
extern void gl_getclientsize(const struct gs_swap_chain *swap,
|
||||
uint32_t *width, uint32_t *height)
|
||||
void *device_get_device_obj(gs_device_t *device)
|
||||
{
|
||||
xcb_connection_t *xcb_conn = XGetXCBConnection(swap->device->plat->display);
|
||||
return device->plat->context;
|
||||
}
|
||||
|
||||
extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width,
|
||||
uint32_t *height)
|
||||
{
|
||||
xcb_connection_t *xcb_conn =
|
||||
XGetXCBConnection(swap->device->plat->display);
|
||||
xcb_window_t window = swap->wi->window;
|
||||
|
||||
xcb_get_geometry_reply_t *geometry = get_window_geometry(xcb_conn, window);
|
||||
xcb_get_geometry_reply_t *geometry =
|
||||
get_window_geometry(xcb_conn, window);
|
||||
if (geometry) {
|
||||
*width = geometry->width;
|
||||
*width = geometry->width;
|
||||
*height = geometry->height;
|
||||
}
|
||||
|
||||
|
|
@ -533,16 +537,12 @@ extern void gl_update(gs_device_t *device)
|
|||
Display *display = device->plat->display;
|
||||
xcb_window_t window = device->cur_swap->wi->window;
|
||||
|
||||
uint32_t values[] = {
|
||||
device->cur_swap->info.cx,
|
||||
device->cur_swap->info.cy
|
||||
};
|
||||
uint32_t values[] = {device->cur_swap->info.cx,
|
||||
device->cur_swap->info.cy};
|
||||
|
||||
xcb_configure_window(
|
||||
XGetXCBConnection(display), window,
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
values
|
||||
);
|
||||
xcb_configure_window(XGetXCBConnection(display), window,
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
values);
|
||||
}
|
||||
|
||||
extern void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
|
||||
|
|
@ -596,15 +596,21 @@ extern void device_present(gs_device_t *device)
|
|||
|
||||
xcb_connection_t *xcb_conn = XGetXCBConnection(display);
|
||||
xcb_generic_event_t *xcb_event;
|
||||
while((xcb_event = xcb_poll_for_event(xcb_conn))) {
|
||||
while ((xcb_event = xcb_poll_for_event(xcb_conn))) {
|
||||
/* TODO: Handle XCB events. */
|
||||
free(xcb_event);
|
||||
}
|
||||
|
||||
switch (swap_type) {
|
||||
case SWAP_TYPE_EXT: glXSwapIntervalEXT(display, window, 0); break;
|
||||
case SWAP_TYPE_MESA: glXSwapIntervalMESA(0); break;
|
||||
case SWAP_TYPE_SGI: glXSwapIntervalSGI(0); break;
|
||||
case SWAP_TYPE_EXT:
|
||||
glXSwapIntervalEXT(display, window, 0);
|
||||
break;
|
||||
case SWAP_TYPE_MESA:
|
||||
glXSwapIntervalMESA(0);
|
||||
break;
|
||||
case SWAP_TYPE_SGI:
|
||||
glXSwapIntervalSGI(0);
|
||||
break;
|
||||
case SWAP_TYPE_NORMAL:;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#include "gl-subsystem.h"
|
||||
|
||||
static bool gl_init_zsbuffer(struct gs_zstencil_buffer *zs, uint32_t width,
|
||||
uint32_t height)
|
||||
uint32_t height)
|
||||
{
|
||||
glGenRenderbuffers(1, &zs->buffer);
|
||||
if (!gl_success("glGenRenderbuffers"))
|
||||
|
|
@ -38,25 +38,31 @@ static bool gl_init_zsbuffer(struct gs_zstencil_buffer *zs, uint32_t width,
|
|||
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;
|
||||
case GS_ZS_NONE: return 0;
|
||||
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;
|
||||
case GS_ZS_NONE:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
gs_zstencil_t *device_zstencil_create(gs_device_t *device, uint32_t width,
|
||||
uint32_t height, enum gs_zstencil_format format)
|
||||
uint32_t height,
|
||||
enum gs_zstencil_format format)
|
||||
{
|
||||
struct gs_zstencil_buffer *zs;
|
||||
|
||||
zs = bzalloc(sizeof(struct gs_zstencil_buffer));
|
||||
zs->format = convert_zstencil_format(format);
|
||||
zs->format = convert_zstencil_format(format);
|
||||
zs->attachment = get_attachment(format);
|
||||
zs->device = device;
|
||||
zs->device = device;
|
||||
|
||||
if (!gl_init_zsbuffer(zs, width, height)) {
|
||||
blog(LOG_ERROR, "device_zstencil_create (GL) failed");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue