diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 5a0b06008..abdab2057 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -34,6 +34,41 @@ static __declspec(thread) graphics_t *thread_graphics = NULL; static __thread graphics_t *thread_graphics = NULL; #endif +static inline bool gs_obj_valid(const void *obj, const char *f, + const char *name) +{ + if (!obj) { + blog(LOG_DEBUG, "%s: Null '%s' parameter", f, name); + return false; + } + + return true; +} + +static inline bool gs_valid(const char *f) +{ + if (!thread_graphics) { + blog(LOG_DEBUG, "%s: called while not in a graphics context", + f); + return false; + } + + return true; +} + +#define ptr_valid(ptr, func) gs_obj_valid(ptr, func, #ptr) + +#define gs_valid_p(func, param1) \ + (gs_valid(func) && ptr_valid(param1, func)) + +#define gs_valid_p2(func, param1, param2) \ + (gs_valid(func) && ptr_valid(param1, func) \ + && ptr_valid(param2, func)) + +#define gs_valid_p3(func, param1, param2, param3) \ + (gs_valid(func) && ptr_valid(param1, func) \ + && ptr_valid(param2, func) && ptr_valid(param3, func)) + #define IMMEDIATE_COUNT 512 void gs_enum_adapters( @@ -42,7 +77,10 @@ void gs_enum_adapters( { graphics_t *graphics = thread_graphics; - if (graphics && graphics->exports.device_enum_adapters) { + if (!gs_valid_p("gs_enum_adapters", callback)) + return; + + if (graphics->exports.device_enum_adapters) { if (graphics->exports.device_enum_adapters(callback, param)) { return; } @@ -178,7 +216,7 @@ extern void gs_effect_actually_destroy(gs_effect_t *effect); void gs_destroy(graphics_t *graphics) { - if (!graphics) + if (!ptr_valid(graphics, "gs_destroy")) return; while (thread_graphics) @@ -219,7 +257,8 @@ void gs_destroy(graphics_t *graphics) void gs_enter_context(graphics_t *graphics) { - if (!graphics) return; + if (!ptr_valid(graphics, "gs_enter_context")) + return; bool is_current = thread_graphics == graphics; if (thread_graphics && !is_current) { @@ -238,7 +277,7 @@ void gs_enter_context(graphics_t *graphics) void gs_leave_context(void) { - if (thread_graphics) { + if (gs_valid("gs_leave_context")) { if (!os_atomic_dec_long(&thread_graphics->ref)) { graphics_t *graphics = thread_graphics; @@ -257,26 +296,26 @@ graphics_t *gs_get_context(void) const char *gs_get_device_name(void) { - return thread_graphics ? + return gs_valid("gs_get_device_name") ? thread_graphics->exports.device_get_name() : NULL; } int gs_get_device_type(void) { - return thread_graphics ? + return gs_valid("gs_get_device_type") ? thread_graphics->exports.device_get_type() : -1; } static inline struct matrix4 *top_matrix(graphics_t *graphics) { - return graphics ? - (graphics->matrix_stack.array + graphics->cur_matrix) : NULL; + return graphics->matrix_stack.array + graphics->cur_matrix; } void gs_matrix_push(void) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_matrix_push")) return; struct matrix4 mat, *top_mat = top_matrix(graphics); @@ -289,7 +328,8 @@ void gs_matrix_push(void) void gs_matrix_pop(void) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_matrix_pop")) return; if (graphics->cur_matrix == 0) { @@ -303,72 +343,121 @@ void gs_matrix_pop(void) void gs_matrix_identity(void) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_identity")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_identity(top_mat); } void gs_matrix_transpose(void) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_transpose")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_transpose(top_mat, top_mat); } void gs_matrix_set(const struct matrix4 *matrix) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_set")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_copy(top_mat, matrix); } void gs_matrix_get(struct matrix4 *dst) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_get")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_copy(dst, top_mat); } void gs_matrix_mul(const struct matrix4 *matrix) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_mul")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_mul(top_mat, matrix, top_mat); } void gs_matrix_rotquat(const struct quat *rot) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_rotquat")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_rotate_i(top_mat, rot, top_mat); } void gs_matrix_rotaa(const struct axisang *rot) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_rotaa")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_rotate_aa_i(top_mat, rot, top_mat); } void gs_matrix_translate(const struct vec3 *pos) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_translate")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_translate3v_i(top_mat, pos, top_mat); } void gs_matrix_scale(const struct vec3 *scale) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; + + if (!gs_valid("gs_matrix_scale")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) matrix4_scale_i(top_mat, scale, top_mat); } void gs_matrix_rotaa4f(float x, float y, float z, float angle) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; struct axisang aa; + if (!gs_valid("gs_matrix_rotaa4f")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) { axisang_set(&aa, x, y, z, angle); matrix4_rotate_aa_i(top_mat, &aa, top_mat); @@ -377,9 +466,13 @@ void gs_matrix_rotaa4f(float x, float y, float z, float angle) void gs_matrix_translate3f(float x, float y, float z) { - struct matrix4 *top_mat = top_matrix(thread_graphics); + struct matrix4 *top_mat; struct vec3 p; + if (!gs_valid("gs_matrix_translate3f")) + return; + + top_mat = top_matrix(thread_graphics); if (top_mat) { vec3_set(&p, x, y, z); matrix4_translate3v_i(top_mat, &p, top_mat); @@ -409,7 +502,8 @@ static inline void reset_immediate_arrays(graphics_t *graphics) void gs_render_start(bool b_new) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_render_start")) return; graphics->using_immediate = !b_new; @@ -445,7 +539,7 @@ void gs_render_stop(enum gs_draw_mode mode) graphics_t *graphics = thread_graphics; size_t i, num; - if (!graphics) + if (!gs_valid("gs_render_stop")) return; num = graphics->verts.num; @@ -509,9 +603,8 @@ gs_vertbuffer_t *gs_render_save(void) graphics_t *graphics = thread_graphics; size_t num_tex, i; - if (!graphics) + if (!gs_valid("gs_render_save")) return NULL; - if (graphics->using_immediate) return NULL; @@ -549,7 +642,10 @@ gs_vertbuffer_t *gs_render_save(void) void gs_vertex2f(float x, float y) { struct vec3 v3; - + + if (!gs_valid("gs_verte")) + return; + vec3_set(&v3, x, y, 0.0f); gs_vertex3v(&v3); } @@ -558,6 +654,9 @@ void gs_vertex3f(float x, float y, float z) { struct vec3 v3; + if (!gs_valid("gs_vertex3f")) + return; + vec3_set(&v3, x, y, z); gs_vertex3v(&v3); } @@ -566,6 +665,9 @@ void gs_normal3f(float x, float y, float z) { struct vec3 v3; + if (!gs_valid("gs_normal3f")) + return; + vec3_set(&v3, x, y, z); gs_normal3v(&v3); } @@ -586,7 +688,8 @@ static inline bool validvertsize(graphics_t *graphics, size_t num, void gs_color(uint32_t color) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_color")) return; if (!validvertsize(graphics, graphics->colors.num, "gs_color")) return; @@ -598,6 +701,9 @@ void gs_texcoord(float x, float y, int unit) { struct vec2 v2; + if (!gs_valid("gs_texcoord")) + return; + vec2_set(&v2, x, y); gs_texcoord2v(&v2, unit); } @@ -606,6 +712,9 @@ void gs_vertex2v(const struct vec2 *v) { struct vec3 v3; + if (!gs_valid("gs_vertex2v")) + return; + vec3_set(&v3, v->x, v->y, 0.0f); gs_vertex3v(&v3); } @@ -613,7 +722,8 @@ void gs_vertex2v(const struct vec2 *v) void gs_vertex3v(const struct vec3 *v) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_vertex3v")) return; if (!validvertsize(graphics, graphics->verts.num, "gs_vertex")) return; @@ -624,7 +734,8 @@ void gs_vertex3v(const struct vec3 *v) void gs_normal3v(const struct vec3 *v) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_normal3v")) return; if (!validvertsize(graphics, graphics->norms.num, "gs_normal")) return; @@ -641,7 +752,8 @@ void gs_color4v(const struct vec4 *v) void gs_texcoord2v(const struct vec2 *v, int unit) { graphics_t *graphics = thread_graphics; - if (!graphics) + + if (!gs_valid("gs_texcoord2v")) return; if (!validvertsize(graphics, graphics->texverts[unit].num, "gs_texcoord")) @@ -658,6 +770,9 @@ input_t *gs_get_input(void) gs_effect_t *gs_get_effect(void) { + if (!gs_valid("gs_get_effect")) + return NULL; + return thread_graphics ? thread_graphics->cur_effect : NULL; } @@ -679,7 +794,7 @@ gs_effect_t *gs_effect_create_from_file(const char *file, char **error_string) char *file_string; gs_effect_t *effect = NULL; - if (!thread_graphics || !file) + if (!gs_valid_p("gs_effect_create_from_file", file)) return NULL; effect = find_cached_effect(file); @@ -701,7 +816,7 @@ gs_effect_t *gs_effect_create_from_file(const char *file, char **error_string) gs_effect_t *gs_effect_create(const char *effect_string, const char *filename, char **error_string) { - if (!thread_graphics || !effect_string) + if (!gs_valid_p("gs_effect_create", effect_string)) return NULL; struct gs_effect *effect = bzalloc(sizeof(struct gs_effect)); @@ -740,7 +855,7 @@ gs_effect_t *gs_effect_create(const char *effect_string, const char *filename, gs_shader_t *gs_vertexshader_create_from_file(const char *file, char **error_string) { - if (!thread_graphics || !file) + if (!gs_valid_p("gs_vertexshader_create_from_file", file)) return NULL; char *file_string; @@ -765,7 +880,7 @@ gs_shader_t *gs_pixelshader_create_from_file(const char *file, char *file_string; gs_shader_t *shader = NULL; - if (!thread_graphics || !file) + if (!gs_valid_p("gs_pixelshader_create_from_file", file)) return NULL; file_string = os_quick_read_utf8_file(file); @@ -850,8 +965,7 @@ void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width, float fcx, fcy; struct gs_vb_data *data; - assert(tex); - if (!tex || !thread_graphics) + if (!gs_valid_p("gs_draw_sprite", tex)) return; if (gs_get_texture_type(tex) != GS_TEXTURE_2D) { @@ -891,18 +1005,22 @@ void gs_draw_cube_backdrop(gs_texture_t *cubetex, const struct quat *rot, void gs_reset_viewport(void) { uint32_t cx, cy; - assert(thread_graphics != NULL); - gs_get_size(&cx, &cy); + if (!gs_valid("gs_reset_viewport")) + return; + + gs_get_size(&cx, &cy); gs_set_viewport(0, 0, (int)cx, (int)cy); } void gs_set_2d_mode(void) { uint32_t cx, cy; - assert(thread_graphics != NULL); - gs_get_size(&cx, &cy); + if (!gs_valid("gs_set_2d_mode")) + return; + + gs_get_size(&cx, &cy); gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -1.0, -1024.0f); } @@ -916,7 +1034,8 @@ void gs_set_3d_mode(double fovy, double znear, double zvar) void gs_viewport_push(void) { - if (!thread_graphics) return; + if (!gs_valid("gs_viewport_push")) + return; struct gs_rect *rect = da_push_back_new( thread_graphics->viewport_stack); @@ -926,7 +1045,10 @@ void gs_viewport_push(void) void gs_viewport_pop(void) { struct gs_rect *rect; - if (!thread_graphics || !thread_graphics->viewport_stack.num) + + if (!gs_valid("gs_viewport_pop")) + return; + if (!thread_graphics->viewport_stack.num) return; rect = da_end(thread_graphics->viewport_stack); @@ -943,7 +1065,7 @@ void gs_texture_set_image(gs_texture_t *tex, const uint8_t *data, int32_t height; int32_t y; - if (!thread_graphics || !tex) + if (!gs_valid_p2("gs_texture_set_image", tex, data)) return; height = (int32_t)gs_texture_get_height(tex); @@ -988,7 +1110,8 @@ void gs_perspective(float angle, float aspect, float near, float far) graphics_t *graphics = thread_graphics; float xmin, xmax, ymin, ymax; - if (!graphics) return; + if (!gs_valid("gs_perspective")) + return; ymax = near * tanf(RAD(angle)*0.5f); ymin = -ymax; @@ -1003,7 +1126,9 @@ void gs_perspective(float angle, float aspect, float near, float far) void gs_blend_state_push(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_blend_state_push")) + return; da_push_back(graphics->blend_state_stack, &graphics->cur_blend_state); } @@ -1013,7 +1138,8 @@ void gs_blend_state_pop(void) graphics_t *graphics = thread_graphics; struct blend_state *state; - if (!graphics) return; + if (!gs_valid("gs_blend_state_pop")) + return; state = da_end(graphics->blend_state_stack); if (!state) @@ -1029,7 +1155,9 @@ void gs_blend_state_pop(void) void gs_reset_blend_state(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_preprocessor_name")) + return; if (!graphics->cur_blend_state.enabled) gs_enable_blending(true); @@ -1048,7 +1176,9 @@ void gs_reset_blend_state(void) const char *gs_preprocessor_name(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_preprocessor_name")) + return NULL; return graphics->exports.device_preprocessor_name(); } @@ -1056,9 +1186,10 @@ const char *gs_preprocessor_name(void) gs_swapchain_t *gs_swapchain_create(const struct gs_init_data *data) { struct gs_init_data new_data = *data; - graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid_p("gs_swapchain_create", data)) + return NULL; if (new_data.num_backbuffers == 0) new_data.num_backbuffers = 1; @@ -1070,7 +1201,9 @@ gs_swapchain_t *gs_swapchain_create(const struct gs_init_data *data) void gs_resize(uint32_t x, uint32_t y) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_resize")) + return; graphics->exports.device_resize(graphics->device, x, y); } @@ -1078,7 +1211,9 @@ void gs_resize(uint32_t x, uint32_t y) void gs_get_size(uint32_t *x, uint32_t *y) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_get_size")) + return; graphics->exports.device_get_size(graphics->device, x, y); } @@ -1086,7 +1221,9 @@ void gs_get_size(uint32_t *x, uint32_t *y) uint32_t gs_get_width(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return 0; + + if (!gs_valid("gs_get_width")) + return 0; return graphics->exports.device_get_width(graphics->device); } @@ -1094,7 +1231,9 @@ uint32_t gs_get_width(void) uint32_t gs_get_height(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return 0; + + if (!gs_valid("gs_get_height")) + return 0; return graphics->exports.device_get_height(graphics->device); } @@ -1112,7 +1251,7 @@ gs_texture_t *gs_texture_create(uint32_t width, uint32_t height, bool pow2tex = is_pow2(width) && is_pow2(height); bool uses_mipmaps = (flags & GS_BUILD_MIPMAPS || levels != 1); - if (!graphics) + if (!gs_valid("gs_texture_create")) return NULL; if (uses_mipmaps && !pow2tex) { @@ -1144,7 +1283,7 @@ gs_texture_t *gs_cubetexture_create(uint32_t size, bool pow2tex = is_pow2(size); bool uses_mipmaps = (flags & GS_BUILD_MIPMAPS || levels != 1); - if (!graphics) + if (!gs_valid("gs_cubetexture_create")) return NULL; if (uses_mipmaps && !pow2tex) { @@ -1174,7 +1313,9 @@ gs_texture_t *gs_voltexture_create(uint32_t width, uint32_t height, uint32_t levels, const uint8_t **data, uint32_t flags) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_voltexture_create")) + return NULL; return graphics->exports.device_voltexture_create(graphics->device, width, height, depth, color_format, levels, data, @@ -1185,7 +1326,9 @@ gs_zstencil_t *gs_zstencil_create(uint32_t width, uint32_t height, enum gs_zstencil_format format) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_zstencil_create")) + return NULL; return graphics->exports.device_zstencil_create(graphics->device, width, height, format); @@ -1195,7 +1338,9 @@ gs_stagesurf_t *gs_stagesurface_create(uint32_t width, uint32_t height, enum gs_color_format color_format) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_stagesurface_create")) + return NULL; return graphics->exports.device_stagesurface_create(graphics->device, width, height, color_format); @@ -1204,7 +1349,9 @@ gs_stagesurf_t *gs_stagesurface_create(uint32_t width, uint32_t height, gs_samplerstate_t *gs_samplerstate_create(const struct gs_sampler_info *info) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid_p("gs_samplerstate_create", info)) + return NULL; return graphics->exports.device_samplerstate_create(graphics->device, info); @@ -1214,7 +1361,9 @@ gs_shader_t *gs_vertexshader_create(const char *shader, const char *file, char **error_string) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid_p("gs_vertexshader_create", shader)) + return NULL; return graphics->exports.device_vertexshader_create(graphics->device, shader, file, error_string); @@ -1224,7 +1373,9 @@ gs_shader_t *gs_pixelshader_create(const char *shader, const char *file, char **error_string) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid_p("gs_pixelshader_create", shader)) + return NULL; return graphics->exports.device_pixelshader_create(graphics->device, shader, file, error_string); @@ -1234,7 +1385,9 @@ gs_vertbuffer_t *gs_vertexbuffer_create(struct gs_vb_data *data, uint32_t flags) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_vertexbuffer_create")) + return NULL; return graphics->exports.device_vertexbuffer_create(graphics->device, data, flags); @@ -1244,7 +1397,9 @@ gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type, void *indices, size_t num, uint32_t flags) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_indexbuffer_create")) + return NULL; return graphics->exports.device_indexbuffer_create(graphics->device, type, indices, num, flags); @@ -1253,7 +1408,9 @@ gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type, enum gs_texture_type gs_get_texture_type(const gs_texture_t *texture) { graphics_t *graphics = thread_graphics; - if (!graphics) return GS_TEXTURE_2D; + + if (!gs_valid_p("gs_get_texture_type", texture)) + return GS_TEXTURE_2D; return graphics->exports.device_get_texture_type(texture); } @@ -1261,7 +1418,9 @@ enum gs_texture_type gs_get_texture_type(const gs_texture_t *texture) void gs_load_vertexbuffer(gs_vertbuffer_t *vertbuffer) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_vertexbuffer")) + return; graphics->exports.device_load_vertexbuffer(graphics->device, vertbuffer); @@ -1270,7 +1429,9 @@ void gs_load_vertexbuffer(gs_vertbuffer_t *vertbuffer) void gs_load_indexbuffer(gs_indexbuffer_t *indexbuffer) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_indexbuffer")) + return; graphics->exports.device_load_indexbuffer(graphics->device, indexbuffer); @@ -1279,7 +1440,9 @@ void gs_load_indexbuffer(gs_indexbuffer_t *indexbuffer) void gs_load_texture(gs_texture_t *tex, int unit) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_texture")) + return; graphics->exports.device_load_texture(graphics->device, tex, unit); } @@ -1287,7 +1450,9 @@ void gs_load_texture(gs_texture_t *tex, int unit) void gs_load_samplerstate(gs_samplerstate_t *samplerstate, int unit) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_samplerstate")) + return; graphics->exports.device_load_samplerstate(graphics->device, samplerstate, unit); @@ -1296,7 +1461,9 @@ void gs_load_samplerstate(gs_samplerstate_t *samplerstate, int unit) void gs_load_vertexshader(gs_shader_t *vertshader) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_vertexshader")) + return; graphics->exports.device_load_vertexshader(graphics->device, vertshader); @@ -1305,7 +1472,9 @@ void gs_load_vertexshader(gs_shader_t *vertshader) void gs_load_pixelshader(gs_shader_t *pixelshader) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_pixelshader")) + return; graphics->exports.device_load_pixelshader(graphics->device, pixelshader); @@ -1314,7 +1483,9 @@ void gs_load_pixelshader(gs_shader_t *pixelshader) void gs_load_default_samplerstate(bool b_3d, int unit) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_default_samplerstate")) + return; graphics->exports.device_load_default_samplerstate(graphics->device, b_3d, unit); @@ -1323,7 +1494,9 @@ void gs_load_default_samplerstate(bool b_3d, int unit) gs_shader_t *gs_get_vertex_shader(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_get_vertex_shader")) + return NULL; return graphics->exports.device_get_vertex_shader(graphics->device); } @@ -1331,7 +1504,9 @@ gs_shader_t *gs_get_vertex_shader(void) gs_shader_t *gs_get_pixel_shader(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_get_pixel_shader")) + return NULL; return graphics->exports.device_get_pixel_shader(graphics->device); } @@ -1339,7 +1514,9 @@ gs_shader_t *gs_get_pixel_shader(void) gs_texture_t *gs_get_render_target(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_get_render_target")) + return NULL; return graphics->exports.device_get_render_target(graphics->device); } @@ -1347,7 +1524,9 @@ gs_texture_t *gs_get_render_target(void) gs_zstencil_t *gs_get_zstencil_target(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_get_zstencil_target")) + return NULL; return graphics->exports.device_get_zstencil_target(graphics->device); } @@ -1355,7 +1534,9 @@ gs_zstencil_t *gs_get_zstencil_target(void) void gs_set_render_target(gs_texture_t *tex, gs_zstencil_t *zstencil) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_set_render_target")) + return; graphics->exports.device_set_render_target(graphics->device, tex, zstencil); @@ -1365,7 +1546,9 @@ void gs_set_cube_render_target(gs_texture_t *cubetex, int side, gs_zstencil_t *zstencil) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_set_cube_render_target")) + return; graphics->exports.device_set_cube_render_target(graphics->device, cubetex, side, zstencil); @@ -1374,7 +1557,9 @@ void gs_set_cube_render_target(gs_texture_t *cubetex, int side, void gs_copy_texture(gs_texture_t *dst, gs_texture_t *src) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid_p2("gs_copy_texture", dst, src)) + return; graphics->exports.device_copy_texture(graphics->device, dst, src); } @@ -1384,7 +1569,9 @@ void gs_copy_texture_region(gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y, uint32_t src_w, uint32_t src_h) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid_p("gs_copy_texture_region", dst)) + return; graphics->exports.device_copy_texture_region(graphics->device, dst, dst_x, dst_y, @@ -1394,7 +1581,9 @@ void gs_copy_texture_region(gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y, void gs_stage_texture(gs_stagesurf_t *dst, gs_texture_t *src) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_stage_texture")) + return; graphics->exports.device_stage_texture(graphics->device, dst, src); } @@ -1402,7 +1591,9 @@ void gs_stage_texture(gs_stagesurf_t *dst, gs_texture_t *src) void gs_begin_scene(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_begin_scene")) + return; graphics->exports.device_begin_scene(graphics->device); } @@ -1411,7 +1602,9 @@ void gs_draw(enum gs_draw_mode draw_mode, uint32_t start_vert, uint32_t num_verts) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_draw")) + return; graphics->exports.device_draw(graphics->device, draw_mode, start_vert, num_verts); @@ -1420,7 +1613,9 @@ void gs_draw(enum gs_draw_mode draw_mode, uint32_t start_vert, void gs_end_scene(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_end_scene")) + return; graphics->exports.device_end_scene(graphics->device); } @@ -1428,7 +1623,9 @@ void gs_end_scene(void) void gs_load_swapchain(gs_swapchain_t *swapchain) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_load_swapchain")) + return; graphics->exports.device_load_swapchain(graphics->device, swapchain); } @@ -1437,6 +1634,10 @@ void gs_clear(uint32_t clear_flags, const struct vec4 *color, float depth, uint8_t stencil) { graphics_t *graphics = thread_graphics; + + if (!gs_valid("gs_clear")) + return; + graphics->exports.device_clear(graphics->device, clear_flags, color, depth, stencil); } @@ -1444,7 +1645,9 @@ void gs_clear(uint32_t clear_flags, const struct vec4 *color, float depth, void gs_present(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_present")) + return; graphics->exports.device_present(graphics->device); } @@ -1452,7 +1655,9 @@ void gs_present(void) void gs_flush(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_flush")) + return; graphics->exports.device_flush(graphics->device); } @@ -1460,7 +1665,9 @@ void gs_flush(void) void gs_set_cull_mode(enum gs_cull_mode mode) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_set_cull_mode")) + return; graphics->exports.device_set_cull_mode(graphics->device, mode); } @@ -1468,7 +1675,9 @@ void gs_set_cull_mode(enum gs_cull_mode mode) enum gs_cull_mode gs_get_cull_mode(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return GS_NEITHER; + + if (!gs_valid("gs_get_cull_mode")) + return GS_NEITHER; return graphics->exports.device_get_cull_mode(graphics->device); } @@ -1476,7 +1685,9 @@ enum gs_cull_mode gs_get_cull_mode(void) void gs_enable_blending(bool enable) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_enable_blending")) + return; graphics->cur_blend_state.enabled = enable; graphics->exports.device_enable_blending(graphics->device, enable); @@ -1485,7 +1696,9 @@ void gs_enable_blending(bool enable) void gs_enable_depth_test(bool enable) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_enable_depth_test")) + return; graphics->exports.device_enable_depth_test(graphics->device, enable); } @@ -1493,7 +1706,9 @@ void gs_enable_depth_test(bool enable) void gs_enable_stencil_test(bool enable) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_enable_stencil_test")) + return; graphics->exports.device_enable_stencil_test(graphics->device, enable); } @@ -1501,7 +1716,9 @@ void gs_enable_stencil_test(bool enable) void gs_enable_stencil_write(bool enable) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_enable_stencil_write")) + return; graphics->exports.device_enable_stencil_write(graphics->device, enable); } @@ -1509,7 +1726,9 @@ void gs_enable_stencil_write(bool enable) void gs_enable_color(bool red, bool green, bool blue, bool alpha) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_enable_color")) + return; graphics->exports.device_enable_color(graphics->device, red, green, blue, alpha); @@ -1518,7 +1737,9 @@ void gs_enable_color(bool red, bool green, bool blue, bool alpha) void gs_blend_function(enum gs_blend_type src, enum gs_blend_type dest) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_blend_function")) + return; graphics->cur_blend_state.src_c = src; graphics->cur_blend_state.dest_c = dest; @@ -1532,7 +1753,9 @@ void gs_blend_function_separate( enum gs_blend_type src_a, enum gs_blend_type dest_a) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_blend_function_separate")) + return; graphics->cur_blend_state.src_c = src_c; graphics->cur_blend_state.dest_c = dest_c; @@ -1545,7 +1768,9 @@ void gs_blend_function_separate( void gs_depth_function(enum gs_depth_test test) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_depth_function")) + return; graphics->exports.device_depth_function(graphics->device, test); } @@ -1553,7 +1778,9 @@ void gs_depth_function(enum gs_depth_test test) void gs_stencil_function(enum gs_stencil_side side, enum gs_depth_test test) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_stencil_function")) + return; graphics->exports.device_stencil_function(graphics->device, side, test); } @@ -1562,7 +1789,9 @@ 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) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_stencil_op")) + return; graphics->exports.device_stencil_op(graphics->device, side, fail, zfail, zpass); @@ -1571,7 +1800,9 @@ void gs_stencil_op(enum gs_stencil_side side, enum gs_stencil_op_type fail, void gs_set_viewport(int x, int y, int width, int height) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_set_viewport")) + return; graphics->exports.device_set_viewport(graphics->device, x, y, width, height); @@ -1580,7 +1811,9 @@ void gs_set_viewport(int x, int y, int width, int height) void gs_get_viewport(struct gs_rect *rect) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid_p("gs_get_viewport", rect)) + return; graphics->exports.device_get_viewport(graphics->device, rect); } @@ -1588,7 +1821,9 @@ void gs_get_viewport(struct gs_rect *rect) void gs_set_scissor_rect(const struct gs_rect *rect) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_set_scissor_rect")) + return; graphics->exports.device_set_scissor_rect(graphics->device, rect); } @@ -1597,7 +1832,9 @@ void gs_ortho(float left, float right, float top, float bottom, float znear, float zfar) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_ortho")) + return; graphics->exports.device_ortho(graphics->device, left, right, top, bottom, znear, zfar); @@ -1607,7 +1844,9 @@ void gs_frustum(float left, float right, float top, float bottom, float znear, float zfar) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_frustum")) + return; graphics->exports.device_frustum(graphics->device, left, right, top, bottom, znear, zfar); @@ -1616,7 +1855,9 @@ void gs_frustum(float left, float right, float top, float bottom, float znear, void gs_projection_push(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_projection_push")) + return; graphics->exports.device_projection_push(graphics->device); } @@ -1624,7 +1865,9 @@ void gs_projection_push(void) void gs_projection_pop(void) { graphics_t *graphics = thread_graphics; - if (!graphics) return; + + if (!gs_valid("gs_projection_pop")) + return; graphics->exports.device_projection_pop(graphics->device); } @@ -1632,7 +1875,9 @@ void gs_projection_pop(void) void gs_swapchain_destroy(gs_swapchain_t *swapchain) { graphics_t *graphics = thread_graphics; - if (!graphics || !swapchain) return; + + if (!gs_valid_p("gs_swapchain_destroy", swapchain)) + return; graphics->exports.gs_swapchain_destroy(swapchain); } @@ -1640,7 +1885,9 @@ void gs_swapchain_destroy(gs_swapchain_t *swapchain) void gs_shader_destroy(gs_shader_t *shader) { graphics_t *graphics = thread_graphics; - if (!graphics || !shader) return; + + if (!gs_valid_p("gs_shader_destroy", shader)) + return; graphics->exports.gs_shader_destroy(shader); } @@ -1648,7 +1895,9 @@ void gs_shader_destroy(gs_shader_t *shader) int gs_shader_get_num_params(const gs_shader_t *shader) { graphics_t *graphics = thread_graphics; - if (!graphics || !shader) return 0; + + if (!gs_valid_p("gs_shader_get_num_params", shader)) + return 0; return graphics->exports.gs_shader_get_num_params(shader); } @@ -1656,7 +1905,9 @@ 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) { graphics_t *graphics = thread_graphics; - if (!graphics || !shader) return NULL; + + if (!gs_valid_p("gs_shader_get_param_by_idx", shader)) + return NULL; return graphics->exports.gs_shader_get_param_by_idx(shader, param); } @@ -1664,7 +1915,9 @@ gs_sparam_t *gs_shader_get_param_by_idx(gs_shader_t *shader, uint32_t param) gs_sparam_t *gs_shader_get_param_by_name(gs_shader_t *shader, const char *name) { graphics_t *graphics = thread_graphics; - if (!graphics || !shader) return NULL; + + if (!gs_valid_p2("gs_shader_get_param_by_name", shader, name)) + return NULL; return graphics->exports.gs_shader_get_param_by_name(shader, name); } @@ -1672,7 +1925,9 @@ gs_sparam_t *gs_shader_get_param_by_name(gs_shader_t *shader, const char *name) gs_sparam_t *gs_shader_get_viewproj_matrix(const gs_shader_t *shader) { graphics_t *graphics = thread_graphics; - if (!graphics || !shader) return NULL; + + if (!gs_valid_p("gs_shader_get_viewproj_matrix", shader)) + return NULL; return graphics->exports.gs_shader_get_viewproj_matrix(shader); } @@ -1680,7 +1935,9 @@ gs_sparam_t *gs_shader_get_viewproj_matrix(const gs_shader_t *shader) gs_sparam_t *gs_shader_get_world_matrix(const gs_shader_t *shader) { graphics_t *graphics = thread_graphics; - if (!graphics || !shader) return NULL; + + if (!gs_valid_p("gs_shader_get_world_matrix", shader)) + return NULL; return graphics->exports.gs_shader_get_world_matrix(shader); } @@ -1689,7 +1946,9 @@ void gs_shader_get_param_info(const gs_sparam_t *param, struct gs_shader_param_info *info) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_get_param_info", param, info)) + return; graphics->exports.gs_shader_get_param_info(param, info); } @@ -1697,7 +1956,9 @@ void gs_shader_get_param_info(const gs_sparam_t *param, void gs_shader_set_bool(gs_sparam_t *param, bool val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p("gs_shader_set_bool", param)) + return; graphics->exports.gs_shader_set_bool(param, val); } @@ -1705,7 +1966,9 @@ void gs_shader_set_bool(gs_sparam_t *param, bool val) void gs_shader_set_float(gs_sparam_t *param, float val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p("gs_shader_set_float", param)) + return; graphics->exports.gs_shader_set_float(param, val); } @@ -1713,7 +1976,9 @@ void gs_shader_set_float(gs_sparam_t *param, float val) void gs_shader_set_int(gs_sparam_t *param, int val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p("gs_shader_set_int", param)) + return; graphics->exports.gs_shader_set_int(param, val); } @@ -1721,7 +1986,9 @@ void gs_shader_set_int(gs_sparam_t *param, int val) void gs_shader_setmatrix3(gs_sparam_t *param, const struct matrix3 *val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_setmatrix3", param, val)) + return; graphics->exports.gs_shader_setmatrix3(param, val); } @@ -1729,7 +1996,9 @@ void gs_shader_setmatrix3(gs_sparam_t *param, const struct matrix3 *val) void gs_shader_set_matrix4(gs_sparam_t *param, const struct matrix4 *val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_set_matrix4", param, val)) + return; graphics->exports.gs_shader_set_matrix4(param, val); } @@ -1737,7 +2006,9 @@ void gs_shader_set_matrix4(gs_sparam_t *param, const struct matrix4 *val) void gs_shader_set_vec2(gs_sparam_t *param, const struct vec2 *val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_set_vec2", param, val)) + return; graphics->exports.gs_shader_set_vec2(param, val); } @@ -1745,7 +2016,9 @@ void gs_shader_set_vec2(gs_sparam_t *param, const struct vec2 *val) void gs_shader_set_vec3(gs_sparam_t *param, const struct vec3 *val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_set_vec3", param, val)) + return; graphics->exports.gs_shader_set_vec3(param, val); } @@ -1753,7 +2026,9 @@ void gs_shader_set_vec3(gs_sparam_t *param, const struct vec3 *val) void gs_shader_set_vec4(gs_sparam_t *param, const struct vec4 *val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_set_vec4", param, val)) + return; graphics->exports.gs_shader_set_vec4(param, val); } @@ -1761,7 +2036,9 @@ void gs_shader_set_vec4(gs_sparam_t *param, const struct vec4 *val) void gs_shader_set_texture(gs_sparam_t *param, gs_texture_t *val) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p("gs_shader_set_texture", param)) + return; graphics->exports.gs_shader_set_texture(param, val); } @@ -1769,7 +2046,9 @@ void gs_shader_set_texture(gs_sparam_t *param, gs_texture_t *val) void gs_shader_set_val(gs_sparam_t *param, const void *val, size_t size) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p2("gs_shader_set_val", param, val)) + return; graphics->exports.gs_shader_set_val(param, val, size); } @@ -1777,7 +2056,9 @@ void gs_shader_set_val(gs_sparam_t *param, const void *val, size_t size) void gs_shader_set_default(gs_sparam_t *param) { graphics_t *graphics = thread_graphics; - if (!graphics || !param) return; + + if (!gs_valid_p("gs_shader_set_default", param)) + return; graphics->exports.gs_shader_set_default(param); } @@ -1785,7 +2066,9 @@ void gs_shader_set_default(gs_sparam_t *param) void gs_texture_destroy(gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return; + + if (!gs_valid_p("gs_texture_destroy", tex)) + return; graphics->exports.gs_texture_destroy(tex); } @@ -1793,7 +2076,9 @@ void gs_texture_destroy(gs_texture_t *tex) uint32_t gs_texture_get_width(const gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return 0; + + if (!gs_valid_p("gs_texture_get_width", tex)) + return 0; return graphics->exports.gs_texture_get_width(tex); } @@ -1801,7 +2086,9 @@ uint32_t gs_texture_get_width(const gs_texture_t *tex) uint32_t gs_texture_get_height(const gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return 0; + + if (!gs_valid_p("gs_texture_get_height", tex)) + return 0; return graphics->exports.gs_texture_get_height(tex); } @@ -1809,7 +2096,9 @@ uint32_t gs_texture_get_height(const gs_texture_t *tex) enum gs_color_format gs_texture_get_color_format(const gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return GS_UNKNOWN; + + if (!gs_valid_p("gs_texture_get_color_format", tex)) + return GS_UNKNOWN; return graphics->exports.gs_texture_get_color_format(tex); } @@ -1817,7 +2106,9 @@ 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) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return false; + + if (!gs_valid_p3("gs_texture_map", tex, ptr, linesize)) + return false; return graphics->exports.gs_texture_map(tex, ptr, linesize); } @@ -1825,7 +2116,9 @@ bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr, uint32_t *linesize) void gs_texture_unmap(gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return; + + if (!gs_valid_p("gs_texture_unmap", tex)) + return; graphics->exports.gs_texture_unmap(tex); } @@ -1833,7 +2126,9 @@ void gs_texture_unmap(gs_texture_t *tex) bool gs_texture_is_rect(const gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return false; + + if (!gs_valid_p("gs_texture_is_rect", tex)) + return false; if (graphics->exports.gs_texture_is_rect) return graphics->exports.gs_texture_is_rect(tex); @@ -1844,7 +2139,9 @@ bool gs_texture_is_rect(const gs_texture_t *tex) void *gs_texture_get_obj(gs_texture_t *tex) { graphics_t *graphics = thread_graphics; - if (!graphics || !tex) return NULL; + + if (!gs_valid_p("gs_texture_get_obj", tex)) + return NULL; return graphics->exports.gs_texture_get_obj(tex); } @@ -1852,7 +2149,9 @@ void *gs_texture_get_obj(gs_texture_t *tex) void gs_cubetexture_destroy(gs_texture_t *cubetex) { graphics_t *graphics = thread_graphics; - if (!graphics || !cubetex) return; + + if (!gs_valid_p("gs_cubetexture_destroy", cubetex)) + return; graphics->exports.gs_cubetexture_destroy(cubetex); } @@ -1860,7 +2159,9 @@ void gs_cubetexture_destroy(gs_texture_t *cubetex) uint32_t gs_cubetexture_get_size(const gs_texture_t *cubetex) { graphics_t *graphics = thread_graphics; - if (!graphics || !cubetex) return 0; + + if (!gs_valid_p("gs_cubetexture_get_size", cubetex)) + return 0; return graphics->exports.gs_cubetexture_get_size(cubetex); } @@ -1869,7 +2170,9 @@ enum gs_color_format gs_cubetexture_get_color_format( const gs_texture_t *cubetex) { graphics_t *graphics = thread_graphics; - if (!graphics || !cubetex) return GS_UNKNOWN; + + if (!gs_valid_p("gs_cubetexture_get_color_format", cubetex)) + return GS_UNKNOWN; return graphics->exports.gs_cubetexture_get_color_format(cubetex); } @@ -1877,7 +2180,9 @@ enum gs_color_format gs_cubetexture_get_color_format( void gs_voltexture_destroy(gs_texture_t *voltex) { graphics_t *graphics = thread_graphics; - if (!graphics || !voltex) return; + + if (!gs_valid_p("gs_voltexture_destroy", voltex)) + return; graphics->exports.gs_voltexture_destroy(voltex); } @@ -1885,7 +2190,9 @@ void gs_voltexture_destroy(gs_texture_t *voltex) uint32_t gs_voltexture_get_width(const gs_texture_t *voltex) { graphics_t *graphics = thread_graphics; - if (!graphics || !voltex) return 0; + + if (!gs_valid_p("gs_voltexture_get_width", voltex)) + return 0; return graphics->exports.gs_voltexture_get_width(voltex); } @@ -1893,7 +2200,9 @@ uint32_t gs_voltexture_get_width(const gs_texture_t *voltex) uint32_t gs_voltexture_get_height(const gs_texture_t *voltex) { graphics_t *graphics = thread_graphics; - if (!graphics || !voltex) return 0; + + if (!gs_valid_p("gs_voltexture_get_height", voltex)) + return 0; return graphics->exports.gs_voltexture_get_height(voltex); } @@ -1901,7 +2210,9 @@ uint32_t gs_voltexture_get_height(const gs_texture_t *voltex) uint32_t gs_voltexture_getdepth(const gs_texture_t *voltex) { graphics_t *graphics = thread_graphics; - if (!graphics || !voltex) return 0; + + if (!gs_valid_p("gs_voltexture_getdepth", voltex)) + return 0; return graphics->exports.gs_voltexture_getdepth(voltex); } @@ -1909,7 +2220,9 @@ uint32_t gs_voltexture_getdepth(const gs_texture_t *voltex) enum gs_color_format gs_voltexture_get_color_format(const gs_texture_t *voltex) { graphics_t *graphics = thread_graphics; - if (!graphics || !voltex) return GS_UNKNOWN; + + if (!gs_valid_p("gs_voltexture_get_color_format", voltex)) + return GS_UNKNOWN; return graphics->exports.gs_voltexture_get_color_format(voltex); } @@ -1917,7 +2230,9 @@ enum gs_color_format gs_voltexture_get_color_format(const gs_texture_t *voltex) void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !stagesurf) return; + + if (!gs_valid_p("gs_stagesurface_destroy", stagesurf)) + return; graphics->exports.gs_stagesurface_destroy(stagesurf); } @@ -1925,7 +2240,9 @@ void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf) uint32_t gs_stagesurface_get_width(const gs_stagesurf_t *stagesurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !stagesurf) return 0; + + if (!gs_valid_p("gs_stagesurface_get_width", stagesurf)) + return 0; return graphics->exports.gs_stagesurface_get_width(stagesurf); } @@ -1933,7 +2250,9 @@ uint32_t gs_stagesurface_get_width(const gs_stagesurf_t *stagesurf) uint32_t gs_stagesurface_get_height(const gs_stagesurf_t *stagesurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !stagesurf) return 0; + + if (!gs_valid_p("gs_stagesurface_get_height", stagesurf)) + return 0; return graphics->exports.gs_stagesurface_get_height(stagesurf); } @@ -1942,7 +2261,9 @@ enum gs_color_format gs_stagesurface_get_color_format( const gs_stagesurf_t *stagesurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !stagesurf) return GS_UNKNOWN; + + if (!gs_valid_p("gs_stagesurface_get_color_format", stagesurf)) + return GS_UNKNOWN; return graphics->exports.gs_stagesurface_get_color_format(stagesurf); } @@ -1951,7 +2272,9 @@ bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data, uint32_t *linesize) { graphics_t *graphics = thread_graphics; - if (!graphics || !stagesurf) return false; + + if (!gs_valid_p3("gs_stagesurface_map", stagesurf, data, linesize)) + return 0; return graphics->exports.gs_stagesurface_map(stagesurf, data, linesize); } @@ -1959,21 +2282,25 @@ bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data, void gs_stagesurface_unmap(gs_stagesurf_t *stagesurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !stagesurf) return; + + if (!gs_valid_p("gs_stagesurface_unmap", stagesurf)) + return; graphics->exports.gs_stagesurface_unmap(stagesurf); } void gs_zstencil_destroy(gs_zstencil_t *zstencil) { - if (!thread_graphics || !zstencil) return; + if (!gs_valid_p("gs_zstencil_destroy", zstencil)) + return; thread_graphics->exports.gs_zstencil_destroy(zstencil); } void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate) { - if (!thread_graphics || !samplerstate) return; + if (!gs_valid_p("gs_samplerstate_destroy", samplerstate)) + return; thread_graphics->exports.gs_samplerstate_destroy(samplerstate); } @@ -1981,21 +2308,25 @@ void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate) void gs_vertexbuffer_destroy(gs_vertbuffer_t *vertbuffer) { graphics_t *graphics = thread_graphics; - if (!graphics || !vertbuffer) return; + + if (!gs_valid_p("gs_vertexbuffer_destroy", vertbuffer)) + return; graphics->exports.gs_vertexbuffer_destroy(vertbuffer); } void gs_vertexbuffer_flush(gs_vertbuffer_t *vertbuffer) { - if (!thread_graphics || !vertbuffer) return; + if (!gs_valid_p("gs_vertexbuffer_flush", vertbuffer)) + return; thread_graphics->exports.gs_vertexbuffer_flush(vertbuffer); } struct gs_vb_data *gs_vertexbuffer_get_data(const gs_vertbuffer_t *vertbuffer) { - if (!thread_graphics || !vertbuffer) return NULL; + if (!gs_valid_p("gs_vertexbuffer_get_data", vertbuffer)) + return NULL; return thread_graphics->exports.gs_vertexbuffer_get_data(vertbuffer); } @@ -2003,28 +2334,33 @@ struct gs_vb_data *gs_vertexbuffer_get_data(const gs_vertbuffer_t *vertbuffer) void gs_indexbuffer_destroy(gs_indexbuffer_t *indexbuffer) { graphics_t *graphics = thread_graphics; - if (!graphics || !indexbuffer) return; + + if (!gs_valid_p("gs_indexbuffer_destroy", indexbuffer)) + return; graphics->exports.gs_indexbuffer_destroy(indexbuffer); } void gs_indexbuffer_flush(gs_indexbuffer_t *indexbuffer) { - if (!thread_graphics || !indexbuffer) return; + if (!gs_valid_p("gs_indexbuffer_flush", indexbuffer)) + return; thread_graphics->exports.gs_indexbuffer_flush(indexbuffer); } void *gs_indexbuffer_get_data(const gs_indexbuffer_t *indexbuffer) { - if (!thread_graphics || !indexbuffer) return NULL; + if (!gs_valid_p("gs_indexbuffer_get_data", indexbuffer)) + return NULL; return thread_graphics->exports.gs_indexbuffer_get_data(indexbuffer); } size_t gs_indexbuffer_get_num_indices(const gs_indexbuffer_t *indexbuffer) { - if (!thread_graphics || !indexbuffer) return 0; + if (!gs_valid_p("gs_indexbuffer_get_num_indices", indexbuffer)) + return 0; return thread_graphics->exports.gs_indexbuffer_get_num_indices( indexbuffer); @@ -2032,7 +2368,8 @@ size_t gs_indexbuffer_get_num_indices(const gs_indexbuffer_t *indexbuffer) enum gs_index_type gs_indexbuffer_get_type(const gs_indexbuffer_t *indexbuffer) { - if (!thread_graphics || !indexbuffer) return (enum gs_index_type)0; + if (!gs_valid_p("gs_indexbuffer_get_type", indexbuffer)) + return (enum gs_index_type)0; return thread_graphics->exports.gs_indexbuffer_get_type(indexbuffer); } @@ -2043,8 +2380,10 @@ enum gs_index_type gs_indexbuffer_get_type(const gs_indexbuffer_t *indexbuffer) gs_texture_t *gs_texture_create_from_iosurface(void *iosurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !iosurf || - !graphics->exports.device_texture_create_from_iosurface) + + if (!gs_valid_p("gs_texture_create_from_iosurface", iosurf)) + return NULL; + if (!graphics->exports.device_texture_create_from_iosurface) return NULL; return graphics->exports.device_texture_create_from_iosurface( @@ -2054,8 +2393,10 @@ gs_texture_t *gs_texture_create_from_iosurface(void *iosurf) bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf) { graphics_t *graphics = thread_graphics; - if (!graphics || !iosurf || - !graphics->exports.gs_texture_rebind_iosurface) + + if (!gs_valid_p("gs_texture_rebind_iosurface", texture)) + return false; + if (!graphics->exports.gs_texture_rebind_iosurface) return false; return graphics->exports.gs_texture_rebind_iosurface(texture, iosurf); @@ -2065,7 +2406,7 @@ bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf) bool gs_gdi_texture_available(void) { - if (!thread_graphics) + if (!gs_valid("gs_gdi_texture_available")) return false; return thread_graphics->exports.device_gdi_texture_available(); @@ -2073,7 +2414,7 @@ bool gs_gdi_texture_available(void) bool gs_shared_texture_available(void) { - if (!thread_graphics) + if (!gs_valid("gs_shared_texture_available")) return false; return thread_graphics->exports.device_shared_texture_available(); @@ -2082,7 +2423,7 @@ bool gs_shared_texture_available(void) bool gs_get_duplicator_monitor_info(int monitor_idx, struct gs_monitor_info *monitor_info) { - if (!thread_graphics) + if (!gs_valid_p("gs_get_duplicator_monitor_info", monitor_info)) return false; if (!thread_graphics->exports.device_get_duplicator_monitor_info) return false; @@ -2094,7 +2435,7 @@ bool gs_get_duplicator_monitor_info(int monitor_idx, gs_duplicator_t *gs_duplicator_create(int monitor_idx) { - if (!thread_graphics) + if (!gs_valid("gs_duplicator_create")) return NULL; if (!thread_graphics->exports.device_duplicator_create) return NULL; @@ -2105,7 +2446,7 @@ gs_duplicator_t *gs_duplicator_create(int monitor_idx) void gs_duplicator_destroy(gs_duplicator_t *duplicator) { - if (!thread_graphics) + if (!gs_valid_p("gs_duplicator_destroy", duplicator)) return; if (!thread_graphics->exports.gs_duplicator_destroy) return; @@ -2115,17 +2456,17 @@ void gs_duplicator_destroy(gs_duplicator_t *duplicator) bool gs_duplicator_update_frame(gs_duplicator_t *duplicator) { - if (!thread_graphics) - return true; + if (!gs_valid_p("gs_duplicator_update_frame", duplicator)) + return false; if (!thread_graphics->exports.gs_duplicator_get_texture) - return true; + return false; return thread_graphics->exports.gs_duplicator_update_frame(duplicator); } gs_texture_t *gs_duplicator_get_texture(gs_duplicator_t *duplicator) { - if (!thread_graphics) + if (!gs_valid_p("gs_duplicator_get_texture", duplicator)) return NULL; if (!thread_graphics->exports.gs_duplicator_get_texture) return NULL; @@ -2137,7 +2478,9 @@ gs_texture_t *gs_duplicator_get_texture(gs_duplicator_t *duplicator) gs_texture_t *gs_texture_create_gdi(uint32_t width, uint32_t height) { graphics_t *graphics = thread_graphics; - if (!graphics) return NULL; + + if (!gs_valid("gs_texture_create_gdi")) + return NULL; if (graphics->exports.device_texture_create_gdi) return graphics->exports.device_texture_create_gdi( @@ -2147,7 +2490,7 @@ gs_texture_t *gs_texture_create_gdi(uint32_t width, uint32_t height) void *gs_texture_get_dc(gs_texture_t *gdi_tex) { - if (!thread_graphics || !gdi_tex) + if (!gs_valid_p("gs_texture_release_dc", gdi_tex)) return NULL; if (thread_graphics->exports.gs_texture_get_dc) @@ -2157,7 +2500,7 @@ void *gs_texture_get_dc(gs_texture_t *gdi_tex) void gs_texture_release_dc(gs_texture_t *gdi_tex) { - if (!thread_graphics || !gdi_tex) + if (!gs_valid_p("gs_texture_release_dc", gdi_tex)) return; if (thread_graphics->exports.gs_texture_release_dc) @@ -2167,7 +2510,7 @@ void gs_texture_release_dc(gs_texture_t *gdi_tex) gs_texture_t *gs_texture_open_shared(uint32_t handle) { graphics_t *graphics = thread_graphics; - if (!graphics) + if (!gs_valid("gs_texture_open_shared")) return NULL; if (graphics->exports.device_texture_open_shared)