2013-09-30 19:37:13 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 21:24:38 -08:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-09-30 19:37:13 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "../util/base.h"
|
|
|
|
#include "../util/bmem.h"
|
|
|
|
#include "../util/platform.h"
|
|
|
|
#include "graphics-internal.h"
|
|
|
|
#include "vec2.h"
|
|
|
|
#include "vec3.h"
|
|
|
|
#include "quat.h"
|
|
|
|
#include "axisang.h"
|
|
|
|
#include "effect-parser.h"
|
|
|
|
#include "effect.h"
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2014-09-25 17:44:05 -07:00
|
|
|
static __declspec(thread) graphics_t *thread_graphics = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
#else /* assume GCC or that other compiler we dare not mention */
|
2014-09-25 17:44:05 -07:00
|
|
|
static __thread graphics_t *thread_graphics = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
#endif
|
|
|
|
|
2013-10-01 06:16:40 -07:00
|
|
|
#define IMMEDIATE_COUNT 512
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-06-27 15:33:03 -07:00
|
|
|
extern void gs_init_image_deps(void);
|
|
|
|
extern void gs_free_image_deps(void);
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
bool load_graphics_imports(struct gs_exports *exports, void *module,
|
|
|
|
const char *module_name);
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
static bool graphics_init_immediate_vb(struct graphics_subsystem *graphics)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_vb_data *vbd;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
vbd = gs_vbdata_create();
|
2013-10-01 06:16:40 -07:00
|
|
|
vbd->num = IMMEDIATE_COUNT;
|
2013-10-01 07:24:59 -07:00
|
|
|
vbd->points = bmalloc(sizeof(struct vec3)*IMMEDIATE_COUNT);
|
|
|
|
vbd->normals = bmalloc(sizeof(struct vec3)*IMMEDIATE_COUNT);
|
|
|
|
vbd->colors = bmalloc(sizeof(uint32_t) *IMMEDIATE_COUNT);
|
2013-09-30 19:37:13 -07:00
|
|
|
vbd->num_tex = 1;
|
2014-08-07 23:42:07 -07:00
|
|
|
vbd->tvarray = bmalloc(sizeof(struct gs_tvertarray));
|
2013-09-30 19:37:13 -07:00
|
|
|
vbd->tvarray[0].width = 2;
|
|
|
|
vbd->tvarray[0].array =
|
2013-10-01 07:24:59 -07:00
|
|
|
bmalloc(sizeof(struct vec2) * IMMEDIATE_COUNT);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
graphics->immediate_vertbuffer = graphics->exports.
|
2014-08-07 23:42:07 -07:00
|
|
|
device_vertexbuffer_create(graphics->device, vbd, GS_DYNAMIC);
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!graphics->immediate_vertbuffer)
|
|
|
|
return false;
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool graphics_init_sprite_vb(struct graphics_subsystem *graphics)
|
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_vb_data *vbd;
|
2013-10-14 12:37:52 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
vbd = gs_vbdata_create();
|
2013-09-30 19:37:13 -07:00
|
|
|
vbd->num = 4;
|
2013-10-01 07:24:59 -07:00
|
|
|
vbd->points = bmalloc(sizeof(struct vec3) * 4);
|
2013-09-30 19:37:13 -07:00
|
|
|
vbd->num_tex = 1;
|
2014-08-07 23:42:07 -07:00
|
|
|
vbd->tvarray = bmalloc(sizeof(struct gs_tvertarray));
|
2013-09-30 19:37:13 -07:00
|
|
|
vbd->tvarray[0].width = 2;
|
2013-10-01 07:24:59 -07:00
|
|
|
vbd->tvarray[0].array = bmalloc(sizeof(struct vec2) * 4);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
memset(vbd->points, 0, sizeof(struct vec3) * 4);
|
|
|
|
memset(vbd->tvarray[0].array, 0, sizeof(struct vec2) * 4);
|
|
|
|
|
|
|
|
graphics->sprite_buffer = graphics->exports.
|
2014-08-07 23:42:07 -07:00
|
|
|
device_vertexbuffer_create(graphics->device, vbd, GS_DYNAMIC);
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!graphics->sprite_buffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
static bool graphics_init(struct graphics_subsystem *graphics)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 top_mat;
|
2013-10-14 12:37:52 -07:00
|
|
|
|
2014-06-14 23:09:13 -07:00
|
|
|
matrix4_identity(&top_mat);
|
2013-10-14 12:37:52 -07:00
|
|
|
da_push_back(graphics->matrix_stack, &top_mat);
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_enter_context(graphics->device);
|
2013-10-14 12:37:52 -07:00
|
|
|
|
|
|
|
if (!graphics_init_immediate_vb(graphics))
|
|
|
|
return false;
|
|
|
|
if (!graphics_init_sprite_vb(graphics))
|
|
|
|
return false;
|
|
|
|
if (pthread_mutex_init(&graphics->mutex, NULL) != 0)
|
|
|
|
return false;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_blend_function(graphics->device,
|
2014-06-29 11:43:52 -07:00
|
|
|
GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA);
|
2014-07-03 14:18:41 -07:00
|
|
|
graphics->cur_blend_state.enabled = true;
|
|
|
|
graphics->cur_blend_state.src = GS_BLEND_SRCALPHA;
|
|
|
|
graphics->cur_blend_state.dest = GS_BLEND_INVSRCALPHA;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_leave_context(graphics->device);
|
2013-10-14 12:37:52 -07:00
|
|
|
|
2014-06-27 15:33:03 -07:00
|
|
|
gs_init_image_deps();
|
2013-10-14 12:37:52 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
int gs_create(graphics_t **pgraphics, const char *module,
|
2013-09-30 19:37:13 -07:00
|
|
|
struct gs_init_data *data)
|
|
|
|
{
|
|
|
|
int errcode = GS_ERROR_FAIL;
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = bzalloc(sizeof(struct graphics_subsystem));
|
2013-10-18 20:25:13 -07:00
|
|
|
pthread_mutex_init_value(&graphics->mutex);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-03-23 01:07:54 -07:00
|
|
|
if (!data->num_backbuffers)
|
|
|
|
data->num_backbuffers = 1;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->module = os_dlopen(module);
|
|
|
|
if (!graphics->module) {
|
2014-06-27 15:16:29 -07:00
|
|
|
errcode = GS_ERROR_MODULE_NOT_FOUND;
|
2013-09-30 19:37:13 -07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!load_graphics_imports(&graphics->exports, graphics->module,
|
|
|
|
module))
|
|
|
|
goto error;
|
|
|
|
|
2014-07-20 17:40:57 -07:00
|
|
|
errcode = graphics->exports.device_create(&graphics->device, data);
|
|
|
|
if (errcode != GS_SUCCESS)
|
2013-09-30 19:37:13 -07:00
|
|
|
goto error;
|
|
|
|
|
2014-07-20 17:40:57 -07:00
|
|
|
if (!graphics_init(graphics)) {
|
|
|
|
errcode = GS_ERROR_FAIL;
|
2013-09-30 19:37:13 -07:00
|
|
|
goto error;
|
2014-07-20 17:40:57 -07:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
*pgraphics = graphics;
|
2014-07-20 17:40:57 -07:00
|
|
|
return errcode;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
error:
|
|
|
|
gs_destroy(graphics);
|
|
|
|
return errcode;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_destroy(graphics_t *graphics)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
if (!graphics)
|
|
|
|
return;
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
while (thread_graphics)
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_leave_context();
|
2013-10-14 12:37:52 -07:00
|
|
|
|
2013-10-16 23:31:18 -07:00
|
|
|
if (graphics->device) {
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_enter_context(graphics->device);
|
|
|
|
graphics->exports.gs_vertexbuffer_destroy(
|
|
|
|
graphics->sprite_buffer);
|
|
|
|
graphics->exports.gs_vertexbuffer_destroy(
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->immediate_vertbuffer);
|
|
|
|
graphics->exports.device_destroy(graphics->device);
|
2013-10-16 23:31:18 -07:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
pthread_mutex_destroy(&graphics->mutex);
|
2013-09-30 19:37:13 -07:00
|
|
|
da_free(graphics->matrix_stack);
|
|
|
|
da_free(graphics->viewport_stack);
|
2014-01-03 09:15:50 -08:00
|
|
|
if (graphics->module)
|
|
|
|
os_dlclose(graphics->module);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(graphics);
|
2014-06-27 15:33:03 -07:00
|
|
|
|
|
|
|
gs_free_image_deps();
|
2013-10-14 12:37:52 -07:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_enter_context(graphics_t *graphics)
|
2013-10-14 12:37:52 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-10-14 12:37:52 -07:00
|
|
|
bool is_current = thread_graphics == graphics;
|
|
|
|
if (thread_graphics && !is_current) {
|
|
|
|
while (thread_graphics)
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_leave_context();
|
2013-10-14 12:37:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_current) {
|
|
|
|
pthread_mutex_lock(&graphics->mutex);
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_enter_context(graphics->device);
|
2013-10-14 12:37:52 -07:00
|
|
|
thread_graphics = graphics;
|
|
|
|
}
|
|
|
|
|
2014-03-16 18:26:46 -07:00
|
|
|
os_atomic_inc_long(&graphics->ref);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_leave_context(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2013-10-14 12:37:52 -07:00
|
|
|
if (thread_graphics) {
|
2014-03-16 18:26:46 -07:00
|
|
|
if (!os_atomic_dec_long(&thread_graphics->ref)) {
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-10-14 12:37:52 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_leave_context(
|
|
|
|
graphics->device);
|
2013-10-14 12:37:52 -07:00
|
|
|
pthread_mutex_unlock(&graphics->mutex);
|
|
|
|
thread_graphics = NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *gs_get_context(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
return thread_graphics;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
const char *gs_get_device_name(void)
|
2014-07-20 15:31:45 -07:00
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics ?
|
|
|
|
thread_graphics->exports.device_get_name() : NULL;
|
2014-07-20 15:31:45 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
int gs_get_device_type(void)
|
2014-07-20 16:19:43 -07:00
|
|
|
{
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics ?
|
|
|
|
thread_graphics->exports.device_get_type() : -1;
|
2014-07-20 16:19:43 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static inline struct matrix4 *top_matrix(graphics_t *graphics)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
return graphics ?
|
|
|
|
(graphics->matrix_stack.array + graphics->cur_matrix) : NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_push(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
|
|
|
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 mat, *top_mat = top_matrix(graphics);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-06-14 23:09:13 -07:00
|
|
|
memcpy(&mat, top_mat, sizeof(struct matrix4));
|
2013-09-30 19:37:13 -07:00
|
|
|
da_push_back(graphics->matrix_stack, &mat);
|
|
|
|
graphics->cur_matrix++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_pop(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
if (graphics->cur_matrix == 0) {
|
2014-02-28 19:07:56 -08:00
|
|
|
blog(LOG_ERROR, "Tried to pop last matrix on stack");
|
2013-09-30 19:37:13 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
da_erase(graphics->matrix_stack, graphics->cur_matrix);
|
|
|
|
graphics->cur_matrix--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_identity(void)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-06-14 23:09:13 -07:00
|
|
|
matrix4_identity(top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_transpose(void)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-06-14 23:09:13 -07:00
|
|
|
matrix4_transpose(top_mat, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-06-14 23:09:13 -07:00
|
|
|
void gs_matrix_set(const struct matrix4 *matrix)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-06-14 23:09:13 -07:00
|
|
|
matrix4_copy(top_mat, matrix);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-06-14 23:09:13 -07:00
|
|
|
void gs_matrix_get(struct matrix4 *dst)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-06-14 23:09:13 -07:00
|
|
|
matrix4_copy(dst, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-06-14 23:09:13 -07:00
|
|
|
void gs_matrix_mul(const struct matrix4 *matrix)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_mul(top_mat, matrix, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_rotquat(const struct quat *rot)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_rotate_i(top_mat, rot, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_rotaa(const struct axisang *rot)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_rotate_aa_i(top_mat, rot, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_translate(const struct vec3 *pos)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_translate3v_i(top_mat, pos, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_scale(const struct vec3 *scale)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat)
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_scale_i(top_mat, scale, top_mat);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_rotaa4f(float x, float y, float z, float angle)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2013-09-30 19:37:13 -07:00
|
|
|
struct axisang aa;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-04-26 23:44:27 -07:00
|
|
|
if (top_mat) {
|
2014-02-23 21:39:33 -08:00
|
|
|
axisang_set(&aa, x, y, z, angle);
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_rotate_aa_i(top_mat, &aa, top_mat);
|
2014-02-23 21:39:33 -08:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_translate3f(float x, float y, float z)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2013-09-30 19:37:13 -07:00
|
|
|
struct vec3 p;
|
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat) {
|
|
|
|
vec3_set(&p, x, y, z);
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_translate3v_i(top_mat, &p, top_mat);
|
2014-02-23 21:39:33 -08:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_matrix_scale3f(float x, float y, float z)
|
|
|
|
{
|
2014-06-14 23:09:13 -07:00
|
|
|
struct matrix4 *top_mat = top_matrix(thread_graphics);
|
2013-09-30 19:37:13 -07:00
|
|
|
struct vec3 p;
|
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (top_mat) {
|
|
|
|
vec3_set(&p, x, y, z);
|
2014-08-20 12:38:53 -07:00
|
|
|
matrix4_scale_i(top_mat, &p, top_mat);
|
2014-02-23 21:39:33 -08:00
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static inline void reset_immediate_arrays(graphics_t *graphics)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
da_init(graphics->verts);
|
|
|
|
da_init(graphics->norms);
|
|
|
|
da_init(graphics->colors);
|
2014-02-23 21:39:33 -08:00
|
|
|
for (size_t i = 0; i < 16; i++)
|
2013-09-30 19:37:13 -07:00
|
|
|
da_init(graphics->texverts[i]);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_render_start(bool b_new)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
graphics->using_immediate = !b_new;
|
|
|
|
reset_immediate_arrays(graphics);
|
|
|
|
|
|
|
|
if (b_new) {
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->vbd = gs_vbdata_create();
|
2013-09-30 19:37:13 -07:00
|
|
|
} else {
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->vbd = gs_vertexbuffer_get_data(
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->immediate_vertbuffer);
|
|
|
|
memset(graphics->vbd->colors, 0xFF,
|
2013-10-01 06:16:40 -07:00
|
|
|
sizeof(uint32_t) * IMMEDIATE_COUNT);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
graphics->verts.array = graphics->vbd->points;
|
|
|
|
graphics->norms.array = graphics->vbd->normals;
|
|
|
|
graphics->colors.array = graphics->vbd->colors;
|
|
|
|
graphics->texverts[0].array = graphics->vbd->tvarray[0].array;
|
|
|
|
|
2013-10-01 06:16:40 -07:00
|
|
|
graphics->verts.capacity = IMMEDIATE_COUNT;
|
|
|
|
graphics->norms.capacity = IMMEDIATE_COUNT;
|
|
|
|
graphics->colors.capacity = IMMEDIATE_COUNT;
|
|
|
|
graphics->texverts[0].capacity = IMMEDIATE_COUNT;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t min_size(const size_t a, const size_t b)
|
|
|
|
{
|
|
|
|
return (a < b) ? a : b;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_render_stop(enum gs_draw_mode mode)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
size_t i, num;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
|
|
|
|
|
|
|
num = graphics->verts.num;
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!num) {
|
|
|
|
if (!graphics->using_immediate) {
|
|
|
|
da_free(graphics->verts);
|
|
|
|
da_free(graphics->norms);
|
|
|
|
da_free(graphics->colors);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
da_free(graphics->texverts[i]);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_vbdata_destroy(graphics->vbd);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (graphics->norms.num &&
|
|
|
|
(graphics->norms.num != graphics->verts.num)) {
|
2014-08-07 23:42:07 -07:00
|
|
|
blog(LOG_ERROR, "gs_render_stop: normal count does "
|
2014-02-28 19:07:56 -08:00
|
|
|
"not match vertex count");
|
2013-09-30 19:37:13 -07:00
|
|
|
num = min_size(num, graphics->norms.num);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (graphics->colors.num &&
|
|
|
|
(graphics->colors.num != graphics->verts.num)) {
|
2014-08-07 23:42:07 -07:00
|
|
|
blog(LOG_ERROR, "gs_render_stop: color count does "
|
2014-02-28 19:07:56 -08:00
|
|
|
"not match vertex count");
|
2013-09-30 19:37:13 -07:00
|
|
|
num = min_size(num, graphics->colors.num);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (graphics->texverts[0].num &&
|
|
|
|
(graphics->texverts[0].num != graphics->verts.num)) {
|
2014-08-07 23:42:07 -07:00
|
|
|
blog(LOG_ERROR, "gs_render_stop: texture vertex count does "
|
2014-02-28 19:07:56 -08:00
|
|
|
"not match vertex count");
|
2013-09-30 19:37:13 -07:00
|
|
|
num = min_size(num, graphics->texverts[0].num);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (graphics->using_immediate) {
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_vertexbuffer_flush(graphics->immediate_vertbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
gs_load_vertexbuffer(graphics->immediate_vertbuffer);
|
|
|
|
gs_load_indexbuffer(NULL);
|
|
|
|
gs_draw(mode, 0, (uint32_t)num);
|
|
|
|
|
|
|
|
reset_immediate_arrays(graphics);
|
|
|
|
} else {
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_vertbuffer_t *vb = gs_render_save();
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
gs_load_vertexbuffer(vb);
|
|
|
|
gs_load_indexbuffer(NULL);
|
|
|
|
gs_draw(mode, 0, 0);
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_vertexbuffer_destroy(vb);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
graphics->vbd = NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_vertbuffer_t *gs_render_save(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-09-30 19:37:13 -07:00
|
|
|
size_t num_tex, i;
|
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return NULL;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
if (graphics->using_immediate)
|
|
|
|
return NULL;
|
|
|
|
|
2014-06-14 23:30:58 -07:00
|
|
|
if (!graphics->verts.num) {
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_vbdata_destroy(graphics->vbd);
|
2013-09-30 19:37:13 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-14 23:30:58 -07:00
|
|
|
for (num_tex = 0; num_tex < 16; num_tex++)
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!graphics->texverts[num_tex].num)
|
|
|
|
break;
|
|
|
|
|
|
|
|
graphics->vbd->points = graphics->verts.array;
|
|
|
|
graphics->vbd->normals = graphics->norms.array;
|
|
|
|
graphics->vbd->colors = graphics->colors.array;
|
|
|
|
graphics->vbd->num = graphics->verts.num;
|
|
|
|
graphics->vbd->num_tex = num_tex;
|
2014-06-14 23:30:58 -07:00
|
|
|
|
|
|
|
if (graphics->vbd->num_tex) {
|
|
|
|
graphics->vbd->tvarray =
|
2014-08-07 23:42:07 -07:00
|
|
|
bmalloc(sizeof(struct gs_tvertarray) * num_tex);
|
2014-06-14 23:30:58 -07:00
|
|
|
|
|
|
|
for (i = 0; i < num_tex; i++) {
|
|
|
|
graphics->vbd->tvarray[i].width = 2;
|
|
|
|
graphics->vbd->tvarray[i].array =
|
|
|
|
graphics->texverts[i].array;
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
reset_immediate_arrays(graphics);
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return gs_vertexbuffer_create(graphics->vbd, 0);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_vertex2f(float x, float y)
|
|
|
|
{
|
|
|
|
struct vec3 v3;
|
|
|
|
|
|
|
|
vec3_set(&v3, x, y, 0.0f);
|
|
|
|
gs_vertex3v(&v3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_vertex3f(float x, float y, float z)
|
|
|
|
{
|
|
|
|
struct vec3 v3;
|
|
|
|
|
|
|
|
vec3_set(&v3, x, y, z);
|
|
|
|
gs_vertex3v(&v3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_normal3f(float x, float y, float z)
|
|
|
|
{
|
|
|
|
struct vec3 v3;
|
|
|
|
|
|
|
|
vec3_set(&v3, x, y, z);
|
|
|
|
gs_normal3v(&v3);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static inline bool validvertsize(graphics_t *graphics, size_t num,
|
2013-09-30 19:37:13 -07:00
|
|
|
const char *name)
|
|
|
|
{
|
2013-10-17 17:21:42 -07:00
|
|
|
if (graphics->using_immediate && num == IMMEDIATE_COUNT) {
|
2014-02-28 19:02:29 -08:00
|
|
|
blog(LOG_ERROR, "%s: tried to use over %u "
|
|
|
|
"for immediate rendering",
|
|
|
|
name, IMMEDIATE_COUNT);
|
2013-09-30 19:37:13 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_color(uint32_t color)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-14 23:30:58 -07:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!validvertsize(graphics, graphics->colors.num, "gs_color"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
da_push_back(graphics->colors, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_texcoord(float x, float y, int unit)
|
|
|
|
{
|
|
|
|
struct vec2 v2;
|
|
|
|
|
|
|
|
vec2_set(&v2, x, y);
|
|
|
|
gs_texcoord2v(&v2, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_vertex2v(const struct vec2 *v)
|
|
|
|
{
|
|
|
|
struct vec3 v3;
|
|
|
|
|
|
|
|
vec3_set(&v3, v->x, v->y, 0.0f);
|
|
|
|
gs_vertex3v(&v3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_vertex3v(const struct vec3 *v)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-14 23:30:58 -07:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!validvertsize(graphics, graphics->verts.num, "gs_vertex"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
da_push_back(graphics->verts, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_normal3v(const struct vec3 *v)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-14 23:30:58 -07:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!validvertsize(graphics, graphics->norms.num, "gs_normal"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
da_push_back(graphics->norms, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_color4v(const struct vec4 *v)
|
|
|
|
{
|
|
|
|
/* TODO */
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(v);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_texcoord2v(const struct vec2 *v, int unit)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-14 23:30:58 -07:00
|
|
|
if (!graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
if (!validvertsize(graphics, graphics->texverts[unit].num,
|
|
|
|
"gs_texcoord"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
da_push_back(graphics->texverts[unit], v);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
input_t *gs_get_input(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_effect_t *gs_get_effect(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
return thread_graphics ? thread_graphics->cur_effect : NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_effect_t *gs_effect_create_from_file(const char *file, char **error_string)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
char *file_string;
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_effect_t *effect = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !file)
|
|
|
|
return NULL;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
file_string = os_quick_read_utf8_file(file);
|
|
|
|
if (!file_string) {
|
2014-02-28 19:02:29 -08:00
|
|
|
blog(LOG_ERROR, "Could not load effect file '%s'", file);
|
2013-09-30 19:37:13 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
effect = gs_effect_create(file_string, file, error_string);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(file_string);
|
|
|
|
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_effect_t *gs_effect_create(const char *effect_string, const char *filename,
|
2013-09-30 19:37:13 -07:00
|
|
|
char **error_string)
|
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !effect_string)
|
|
|
|
return NULL;
|
|
|
|
|
2014-02-09 11:34:07 -08:00
|
|
|
struct gs_effect *effect = bzalloc(sizeof(struct gs_effect));
|
2013-09-30 19:37:13 -07:00
|
|
|
struct effect_parser parser;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
effect->graphics = thread_graphics;
|
|
|
|
|
|
|
|
ep_init(&parser);
|
|
|
|
success = ep_parse(&parser, effect, effect_string, filename);
|
|
|
|
if (!success) {
|
2014-02-16 21:42:35 -08:00
|
|
|
if (error_string)
|
|
|
|
*error_string = error_data_buildstring(
|
|
|
|
&parser.cfp.error_list);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_effect_destroy(effect);
|
2013-09-30 19:37:13 -07:00
|
|
|
effect = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ep_free(&parser);
|
|
|
|
return effect;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *gs_vertexshader_create_from_file(const char *file,
|
2014-08-07 23:42:07 -07:00
|
|
|
char **error_string)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !file)
|
|
|
|
return NULL;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
char *file_string;
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *shader = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
file_string = os_quick_read_utf8_file(file);
|
|
|
|
if (!file_string) {
|
2014-02-28 19:02:29 -08:00
|
|
|
blog(LOG_ERROR, "Could not load vertex shader file '%s'",
|
2013-09-30 19:37:13 -07:00
|
|
|
file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
shader = gs_vertexshader_create(file_string, file, error_string);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(file_string);
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *gs_pixelshader_create_from_file(const char *file,
|
2014-08-07 23:42:07 -07:00
|
|
|
char **error_string)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
char *file_string;
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *shader = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !file)
|
|
|
|
return NULL;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
file_string = os_quick_read_utf8_file(file);
|
|
|
|
if (!file_string) {
|
2014-02-28 19:02:29 -08:00
|
|
|
blog(LOG_ERROR, "Could not load pixel shader file '%s'",
|
2013-09-30 19:37:13 -07:00
|
|
|
file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
shader = gs_pixelshader_create(file_string, file, error_string);
|
2013-09-30 19:37:13 -07:00
|
|
|
bfree(file_string);
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2013-12-20 11:36:38 -08:00
|
|
|
static inline void assign_sprite_rect(float *start, float *end, float size,
|
|
|
|
bool flip)
|
|
|
|
{
|
|
|
|
if (!flip) {
|
|
|
|
*start = 0.0f;
|
|
|
|
*end = size;
|
|
|
|
} else {
|
|
|
|
*start = size;
|
|
|
|
*end = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 15:05:51 -07:00
|
|
|
static inline void assign_sprite_uv(float *start, float *end, bool flip)
|
|
|
|
{
|
|
|
|
if (!flip) {
|
|
|
|
*start = 0.0f;
|
|
|
|
*end = 1.0f;
|
|
|
|
} else {
|
|
|
|
*start = 1.0f;
|
|
|
|
*end = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static void build_sprite(struct gs_vb_data *data, float fcx, float fcy,
|
2014-02-14 14:13:36 -08:00
|
|
|
float start_u, float end_u, float start_v, float end_v)
|
2013-10-26 15:05:51 -07:00
|
|
|
{
|
|
|
|
struct vec2 *tvarray = data->tvarray[0].array;
|
|
|
|
|
|
|
|
vec3_zero(data->points);
|
|
|
|
vec3_set(data->points+1, fcx, 0.0f, 0.0f);
|
|
|
|
vec3_set(data->points+2, 0.0f, fcy, 0.0f);
|
|
|
|
vec3_set(data->points+3, fcx, fcy, 0.0f);
|
|
|
|
vec2_set(tvarray, start_u, start_v);
|
|
|
|
vec2_set(tvarray+1, end_u, start_v);
|
|
|
|
vec2_set(tvarray+2, start_u, end_v);
|
|
|
|
vec2_set(tvarray+3, end_u, end_v);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline void build_sprite_norm(struct gs_vb_data *data, float fcx,
|
|
|
|
float fcy, uint32_t flip)
|
2013-12-20 11:36:38 -08:00
|
|
|
{
|
|
|
|
float start_u, end_u;
|
|
|
|
float start_v, end_v;
|
|
|
|
|
|
|
|
assign_sprite_uv(&start_u, &end_u, (flip & GS_FLIP_U) != 0);
|
|
|
|
assign_sprite_uv(&start_v, &end_v, (flip & GS_FLIP_V) != 0);
|
2014-02-14 14:13:36 -08:00
|
|
|
build_sprite(data, fcx, fcy, start_u, end_u, start_v, end_v);
|
2013-12-20 11:36:38 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
static inline void build_sprite_rect(struct gs_vb_data *data, gs_texture_t *tex,
|
2013-12-20 11:36:38 -08:00
|
|
|
float fcx, float fcy, uint32_t flip)
|
|
|
|
{
|
|
|
|
float start_u, end_u;
|
|
|
|
float start_v, end_v;
|
2014-08-07 23:42:07 -07:00
|
|
|
float width = (float)gs_texture_get_width(tex);
|
|
|
|
float height = (float)gs_texture_get_height(tex);
|
2013-12-20 11:36:38 -08:00
|
|
|
|
|
|
|
assign_sprite_rect(&start_u, &end_u, width, (flip & GS_FLIP_U) != 0);
|
|
|
|
assign_sprite_rect(&start_v, &end_v, height, (flip & GS_FLIP_V) != 0);
|
2014-02-14 14:13:36 -08:00
|
|
|
build_sprite(data, fcx, fcy, start_u, end_u, start_v, end_v);
|
2013-12-20 11:36:38 -08:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width,
|
2013-11-26 21:26:14 -08:00
|
|
|
uint32_t height)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-09-30 19:37:13 -07:00
|
|
|
float fcx, fcy;
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_vb_data *data;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
assert(tex);
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!tex || !thread_graphics)
|
|
|
|
return;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (gs_get_texture_type(tex) != GS_TEXTURE_2D) {
|
2014-02-28 19:07:56 -08:00
|
|
|
blog(LOG_ERROR, "A sprite must be a 2D texture");
|
2013-09-30 19:37:13 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
fcx = width ? (float)width : (float)gs_texture_get_width(tex);
|
|
|
|
fcy = height ? (float)height : (float)gs_texture_get_height(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
data = gs_vertexbuffer_get_data(graphics->sprite_buffer);
|
|
|
|
if (gs_texture_is_rect(tex))
|
2013-12-20 11:36:38 -08:00
|
|
|
build_sprite_rect(data, tex, fcx, fcy, flip);
|
|
|
|
else
|
|
|
|
build_sprite_norm(data, fcx, fcy, flip);
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_vertexbuffer_flush(graphics->sprite_buffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_load_vertexbuffer(graphics->sprite_buffer);
|
2013-10-16 23:31:18 -07:00
|
|
|
gs_load_indexbuffer(NULL);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
gs_draw(GS_TRISTRIP, 0, 0);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_draw_cube_backdrop(gs_texture_t *cubetex, const struct quat *rot,
|
2013-09-30 19:37:13 -07:00
|
|
|
float left, float right, float top, float bottom, float znear)
|
|
|
|
{
|
|
|
|
/* TODO */
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(cubetex);
|
|
|
|
UNUSED_PARAMETER(rot);
|
|
|
|
UNUSED_PARAMETER(left);
|
|
|
|
UNUSED_PARAMETER(right);
|
|
|
|
UNUSED_PARAMETER(top);
|
|
|
|
UNUSED_PARAMETER(bottom);
|
|
|
|
UNUSED_PARAMETER(znear);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_reset_viewport(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
uint32_t cx, cy;
|
2014-04-14 13:55:14 -07:00
|
|
|
assert(thread_graphics != NULL);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_get_size(&cx, &cy);
|
2014-04-14 13:55:14 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_set_viewport(0, 0, (int)cx, (int)cy);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_set_2d_mode(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
uint32_t cx, cy;
|
2014-04-14 13:55:14 -07:00
|
|
|
assert(thread_graphics != NULL);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_get_size(&cx, &cy);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -1.0, -1024.0f);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_set_3d_mode(double fovy, double znear, double zvar)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
/* TODO */
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(fovy);
|
|
|
|
UNUSED_PARAMETER(znear);
|
|
|
|
UNUSED_PARAMETER(zvar);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_viewport_push(void)
|
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
struct gs_rect *rect = da_push_back_new(
|
|
|
|
thread_graphics->viewport_stack);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_get_viewport(rect);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_viewport_pop(void)
|
|
|
|
{
|
|
|
|
struct gs_rect *rect;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !thread_graphics->viewport_stack.num)
|
2013-09-30 19:37:13 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
rect = da_end(thread_graphics->viewport_stack);
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_set_viewport(rect->x, rect->y, rect->cx, rect->cy);
|
2013-09-30 19:37:13 -07:00
|
|
|
da_pop_back(thread_graphics->viewport_stack);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_texture_set_image(gs_texture_t *tex, const uint8_t *data,
|
2014-08-07 23:42:07 -07:00
|
|
|
uint32_t linesize, bool flip)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-06-27 21:29:06 -07:00
|
|
|
uint8_t *ptr;
|
2014-02-09 04:51:06 -08:00
|
|
|
uint32_t linesize_out;
|
2013-10-25 10:25:28 -07:00
|
|
|
uint32_t row_copy;
|
2014-06-27 21:29:06 -07:00
|
|
|
int32_t height;
|
2013-10-25 10:25:28 -07:00
|
|
|
int32_t y;
|
|
|
|
|
2014-06-27 21:29:06 -07:00
|
|
|
if (!thread_graphics || !tex)
|
|
|
|
return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
height = (int32_t)gs_texture_get_height(tex);
|
2014-06-27 21:29:06 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (!gs_texture_map(tex, &ptr, &linesize_out))
|
2013-10-25 10:25:28 -07:00
|
|
|
return;
|
|
|
|
|
2014-02-09 04:51:06 -08:00
|
|
|
row_copy = (linesize < linesize_out) ? linesize : linesize_out;
|
2013-10-25 10:25:28 -07:00
|
|
|
|
|
|
|
if (flip) {
|
|
|
|
for (y = height-1; y >= 0; y--)
|
2014-06-27 21:29:06 -07:00
|
|
|
memcpy(ptr + (uint32_t)y * linesize_out,
|
|
|
|
data + (uint32_t)y * linesize,
|
2013-10-25 10:25:28 -07:00
|
|
|
row_copy);
|
|
|
|
|
2014-02-09 04:51:06 -08:00
|
|
|
} else if (linesize == linesize_out) {
|
2013-10-25 10:25:28 -07:00
|
|
|
memcpy(ptr, data, row_copy * height);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
for (y = 0; y < height; y++)
|
2014-06-27 21:29:06 -07:00
|
|
|
memcpy(ptr + (uint32_t)y * linesize_out,
|
|
|
|
data + (uint32_t)y * linesize,
|
2013-10-25 10:25:28 -07:00
|
|
|
row_copy);
|
|
|
|
}
|
2014-02-09 05:24:21 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_texture_unmap(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_cubetexture_set_image(gs_texture_t *cubetex, uint32_t side,
|
2014-08-07 23:42:07 -07:00
|
|
|
const void *data, uint32_t linesize, bool invert)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
/* TODO */
|
2014-02-14 14:13:36 -08:00
|
|
|
UNUSED_PARAMETER(cubetex);
|
|
|
|
UNUSED_PARAMETER(side);
|
|
|
|
UNUSED_PARAMETER(data);
|
|
|
|
UNUSED_PARAMETER(linesize);
|
|
|
|
UNUSED_PARAMETER(invert);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2013-10-16 23:31:18 -07:00
|
|
|
void gs_perspective(float angle, float aspect, float near, float far)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-10-16 23:31:18 -07:00
|
|
|
float xmin, xmax, ymin, ymax;
|
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-10-16 23:31:18 -07:00
|
|
|
ymax = near * tanf(RAD(angle)*0.5f);
|
|
|
|
ymin = -ymax;
|
|
|
|
|
|
|
|
xmin = ymin * aspect;
|
|
|
|
xmax = ymax * aspect;
|
|
|
|
|
|
|
|
graphics->exports.device_frustum(graphics->device, xmin, xmax,
|
|
|
|
ymin, ymax, near, far);
|
|
|
|
}
|
|
|
|
|
2014-07-03 13:57:40 -07:00
|
|
|
void gs_reset_blend_state(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-07-03 13:57:40 -07:00
|
|
|
if (!graphics) return;
|
|
|
|
|
|
|
|
if (!graphics->cur_blend_state.enabled)
|
|
|
|
gs_enable_blending(true);
|
|
|
|
|
|
|
|
if (graphics->cur_blend_state.src != GS_BLEND_SRCALPHA ||
|
|
|
|
graphics->cur_blend_state.dest != GS_BLEND_INVSRCALPHA)
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_blend_function(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA);
|
2014-07-03 13:57:40 -07:00
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
const char *gs_preprocessor_name(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-02-16 18:28:21 -08:00
|
|
|
return graphics->exports.device_preprocessor_name();
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_swapchain_t *gs_swapchain_create(struct gs_init_data *data)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-26 15:22:56 -07:00
|
|
|
struct gs_init_data new_data = *data;
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-09-26 15:22:56 -07:00
|
|
|
if (new_data.num_backbuffers == 0)
|
|
|
|
new_data.num_backbuffers = 1;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_swapchain_create(graphics->device,
|
2014-09-26 15:22:56 -07:00
|
|
|
&new_data);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_resize(uint32_t x, uint32_t y)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_resize(graphics->device, x, y);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_get_size(uint32_t *x, uint32_t *y)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_get_size(graphics->device, x, y);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
uint32_t gs_get_width(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_width(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
uint32_t gs_get_height(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_height(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2013-10-04 12:13:59 -07:00
|
|
|
static inline bool is_pow2(uint32_t size)
|
|
|
|
{
|
|
|
|
return size >= 2 && (size & (size-1)) == 0;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_t *gs_texture_create(uint32_t width, uint32_t height,
|
2013-10-16 23:31:18 -07:00
|
|
|
enum gs_color_format color_format, uint32_t levels,
|
2014-06-27 21:29:06 -07:00
|
|
|
const uint8_t **data, uint32_t flags)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-10-04 12:13:59 -07:00
|
|
|
bool pow2tex = is_pow2(width) && is_pow2(height);
|
2014-08-07 23:42:07 -07:00
|
|
|
bool uses_mipmaps = (flags & GS_BUILD_MIPMAPS || levels != 1);
|
2013-10-04 12:13:59 -07:00
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-04 12:13:59 -07:00
|
|
|
if (uses_mipmaps && !pow2tex) {
|
|
|
|
blog(LOG_WARNING, "Cannot use mipmaps with a "
|
|
|
|
"non-power-of-two texture. Disabling "
|
|
|
|
"mipmaps for this texture.");
|
|
|
|
|
|
|
|
uses_mipmaps = false;
|
2014-08-07 23:42:07 -07:00
|
|
|
flags &= ~GS_BUILD_MIPMAPS;
|
2013-10-04 12:13:59 -07:00
|
|
|
levels = 1;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (uses_mipmaps && flags & GS_RENDER_TARGET) {
|
2013-10-04 12:13:59 -07:00
|
|
|
blog(LOG_WARNING, "Cannot use mipmaps with render targets. "
|
|
|
|
"Disabling mipmaps for this texture.");
|
2014-08-07 23:42:07 -07:00
|
|
|
flags &= ~GS_BUILD_MIPMAPS;
|
2013-10-04 12:13:59 -07:00
|
|
|
levels = 1;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_texture_create(graphics->device,
|
2013-10-04 08:55:33 -07:00
|
|
|
width, height, color_format, levels, data, flags);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_t *gs_cubetexture_create(uint32_t size,
|
2013-10-04 08:55:33 -07:00
|
|
|
enum gs_color_format color_format, uint32_t levels,
|
2014-06-27 21:29:06 -07:00
|
|
|
const uint8_t **data, uint32_t flags)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-10-04 12:13:59 -07:00
|
|
|
bool pow2tex = is_pow2(size);
|
2014-08-07 23:42:07 -07:00
|
|
|
bool uses_mipmaps = (flags & GS_BUILD_MIPMAPS || levels != 1);
|
2013-10-04 12:13:59 -07:00
|
|
|
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-04 12:13:59 -07:00
|
|
|
if (uses_mipmaps && !pow2tex) {
|
|
|
|
blog(LOG_WARNING, "Cannot use mipmaps with a "
|
|
|
|
"non-power-of-two texture. Disabling "
|
|
|
|
"mipmaps for this texture.");
|
|
|
|
|
|
|
|
uses_mipmaps = false;
|
2014-08-07 23:42:07 -07:00
|
|
|
flags &= ~GS_BUILD_MIPMAPS;
|
2013-10-04 12:13:59 -07:00
|
|
|
levels = 1;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (uses_mipmaps && flags & GS_RENDER_TARGET) {
|
2013-10-04 12:13:59 -07:00
|
|
|
blog(LOG_WARNING, "Cannot use mipmaps with render targets. "
|
|
|
|
"Disabling mipmaps for this texture.");
|
2014-08-07 23:42:07 -07:00
|
|
|
flags &= ~GS_BUILD_MIPMAPS;
|
2013-10-04 12:13:59 -07:00
|
|
|
levels = 1;
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_cubetexture_create(graphics->device,
|
2013-10-04 08:55:33 -07:00
|
|
|
size, color_format, levels, data, flags);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_t *gs_voltexture_create(uint32_t width, uint32_t height,
|
2013-10-04 08:55:33 -07:00
|
|
|
uint32_t depth, enum gs_color_format color_format,
|
2014-06-27 21:29:06 -07:00
|
|
|
uint32_t levels, const uint8_t **data, uint32_t flags)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_voltexture_create(graphics->device,
|
2013-10-04 08:55:33 -07:00
|
|
|
width, height, depth, color_format, levels, data,
|
|
|
|
flags);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_zstencil_t *gs_zstencil_create(uint32_t width, uint32_t height,
|
2013-09-30 19:37:13 -07:00
|
|
|
enum gs_zstencil_format format)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_zstencil_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
width, height, format);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_stagesurf_t *gs_stagesurface_create(uint32_t width, uint32_t height,
|
2013-09-30 19:37:13 -07:00
|
|
|
enum gs_color_format color_format)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_stagesurface_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
width, height, color_format);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_samplerstate_t *gs_samplerstate_create(struct gs_sampler_info *info)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_samplerstate_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
info);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *gs_vertexshader_create(const char *shader, const char *file,
|
2013-09-30 19:37:13 -07:00
|
|
|
char **error_string)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_vertexshader_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
shader, file, error_string);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *gs_pixelshader_create(const char *shader,
|
2013-09-30 19:37:13 -07:00
|
|
|
const char *file, char **error_string)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_pixelshader_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
shader, file, error_string);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_vertbuffer_t *gs_vertexbuffer_create(struct gs_vb_data *data,
|
2013-09-30 19:37:13 -07:00
|
|
|
uint32_t flags)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_vertexbuffer_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
data, flags);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type,
|
2013-09-30 19:37:13 -07:00
|
|
|
void *indices, size_t num, uint32_t flags)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_indexbuffer_create(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
type, indices, num, flags);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
enum gs_texture_type gs_get_texture_type(gs_texture_t *texture)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return GS_TEXTURE_2D;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_texture_type(texture);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_vertexbuffer(gs_vertbuffer_t *vertbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_vertexbuffer(graphics->device,
|
|
|
|
vertbuffer);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_indexbuffer(gs_indexbuffer_t *indexbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_indexbuffer(graphics->device,
|
|
|
|
indexbuffer);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_texture(gs_texture_t *tex, int unit)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_texture(graphics->device, tex, unit);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_samplerstate(gs_samplerstate_t *samplerstate, int unit)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_samplerstate(graphics->device,
|
|
|
|
samplerstate, unit);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_vertexshader(gs_shader_t *vertshader)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_vertexshader(graphics->device,
|
|
|
|
vertshader);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_pixelshader(gs_shader_t *pixelshader)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_pixelshader(graphics->device,
|
|
|
|
pixelshader);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_load_default_samplerstate(bool b_3d, int unit)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_load_default_samplerstate(graphics->device,
|
2013-09-30 19:37:13 -07:00
|
|
|
b_3d, unit);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *gs_get_vertex_shader(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_vertex_shader(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_shader_t *gs_get_pixel_shader(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_pixel_shader(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_t *gs_get_render_target(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_render_target(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_zstencil_t *gs_get_zstencil_target(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_zstencil_target(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_set_render_target(gs_texture_t *tex, gs_zstencil_t *zstencil)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_set_render_target(graphics->device, tex,
|
2013-09-30 19:37:13 -07:00
|
|
|
zstencil);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_set_cube_render_target(gs_texture_t *cubetex, int side,
|
|
|
|
gs_zstencil_t *zstencil)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_set_cube_render_target(graphics->device,
|
|
|
|
cubetex, side, zstencil);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_copy_texture(gs_texture_t *dst, gs_texture_t *src)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_copy_texture(graphics->device, dst, src);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_copy_texture_region(gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y,
|
|
|
|
gs_texture_t *src, uint32_t src_x, uint32_t src_y,
|
2014-04-09 11:04:58 -07:00
|
|
|
uint32_t src_w, uint32_t src_h)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-04-09 11:04:58 -07:00
|
|
|
if (!graphics) return;
|
|
|
|
|
|
|
|
graphics->exports.device_copy_texture_region(graphics->device,
|
|
|
|
dst, dst_x, dst_y,
|
|
|
|
src, src_x, src_y, src_w, src_h);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_stage_texture(gs_stagesurf_t *dst, gs_texture_t *src)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_stage_texture(graphics->device, dst, src);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_begin_scene(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_begin_scene(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_draw(enum gs_draw_mode draw_mode, uint32_t start_vert,
|
|
|
|
uint32_t num_verts)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_draw(graphics->device, draw_mode,
|
|
|
|
start_vert, num_verts);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_end_scene(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_end_scene(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_load_swapchain(gs_swapchain_t *swapchain)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_load_swapchain(graphics->device, swapchain);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_clear(uint32_t clear_flags, struct vec4 *color, float depth,
|
|
|
|
uint8_t stencil)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_clear(graphics->device, clear_flags, color,
|
|
|
|
depth, stencil);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_present(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_present(graphics->device);
|
|
|
|
}
|
|
|
|
|
2014-06-25 19:32:34 -07:00
|
|
|
void gs_flush(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:32:34 -07:00
|
|
|
if (!graphics) return;
|
|
|
|
|
|
|
|
graphics->exports.device_flush(graphics->device);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_set_cull_mode(enum gs_cull_mode mode)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_set_cull_mode(graphics->device, mode);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
enum gs_cull_mode gs_get_cull_mode(void)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return GS_NEITHER;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_get_cull_mode(graphics->device);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_enable_blending(bool enable)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-07-03 13:57:40 -07:00
|
|
|
graphics->cur_blend_state.enabled = enable;
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_enable_blending(graphics->device, enable);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_enable_depth_test(bool enable)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_enable_depth_test(graphics->device, enable);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_enable_stencil_test(bool enable)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_enable_stencil_test(graphics->device, enable);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_enable_stencil_write(bool enable)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_enable_stencil_write(graphics->device, enable);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2013-10-12 20:18:05 -07:00
|
|
|
void gs_enable_color(bool red, bool green, bool blue, bool alpha)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-10-12 20:18:05 -07:00
|
|
|
graphics->exports.device_enable_color(graphics->device, red, green,
|
|
|
|
blue, alpha);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_blend_function(enum gs_blend_type src, enum gs_blend_type dest)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-07-03 13:57:40 -07:00
|
|
|
graphics->cur_blend_state.src = src;
|
|
|
|
graphics->cur_blend_state.dest = dest;
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_blend_function(graphics->device, src, dest);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_depth_function(enum gs_depth_test test)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_depth_function(graphics->device, test);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_stencil_function(enum gs_stencil_side side, enum gs_depth_test test)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_stencil_function(graphics->device, side, test);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_stencil_op(enum gs_stencil_side side, enum gs_stencil_op_type fail,
|
|
|
|
enum gs_stencil_op_type zfail, enum gs_stencil_op_type zpass)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_stencil_op(graphics->device, side, fail, zfail,
|
2013-09-30 19:37:13 -07:00
|
|
|
zpass);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_set_viewport(int x, int y, int width, int height)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_set_viewport(graphics->device, x, y, width,
|
2013-09-30 19:37:13 -07:00
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_get_viewport(struct gs_rect *rect)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_get_viewport(graphics->device, rect);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
void gs_set_scissor_rect(struct gs_rect *rect)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.device_set_scissor_rect(graphics->device, rect);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void gs_ortho(float left, float right, float top, float bottom, float znear,
|
|
|
|
float zfar)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_ortho(graphics->device, left, right, top,
|
|
|
|
bottom, znear, zfar);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_frustum(float left, float right, float top, float bottom, float znear,
|
|
|
|
float zfar)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_frustum(graphics->device, left, right, top,
|
|
|
|
bottom, znear, zfar);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_projection_push(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_projection_push(graphics->device);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_projection_pop(void)
|
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics) return;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
graphics->exports.device_projection_pop(graphics->device);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_swapchain_destroy(gs_swapchain_t *swapchain)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !swapchain) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_swapchain_destroy(swapchain);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_destroy(gs_shader_t *shader)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !shader) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_destroy(shader);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
int gs_shader_get_num_params(gs_shader_t *shader)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !shader) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_shader_get_num_params(shader);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_sparam_t *gs_shader_get_param_by_idx(gs_shader_t *shader, uint32_t param)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !shader) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_shader_get_param_by_idx(shader, param);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_sparam_t *gs_shader_get_param_by_name(gs_shader_t *shader, const char *name)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !shader) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_shader_get_param_by_name(shader, name);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_sparam_t *gs_shader_get_viewproj_matrix(gs_shader_t *shader)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !shader) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_shader_get_viewproj_matrix(shader);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_sparam_t *gs_shader_get_world_matrix(gs_shader_t *shader)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !shader) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_shader_get_world_matrix(shader);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_get_param_info(gs_sparam_t *param,
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_shader_param_info *info)
|
2014-06-25 19:50:08 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_get_param_info(param, info);
|
2014-06-25 19:50:08 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_bool(gs_sparam_t *param, bool val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_bool(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_float(gs_sparam_t *param, float val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_float(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_int(gs_sparam_t *param, int val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_int(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_setmatrix3(gs_sparam_t *param, const struct matrix3 *val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_setmatrix3(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_matrix4(gs_sparam_t *param, const struct matrix4 *val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_matrix4(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_vec2(gs_sparam_t *param, const struct vec2 *val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_vec2(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_vec3(gs_sparam_t *param, const struct vec3 *val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_vec3(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_vec4(gs_sparam_t *param, const struct vec4 *val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_vec4(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_texture(gs_sparam_t *param, gs_texture_t *val)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_texture(param, val);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_val(gs_sparam_t *param, const void *val, size_t size)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_val(param, val, size);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_shader_set_default(gs_sparam_t *param)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-06-25 19:50:08 -07:00
|
|
|
if (!graphics || !param) return;
|
2014-02-23 21:39:33 -08:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_shader_set_default(param);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_texture_destroy(gs_texture_t *tex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_texture_destroy(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_texture_get_width(gs_texture_t *tex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_texture_get_width(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_texture_get_height(gs_texture_t *tex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_texture_get_height(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
enum gs_color_format gs_texture_get_color_format(gs_texture_t *tex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return GS_UNKNOWN;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_texture_get_color_format(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr, uint32_t *linesize)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return false;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_texture_map(tex, ptr, linesize);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_texture_unmap(gs_texture_t *tex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_texture_unmap(tex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
bool gs_texture_is_rect(gs_texture_t *tex)
|
2013-12-20 11:36:38 -08:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !tex) return false;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (graphics->exports.gs_texture_is_rect)
|
|
|
|
return graphics->exports.gs_texture_is_rect(tex);
|
2013-12-20 11:36:38 -08:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void *gs_texture_get_obj(gs_texture_t *tex)
|
2014-03-29 17:19:31 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-03-29 17:19:31 -07:00
|
|
|
if (!graphics || !tex) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_texture_get_obj(tex);
|
2014-03-29 17:19:31 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_cubetexture_destroy(gs_texture_t *cubetex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !cubetex) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_cubetexture_destroy(cubetex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_cubetexture_get_size(gs_texture_t *cubetex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !cubetex) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_cubetexture_get_size(cubetex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
enum gs_color_format gs_cubetexture_get_color_format(gs_texture_t *cubetex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !cubetex) return GS_UNKNOWN;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_cubetexture_get_color_format(cubetex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_voltexture_destroy(gs_texture_t *voltex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !voltex) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_voltexture_destroy(voltex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_voltexture_get_width(gs_texture_t *voltex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !voltex) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_voltexture_get_width(voltex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_voltexture_get_height(gs_texture_t *voltex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !voltex) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_voltexture_get_height(voltex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_voltexture_getdepth(gs_texture_t *voltex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !voltex) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_voltexture_getdepth(voltex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
enum gs_color_format gs_voltexture_get_color_format(gs_texture_t *voltex)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !voltex) return GS_UNKNOWN;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_voltexture_get_color_format(voltex);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !stagesurf) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_stagesurface_destroy(stagesurf);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_stagesurface_get_width(gs_stagesurf_t *stagesurf)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !stagesurf) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_stagesurface_get_width(stagesurf);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
uint32_t gs_stagesurface_get_height(gs_stagesurf_t *stagesurf)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !stagesurf) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_stagesurface_get_height(stagesurf);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
enum gs_color_format gs_stagesurface_get_color_format(gs_stagesurf_t *stagesurf)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !stagesurf) return GS_UNKNOWN;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_stagesurface_get_color_format(stagesurf);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data,
|
2014-08-07 23:42:07 -07:00
|
|
|
uint32_t *linesize)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !stagesurf) return false;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_stagesurface_map(stagesurf, data, linesize);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_stagesurface_unmap(gs_stagesurf_t *stagesurf)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !stagesurf) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_stagesurface_unmap(stagesurf);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_zstencil_destroy(gs_zstencil_t *zstencil)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !zstencil) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
thread_graphics->exports.gs_zstencil_destroy(zstencil);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !samplerstate) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
thread_graphics->exports.gs_samplerstate_destroy(samplerstate);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_vertexbuffer_destroy(gs_vertbuffer_t *vertbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !vertbuffer) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_vertexbuffer_destroy(vertbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_vertexbuffer_flush(gs_vertbuffer_t *vertbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !vertbuffer) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
thread_graphics->exports.gs_vertexbuffer_flush(vertbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
struct gs_vb_data *gs_vertexbuffer_get_data(gs_vertbuffer_t *vertbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !vertbuffer) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics->exports.gs_vertexbuffer_get_data(vertbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_indexbuffer_destroy(gs_indexbuffer_t *indexbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !indexbuffer) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
graphics->exports.gs_indexbuffer_destroy(indexbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_indexbuffer_flush(gs_indexbuffer_t *indexbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !indexbuffer) return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
thread_graphics->exports.gs_indexbuffer_flush(indexbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void *gs_indexbuffer_get_data(gs_indexbuffer_t *indexbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !indexbuffer) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics->exports.gs_indexbuffer_get_data(indexbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
size_t gs_indexbuffer_get_num_indices(gs_indexbuffer_t *indexbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !indexbuffer) return 0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics->exports.gs_indexbuffer_get_num_indices(
|
|
|
|
indexbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
enum gs_index_type gs_indexbuffer_get_type(gs_indexbuffer_t *indexbuffer)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!thread_graphics || !indexbuffer) return (enum gs_index_type)0;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics->exports.gs_indexbuffer_get_type(indexbuffer);
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2013-12-23 07:34:56 -08:00
|
|
|
|
2014-03-05 09:43:14 -08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
2013-12-23 07:34:56 -08:00
|
|
|
/** Platform specific functions */
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_t *gs_texture_create_from_iosurface(void *iosurf)
|
2013-12-23 07:34:56 -08:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-02-23 21:39:33 -08:00
|
|
|
if (!graphics || !iosurf ||
|
2014-08-07 23:42:07 -07:00
|
|
|
!graphics->exports.device_texture_create_from_iosurface)
|
2013-12-23 07:34:56 -08:00
|
|
|
return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.device_texture_create_from_iosurface(
|
2013-12-23 07:34:56 -08:00
|
|
|
graphics->device, iosurf);
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf)
|
2013-12-23 07:34:56 -08:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-08-07 23:42:07 -07:00
|
|
|
if (!graphics || !iosurf ||
|
|
|
|
!graphics->exports.gs_texture_rebind_iosurface)
|
2013-12-23 07:34:56 -08:00
|
|
|
return false;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return graphics->exports.gs_texture_rebind_iosurface(texture, iosurf);
|
2013-12-23 07:34:56 -08:00
|
|
|
}
|
2014-03-05 09:43:14 -08:00
|
|
|
|
|
|
|
#elif _WIN32
|
|
|
|
|
|
|
|
bool gs_gdi_texture_available(void)
|
|
|
|
{
|
|
|
|
if (!thread_graphics)
|
|
|
|
return false;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
return thread_graphics->exports.device_gdi_texture_available();
|
2014-03-05 09:43:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** creates a windows GDI-lockable texture */
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_t *gs_texture_create_gdi(uint32_t width, uint32_t height)
|
2014-03-05 09:43:14 -08:00
|
|
|
{
|
2014-09-25 17:44:05 -07:00
|
|
|
graphics_t *graphics = thread_graphics;
|
2014-03-05 09:43:14 -08:00
|
|
|
if (!graphics) return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (graphics->exports.device_texture_create_gdi)
|
|
|
|
return graphics->exports.device_texture_create_gdi(
|
2014-03-05 09:43:14 -08:00
|
|
|
graphics->device, width, height);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void *gs_texture_get_dc(gs_texture_t *gdi_tex)
|
2014-03-05 09:43:14 -08:00
|
|
|
{
|
|
|
|
if (!thread_graphics || !gdi_tex)
|
|
|
|
return NULL;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (thread_graphics->exports.gs_texture_get_dc)
|
|
|
|
return thread_graphics->exports.gs_texture_get_dc(gdi_tex);
|
2014-03-05 09:43:14 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
void gs_texture_release_dc(gs_texture_t *gdi_tex)
|
2014-03-05 09:43:14 -08:00
|
|
|
{
|
|
|
|
if (!thread_graphics || !gdi_tex)
|
|
|
|
return;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
if (thread_graphics->exports.gs_texture_release_dc)
|
|
|
|
thread_graphics->exports.gs_texture_release_dc(gdi_tex);
|
2014-03-05 09:43:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|