New upstream version 24.0.1+dfsg1

This commit is contained in:
Sebastian Ramacher 2019-09-22 23:19:10 +02:00
parent b14f9eae6d
commit 5a730d6ec3
842 changed files with 42245 additions and 33385 deletions

View file

@ -22,13 +22,13 @@ void axisang_from_quat(struct axisang *dst, const struct quat *q)
{
float len, leni;
len = q->x*q->x + q->y*q->y + q->z*q->z;
len = q->x * q->x + q->y * q->y + q->z * q->z;
if (!close_float(len, 0.0f, EPSILON)) {
leni = 1.0f/sqrtf(len);
leni = 1.0f / sqrtf(len);
dst->x = q->x * leni;
dst->y = q->y * leni;
dst->z = q->z * leni;
dst->w = acosf(q->w)*2.0f;
dst->w = acosf(q->w) * 2.0f;
} else {
dst->x = 0.0f;
dst->y = 0.0f;

View file

@ -27,7 +27,9 @@ struct quat;
struct axisang {
union {
struct {float x, y, z, w;};
struct {
float x, y, z, w;
};
float ptr[4];
};
};
@ -49,7 +51,7 @@ static inline void axisang_copy(struct axisang *dst, struct axisang *aa)
}
static inline void axisang_set(struct axisang *dst, float x, float y, float z,
float w)
float w)
{
dst->x = x;
dst->y = y;

View file

@ -22,35 +22,34 @@
#include "plane.h"
void bounds_move(struct bounds *dst, const struct bounds *b,
const struct vec3 *v)
const struct vec3 *v)
{
vec3_add(&dst->min, &b->min, v);
vec3_add(&dst->max, &b->max, v);
}
void bounds_scale(struct bounds *dst, const struct bounds *b,
const struct vec3 *v)
const struct vec3 *v)
{
vec3_mul(&dst->min, &b->min, v);
vec3_mul(&dst->max, &b->max, v);
}
void bounds_merge(struct bounds *dst, const struct bounds *b1,
const struct bounds *b2)
const struct bounds *b2)
{
vec3_min(&dst->min, &b1->min, &b2->min);
vec3_max(&dst->max, &b1->max, &b2->max);
}
void bounds_merge_point(struct bounds *dst, const struct bounds *b,
const struct vec3 *v)
const struct vec3 *v)
{
vec3_min(&dst->min, &b->min, v);
vec3_max(&dst->max, &b->max, v);
}
void bounds_get_point(struct vec3 *dst, const struct bounds *b,
unsigned int i)
void bounds_get_point(struct vec3 *dst, const struct bounds *b, unsigned int i)
{
if (i > 8)
return;
@ -68,11 +67,19 @@ void bounds_get_point(struct vec3 *dst, const struct bounds *b,
* 7 = MAX.x,MAX.y,MAX.z
*/
if(i > 3) {dst->x = b->max.x; i -= 4;}
else {dst->x = b->min.x;}
if (i > 3) {
dst->x = b->max.x;
i -= 4;
} else {
dst->x = b->min.x;
}
if(i > 1) {dst->y = b->max.y; i -= 2;}
else {dst->y = b->min.y;}
if (i > 1) {
dst->y = b->max.y;
i -= 2;
} else {
dst->y = b->min.y;
}
dst->z = (i == 1) ? b->max.z : b->min.z;
}
@ -85,7 +92,7 @@ void bounds_get_center(struct vec3 *dst, const struct bounds *b)
}
void bounds_transform(struct bounds *dst, const struct bounds *b,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct bounds temp;
bool b_init = false;
@ -124,7 +131,7 @@ void bounds_transform(struct bounds *dst, const struct bounds *b,
}
void bounds_transform3x4(struct bounds *dst, const struct bounds *b,
const struct matrix3 *m)
const struct matrix3 *m)
{
struct bounds temp;
bool b_init = false;
@ -163,7 +170,7 @@ void bounds_transform3x4(struct bounds *dst, const struct bounds *b,
}
bool bounds_intersection_ray(const struct bounds *b, const struct vec3 *orig,
const struct vec3 *dir, float *t)
const struct vec3 *dir, float *t)
{
float t_max = M_INFINITE;
float t_min = -M_INFINITE;
@ -179,22 +186,26 @@ bool bounds_intersection_ray(const struct bounds *b, const struct vec3 *orig,
float f = dir->ptr[i];
if (fabsf(f) > 0.0f) {
float fi = 1.0f/f;
float t1 = (e+max_offset.ptr[i])*fi;
float t2 = (e-max_offset.ptr[i])*fi;
float fi = 1.0f / f;
float t1 = (e + max_offset.ptr[i]) * fi;
float t2 = (e - max_offset.ptr[i]) * fi;
if (t1 > t2) {
if (t2 > t_min) t_min = t2;
if (t1 < t_max) t_max = t1;
if (t2 > t_min)
t_min = t2;
if (t1 < t_max)
t_max = t1;
} else {
if (t1 > t_min) t_min = t1;
if (t2 < t_max) t_max = t2;
if (t1 > t_min)
t_min = t1;
if (t2 < t_max)
t_max = t2;
}
if (t_min > t_max)
return false;
if (t_max < 0.0f)
return false;
} else if ((-e - max_offset.ptr[i]) > 0.0f ||
(-e + max_offset.ptr[i]) < 0.0f) {
(-e + max_offset.ptr[i]) < 0.0f) {
return false;
}
}
@ -204,7 +215,7 @@ bool bounds_intersection_ray(const struct bounds *b, const struct vec3 *orig,
}
bool bounds_intersection_line(const struct bounds *b, const struct vec3 *p1,
const struct vec3 *p2, float *t)
const struct vec3 *p2, float *t)
{
struct vec3 dir;
float length;
@ -214,7 +225,7 @@ bool bounds_intersection_line(const struct bounds *b, const struct vec3 *p1,
if (length <= TINY_EPSILON)
return false;
vec3_mulf(&dir, &dir, 1.0f/length);
vec3_mulf(&dir, &dir, 1.0f / length);
if (!bounds_intersection_ray(b, p1, &dir, t))
return false;
@ -259,7 +270,7 @@ bool bounds_under_plane(const struct bounds *b, const struct plane *p)
}
bool bounds_intersects(const struct bounds *b, const struct bounds *test,
float epsilon)
float epsilon)
{
return ((b->min.x - test->max.x) <= epsilon) &&
((test->min.x - b->max.x) <= epsilon) &&
@ -270,7 +281,7 @@ bool bounds_intersects(const struct bounds *b, const struct bounds *test,
}
bool bounds_intersects_obb(const struct bounds *b, const struct bounds *test,
const struct matrix4 *m, float epsilon)
const struct matrix4 *m, float epsilon)
{
struct bounds b_tr, test_tr;
struct matrix4 m_inv;
@ -285,7 +296,7 @@ bool bounds_intersects_obb(const struct bounds *b, const struct bounds *test,
}
bool bounds_intersects_obb3x4(const struct bounds *b, const struct bounds *test,
const struct matrix3 *m, float epsilon)
const struct matrix3 *m, float epsilon)
{
struct bounds b_tr, test_tr;
struct matrix3 m_inv;
@ -300,7 +311,7 @@ bool bounds_intersects_obb3x4(const struct bounds *b, const struct bounds *test,
}
static inline float vec3or_offset_len(const struct bounds *b,
const struct vec3 *v)
const struct vec3 *v)
{
struct vec3 temp1, temp2;
vec3_sub(&temp1, &b->max, &b->min);

View file

@ -33,7 +33,7 @@ extern "C" {
#define BOUNDS_MAX_Z 4
#define BOUNDS_OUTSIDE 1
#define BOUNDS_INSIDE 2
#define BOUNDS_INSIDE 2
#define BOUNDS_PARTIAL 3
struct bounds {
@ -53,18 +53,18 @@ static inline void bounds_copy(struct bounds *dst, const struct bounds *b)
}
EXPORT void bounds_move(struct bounds *dst, const struct bounds *b,
const struct vec3 *v);
const struct vec3 *v);
EXPORT void bounds_scale(struct bounds *dst, const struct bounds *b,
const struct vec3 *v);
const struct vec3 *v);
EXPORT void bounds_merge(struct bounds *dst, const struct bounds *b1,
const struct bounds *b2);
const struct bounds *b2);
EXPORT void bounds_merge_point(struct bounds *dst, const struct bounds *b,
const struct vec3 *v);
const struct vec3 *v);
EXPORT void bounds_get_point(struct vec3 *dst, const struct bounds *b,
unsigned int i);
unsigned int i);
EXPORT void bounds_get_center(struct vec3 *dst, const struct bounds *b);
/**
@ -72,59 +72,56 @@ EXPORT void bounds_get_center(struct vec3 *dst, const struct bounds *b);
* the actual size becoming larger than it originally was.
*/
EXPORT void bounds_transform(struct bounds *dst, const struct bounds *b,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void bounds_transform3x4(struct bounds *dst, const struct bounds *b,
const struct matrix3 *m);
const struct matrix3 *m);
EXPORT bool bounds_intersection_ray(const struct bounds *b,
const struct vec3 *orig, const struct vec3 *dir, float *t);
const struct vec3 *orig,
const struct vec3 *dir, float *t);
EXPORT bool bounds_intersection_line(const struct bounds *b,
const struct vec3 *p1, const struct vec3 *p2, float *t);
const struct vec3 *p1,
const struct vec3 *p2, float *t);
EXPORT bool bounds_plane_test(const struct bounds *b, const struct plane *p);
EXPORT bool bounds_under_plane(const struct bounds *b,
const struct plane *p);
EXPORT bool bounds_under_plane(const struct bounds *b, const struct plane *p);
static inline bool bounds_inside(const struct bounds *b,
const struct bounds *test)
const struct bounds *test)
{
return test->min.x >= b->min.x &&
test->min.y >= b->min.y &&
test->min.z >= b->min.z &&
test->max.x <= b->max.x &&
test->max.y <= b->max.y &&
test->max.z <= b->max.z;
return test->min.x >= b->min.x && test->min.y >= b->min.y &&
test->min.z >= b->min.z && test->max.x <= b->max.x &&
test->max.y <= b->max.y && test->max.z <= b->max.z;
}
static inline bool bounds_vec3_inside(const struct bounds *b,
const struct vec3 *v)
const struct vec3 *v)
{
return v->x >= (b->min.x-EPSILON) &&
v->x <= (b->max.x+EPSILON) &&
v->y >= (b->min.y-EPSILON) &&
v->y <= (b->max.y+EPSILON) &&
v->z >= (b->min.z-EPSILON) &&
v->z <= (b->max.z+EPSILON);
return v->x >= (b->min.x - EPSILON) && v->x <= (b->max.x + EPSILON) &&
v->y >= (b->min.y - EPSILON) && v->y <= (b->max.y + EPSILON) &&
v->z >= (b->min.z - EPSILON) && v->z <= (b->max.z + EPSILON);
}
EXPORT bool bounds_intersects(const struct bounds *b,
const struct bounds *test, float epsilon);
EXPORT bool bounds_intersects(const struct bounds *b, const struct bounds *test,
float epsilon);
EXPORT bool bounds_intersects_obb(const struct bounds *b,
const struct bounds *test, const struct matrix4 *m,
float epsilon);
const struct bounds *test,
const struct matrix4 *m, float epsilon);
EXPORT bool bounds_intersects_obb3x4(const struct bounds *b,
const struct bounds *test, const struct matrix3 *m,
float epsilon);
const struct bounds *test,
const struct matrix3 *m, float epsilon);
static inline bool bounds_intersects_ray(const struct bounds *b,
const struct vec3 *orig, const struct vec3 *dir)
const struct vec3 *orig,
const struct vec3 *dir)
{
float t;
return bounds_intersection_ray(b, orig, dir, &t);
}
static inline bool bounds_intersects_line(const struct bounds *b,
const struct vec3 *p1, const struct vec3 *p2)
const struct vec3 *p1,
const struct vec3 *p2)
{
float t;
return bounds_intersection_line(b, p1, p2, &t);

View file

@ -25,90 +25,103 @@ extern "C" {
EXPORT const char *device_get_name(void);
EXPORT int device_get_type(void);
EXPORT bool device_enum_adapters(
bool (*callback)(void *param, const char *name, uint32_t id),
void *param);
EXPORT bool device_enum_adapters(bool (*callback)(void *param, const char *name,
uint32_t id),
void *param);
EXPORT const char *device_preprocessor_name(void);
EXPORT int device_create(gs_device_t **device, uint32_t adapter);
EXPORT void device_destroy(gs_device_t *device);
EXPORT void device_enter_context(gs_device_t *device);
EXPORT void device_leave_context(gs_device_t *device);
EXPORT void *device_get_device_obj(gs_device_t *device);
EXPORT gs_swapchain_t *device_swapchain_create(gs_device_t *device,
const struct gs_init_data *data);
const struct gs_init_data *data);
EXPORT void device_resize(gs_device_t *device, uint32_t x, uint32_t y);
EXPORT void device_get_size(const gs_device_t *device, uint32_t *x, uint32_t *y);
EXPORT void device_get_size(const gs_device_t *device, uint32_t *x,
uint32_t *y);
EXPORT uint32_t device_get_width(const gs_device_t *device);
EXPORT uint32_t device_get_height(const gs_device_t *device);
EXPORT gs_texture_t *device_texture_create(gs_device_t *device, uint32_t width,
uint32_t height, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *device_cubetexture_create(gs_device_t *device,
uint32_t size, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *device_voltexture_create(gs_device_t *device,
uint32_t width, uint32_t height, uint32_t depth,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *
device_texture_create(gs_device_t *device, uint32_t width, uint32_t height,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *
device_cubetexture_create(gs_device_t *device, uint32_t size,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *
device_voltexture_create(gs_device_t *device, uint32_t width, uint32_t height,
uint32_t depth, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
EXPORT gs_zstencil_t *device_zstencil_create(gs_device_t *device,
uint32_t width, uint32_t height,
enum gs_zstencil_format format);
EXPORT gs_stagesurf_t *device_stagesurface_create(gs_device_t *device,
uint32_t width, uint32_t height,
enum gs_color_format color_format);
EXPORT gs_samplerstate_t *device_samplerstate_create(gs_device_t *device,
const struct gs_sampler_info *info);
uint32_t width, uint32_t height,
enum gs_zstencil_format format);
EXPORT gs_stagesurf_t *
device_stagesurface_create(gs_device_t *device, uint32_t width, uint32_t height,
enum gs_color_format color_format);
EXPORT gs_samplerstate_t *
device_samplerstate_create(gs_device_t *device,
const struct gs_sampler_info *info);
EXPORT gs_shader_t *device_vertexshader_create(gs_device_t *device,
const char *shader, const char *file,
char **error_string);
const char *shader,
const char *file,
char **error_string);
EXPORT gs_shader_t *device_pixelshader_create(gs_device_t *device,
const char *shader, const char *file,
char **error_string);
const char *shader,
const char *file,
char **error_string);
EXPORT gs_vertbuffer_t *device_vertexbuffer_create(gs_device_t *device,
struct gs_vb_data *data, uint32_t flags);
struct gs_vb_data *data,
uint32_t flags);
EXPORT gs_indexbuffer_t *device_indexbuffer_create(gs_device_t *device,
enum gs_index_type type, void *indices, size_t num,
uint32_t flags);
EXPORT enum gs_texture_type device_get_texture_type(
const gs_texture_t *texture);
enum gs_index_type type,
void *indices, size_t num,
uint32_t flags);
EXPORT gs_timer_t *device_timer_create(gs_device_t *device);
EXPORT gs_timer_range_t *device_timer_range_create(gs_device_t *device);
EXPORT enum gs_texture_type
device_get_texture_type(const gs_texture_t *texture);
EXPORT void device_load_vertexbuffer(gs_device_t *device,
gs_vertbuffer_t *vertbuffer);
gs_vertbuffer_t *vertbuffer);
EXPORT void device_load_indexbuffer(gs_device_t *device,
gs_indexbuffer_t *indexbuffer);
gs_indexbuffer_t *indexbuffer);
EXPORT void device_load_texture(gs_device_t *device, gs_texture_t *tex,
int unit);
int unit);
EXPORT void device_load_samplerstate(gs_device_t *device,
gs_samplerstate_t *samplerstate, int unit);
gs_samplerstate_t *samplerstate, int unit);
EXPORT void device_load_vertexshader(gs_device_t *device,
gs_shader_t *vertshader);
gs_shader_t *vertshader);
EXPORT void device_load_pixelshader(gs_device_t *device,
gs_shader_t *pixelshader);
gs_shader_t *pixelshader);
EXPORT void device_load_default_samplerstate(gs_device_t *device, bool b_3d,
int unit);
int unit);
EXPORT gs_shader_t *device_get_vertex_shader(const gs_device_t *device);
EXPORT gs_shader_t *device_get_pixel_shader(const gs_device_t *device);
EXPORT gs_texture_t *device_get_render_target(const gs_device_t *device);
EXPORT gs_zstencil_t *device_get_zstencil_target(const gs_device_t *device);
EXPORT void device_set_render_target(gs_device_t *device, gs_texture_t *tex,
gs_zstencil_t *zstencil);
gs_zstencil_t *zstencil);
EXPORT void device_set_cube_render_target(gs_device_t *device,
gs_texture_t *cubetex,
int side, gs_zstencil_t *zstencil);
gs_texture_t *cubetex, int side,
gs_zstencil_t *zstencil);
EXPORT void device_copy_texture(gs_device_t *device, gs_texture_t *dst,
gs_texture_t *src);
EXPORT void device_copy_texture_region(gs_device_t *device,
gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y,
gs_texture_t *src, uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h);
gs_texture_t *src);
EXPORT void device_copy_texture_region(gs_device_t *device, gs_texture_t *dst,
uint32_t dst_x, uint32_t dst_y,
gs_texture_t *src, uint32_t src_x,
uint32_t src_y, uint32_t src_w,
uint32_t src_h);
EXPORT void device_stage_texture(gs_device_t *device, gs_stagesurf_t *dst,
gs_texture_t *src);
gs_texture_t *src);
EXPORT void device_begin_scene(gs_device_t *device);
EXPORT void device_draw(gs_device_t *device, enum gs_draw_mode draw_mode,
uint32_t start_vert, uint32_t num_verts);
uint32_t start_vert, uint32_t num_verts);
EXPORT void device_end_scene(gs_device_t *device);
EXPORT void device_load_swapchain(gs_device_t *device,
gs_swapchain_t *swapchain);
gs_swapchain_t *swapchain);
EXPORT void device_clear(gs_device_t *device, uint32_t clear_flags,
const struct vec4 *color, float depth, uint8_t stencil);
const struct vec4 *color, float depth,
uint8_t stencil);
EXPORT void device_present(gs_device_t *device);
EXPORT void device_flush(gs_device_t *device);
EXPORT void device_set_cull_mode(gs_device_t *device, enum gs_cull_mode mode);
@ -118,32 +131,37 @@ EXPORT void device_enable_depth_test(gs_device_t *device, bool enable);
EXPORT void device_enable_stencil_test(gs_device_t *device, bool enable);
EXPORT void device_enable_stencil_write(gs_device_t *device, bool enable);
EXPORT void device_enable_color(gs_device_t *device, bool red, bool green,
bool blue, bool alpha);
bool blue, bool alpha);
EXPORT void device_blend_function(gs_device_t *device, enum gs_blend_type src,
enum gs_blend_type dest);
enum gs_blend_type dest);
EXPORT void device_blend_function_separate(gs_device_t *device,
enum gs_blend_type src_c, enum gs_blend_type dest_c,
enum gs_blend_type src_a, enum gs_blend_type dest_a);
enum gs_blend_type src_c,
enum gs_blend_type dest_c,
enum gs_blend_type src_a,
enum gs_blend_type dest_a);
EXPORT void device_depth_function(gs_device_t *device, enum gs_depth_test test);
EXPORT void device_stencil_function(gs_device_t *device,
enum gs_stencil_side side, enum gs_depth_test test);
enum gs_stencil_side side,
enum gs_depth_test test);
EXPORT void device_stencil_op(gs_device_t *device, enum gs_stencil_side side,
enum gs_stencil_op_type fail, enum gs_stencil_op_type zfail,
enum gs_stencil_op_type zpass);
enum gs_stencil_op_type fail,
enum gs_stencil_op_type zfail,
enum gs_stencil_op_type zpass);
EXPORT void device_set_viewport(gs_device_t *device, int x, int y, int width,
int height);
int height);
EXPORT void device_get_viewport(const gs_device_t *device,
struct gs_rect *rect);
struct gs_rect *rect);
EXPORT void device_set_scissor_rect(gs_device_t *device,
const struct gs_rect *rect);
const struct gs_rect *rect);
EXPORT void device_ortho(gs_device_t *device, float left, float right,
float top, float bottom, float znear, float zfar);
float top, float bottom, float znear, float zfar);
EXPORT void device_frustum(gs_device_t *device, float left, float right,
float top, float bottom, float znear, float zfar);
float top, float bottom, float znear, float zfar);
EXPORT void device_projection_push(gs_device_t *device);
EXPORT void device_projection_pop(gs_device_t *device);
EXPORT void device_debug_marker_begin(gs_device_t *device,
const char *markername, const float color[4]);
const char *markername,
const float color[4]);
EXPORT void device_debug_marker_end(gs_device_t *device);
#ifdef __cplusplus

File diff suppressed because it is too large Load diff

View file

@ -67,9 +67,9 @@ static inline void ep_var_free(struct ep_var *epv)
/* effect parser param data */
struct ep_param {
char *type, *name;
DARRAY(uint8_t) default_val;
DARRAY(char*) properties;
char *type, *name;
DARRAY(uint8_t) default_val;
DARRAY(char *) properties;
struct gs_effect_param *param;
bool is_const, is_property, is_uniform, is_texture, written;
int writeorder, array_count;
@ -78,18 +78,18 @@ struct ep_param {
extern void ep_param_writevar(struct dstr *dst, struct darray *use_params);
static inline void ep_param_init(struct ep_param *epp,
char *type, char *name,
bool is_property, bool is_const, bool is_uniform)
static inline void ep_param_init(struct ep_param *epp, char *type, char *name,
bool is_property, bool is_const,
bool is_uniform)
{
epp->type = type;
epp->name = name;
epp->type = type;
epp->name = name;
epp->is_property = is_property;
epp->is_const = is_const;
epp->is_uniform = is_uniform;
epp->is_texture = (astrcmp_n(epp->type, "texture", 7) == 0);
epp->written = false;
epp->writeorder = false;
epp->is_const = is_const;
epp->is_uniform = is_uniform;
epp->is_texture = (astrcmp_n(epp->type, "texture", 7) == 0);
epp->written = false;
epp->writeorder = false;
epp->array_count = 0;
da_init(epp->default_val);
da_init(epp->properties);
@ -136,7 +136,7 @@ static inline void ep_struct_free(struct ep_struct *eps)
bfree(eps->name);
for (i = 0; i < eps->vars.num; i++)
ep_var_free(eps->vars.array+i);
ep_var_free(eps->vars.array + i);
da_free(eps->vars);
}
@ -145,8 +145,8 @@ static inline void ep_struct_free(struct ep_struct *eps)
struct ep_sampler {
char *name;
DARRAY(char*) states;
DARRAY(char*) values;
DARRAY(char *) states;
DARRAY(char *) values;
bool written;
};
@ -210,7 +210,7 @@ static inline void ep_technique_free(struct ep_technique *ept)
size_t i;
for (i = 0; i < ept->passes.num; i++)
ep_pass_free(ept->passes.array+i);
ep_pass_free(ept->passes.array + i);
bfree(ept->name);
da_free(ept->passes);
@ -223,18 +223,17 @@ struct ep_func {
char *name, *ret_type, *mapping;
struct dstr contents;
DARRAY(struct ep_var) param_vars;
DARRAY(const char*) func_deps;
DARRAY(const char*) struct_deps;
DARRAY(const char*) param_deps;
DARRAY(const char*) sampler_deps;
DARRAY(const char *) func_deps;
DARRAY(const char *) struct_deps;
DARRAY(const char *) param_deps;
DARRAY(const char *) sampler_deps;
bool written;
};
static inline void ep_func_init(struct ep_func *epf, char *ret_type,
char *name)
static inline void ep_func_init(struct ep_func *epf, char *ret_type, char *name)
{
memset(epf, 0, sizeof(struct ep_func));
epf->name = name;
epf->name = name;
epf->ret_type = ret_type;
}
@ -242,7 +241,7 @@ static inline void ep_func_free(struct ep_func *epf)
{
size_t i;
for (i = 0; i < epf->param_vars.num; i++)
ep_var_free(epf->param_vars.array+i);
ep_var_free(epf->param_vars.array + i);
bfree(epf->name);
bfree(epf->ret_type);
@ -260,10 +259,10 @@ static inline void ep_func_free(struct ep_func *epf)
struct effect_parser {
gs_effect_t *effect;
DARRAY(struct ep_param) params;
DARRAY(struct ep_struct) structs;
DARRAY(struct ep_func) funcs;
DARRAY(struct ep_sampler) samplers;
DARRAY(struct ep_param) params;
DARRAY(struct ep_struct) structs;
DARRAY(struct ep_func) funcs;
DARRAY(struct ep_sampler) samplers;
DARRAY(struct ep_technique) techniques;
/* internal vars */
@ -291,7 +290,7 @@ static inline void ep_init(struct effect_parser *ep)
extern void ep_free(struct effect_parser *ep);
extern bool ep_parse(struct effect_parser *ep, gs_effect_t *effect,
const char *effect_string, const char *file);
const char *effect_string, const char *file);
#ifdef __cplusplus
}

View file

@ -36,12 +36,13 @@ void gs_effect_destroy(gs_effect_t *effect)
}
gs_technique_t *gs_effect_get_technique(const gs_effect_t *effect,
const char *name)
const char *name)
{
if (!effect) return NULL;
if (!effect)
return NULL;
for (size_t i = 0; i < effect->techniques.num; i++) {
struct gs_effect_technique *tech = effect->techniques.array+i;
struct gs_effect_technique *tech = effect->techniques.array + i;
if (strcmp(tech->name, name) == 0)
return tech;
}
@ -51,7 +52,8 @@ gs_technique_t *gs_effect_get_technique(const gs_effect_t *effect,
gs_technique_t *gs_effect_get_current_technique(const gs_effect_t *effect)
{
if (!effect) return NULL;
if (!effect)
return NULL;
return effect->cur_technique;
}
@ -67,14 +69,16 @@ bool gs_effect_loop(gs_effect_t *effect, const char *name)
if (!!gs_get_effect()) {
blog(LOG_WARNING, "gs_effect_loop: An effect is "
"already active");
"already active");
return false;
}
tech = gs_effect_get_technique(effect, name);
if (!tech) {
blog(LOG_WARNING, "gs_effect_loop: Technique '%s' "
"not found.", name);
blog(LOG_WARNING,
"gs_effect_loop: Technique '%s' "
"not found.",
name);
return false;
}
@ -86,7 +90,7 @@ bool gs_effect_loop(gs_effect_t *effect, const char *name)
}
if (!gs_technique_begin_pass(effect->cur_technique,
effect->loop_pass++)) {
effect->loop_pass++)) {
gs_technique_end(effect->cur_technique);
effect->looping = false;
effect->loop_pass = 0;
@ -98,7 +102,8 @@ bool gs_effect_loop(gs_effect_t *effect, const char *name)
size_t gs_technique_begin(gs_technique_t *tech)
{
if (!tech) return 0;
if (!tech)
return 0;
tech->effect->cur_technique = tech;
tech->effect->graphics->cur_effect = tech->effect;
@ -108,7 +113,8 @@ size_t gs_technique_begin(gs_technique_t *tech)
void gs_technique_end(gs_technique_t *tech)
{
if (!tech) return;
if (!tech)
return;
struct gs_effect *effect = tech->effect;
struct gs_effect_param *params = effect->params.array;
@ -121,7 +127,7 @@ void gs_technique_end(gs_technique_t *tech)
tech->effect->graphics->cur_effect = NULL;
for (i = 0; i < effect->params.num; i++) {
struct gs_effect_param *param = params+i;
struct gs_effect_param *param = params + i;
da_free(param->cur_val);
param->changed = false;
@ -145,12 +151,13 @@ static void upload_shader_params(struct darray *pass_params, bool changed_only)
size_t i;
for (i = 0; i < pass_params->num; i++) {
struct pass_shaderparam *param = params+i;
struct pass_shaderparam *param = params + i;
struct gs_effect_param *eparam = param->eparam;
gs_sparam_t *sparam = param->sparam;
if (eparam->next_sampler)
gs_shader_set_next_sampler(sparam, eparam->next_sampler);
gs_shader_set_next_sampler(sparam,
eparam->next_sampler);
if (changed_only && !eparam->changed)
continue;
@ -163,12 +170,12 @@ static void upload_shader_params(struct darray *pass_params, bool changed_only)
}
gs_shader_set_val(sparam, eparam->cur_val.array,
eparam->cur_val.num);
eparam->cur_val.num);
}
}
static inline void upload_parameters(struct gs_effect *effect,
bool changed_only)
bool changed_only)
{
struct darray *vshader_params, *pshader_params;
@ -184,7 +191,7 @@ static inline void upload_parameters(struct gs_effect *effect,
reset_params(pshader_params);
}
void gs_effect_update_params(gs_effect_t *effect)
void gs_effect_update_params(gs_effect_t *effect)
{
if (effect)
upload_parameters(effect, true);
@ -199,7 +206,7 @@ bool gs_technique_begin_pass(gs_technique_t *tech, size_t idx)
return false;
passes = tech->passes.array;
cur_pass = passes+idx;
cur_pass = passes + idx;
tech->effect->cur_pass = cur_pass;
gs_load_vertexshader(cur_pass->vertshader);
@ -209,14 +216,13 @@ bool gs_technique_begin_pass(gs_technique_t *tech, size_t idx)
return true;
}
bool gs_technique_begin_pass_by_name(gs_technique_t *tech,
const char *name)
bool gs_technique_begin_pass_by_name(gs_technique_t *tech, const char *name)
{
if (!tech)
return false;
for (size_t i = 0; i < tech->passes.num; i++) {
struct gs_effect_pass *pass = tech->passes.array+i;
struct gs_effect_pass *pass = tech->passes.array + i;
if (strcmp(pass->name, name) == 0) {
gs_technique_begin_pass(tech, i);
return true;
@ -231,7 +237,7 @@ static inline void clear_tex_params(struct darray *in_params)
struct pass_shaderparam *params = in_params->array;
for (size_t i = 0; i < in_params->num; i++) {
struct pass_shaderparam *param = params+i;
struct pass_shaderparam *param = params + i;
struct gs_shader_param_info info;
gs_shader_get_param_info(param->sparam, &info);
@ -242,7 +248,8 @@ static inline void clear_tex_params(struct darray *in_params)
void gs_technique_end_pass(gs_technique_t *tech)
{
if (!tech) return;
if (!tech)
return;
struct gs_effect_pass *pass = tech->effect->cur_pass;
if (!pass)
@ -260,24 +267,26 @@ size_t gs_effect_get_num_params(const gs_effect_t *effect)
gs_eparam_t *gs_effect_get_param_by_idx(const gs_effect_t *effect, size_t param)
{
if (!effect) return NULL;
if (!effect)
return NULL;
struct gs_effect_param *params = effect->params.array;
if (param >= effect->params.num)
return NULL;
return params+param;
return params + param;
}
gs_eparam_t *gs_effect_get_param_by_name(const gs_effect_t *effect,
const char *name)
const char *name)
{
if (!effect) return NULL;
if (!effect)
return NULL;
struct gs_effect_param *params = effect->params.array;
for (size_t i = 0; i < effect->params.num; i++) {
struct gs_effect_param *param = params+i;
struct gs_effect_param *param = params + i;
if (strcmp(param->name, name) == 0)
return param;
@ -292,10 +301,11 @@ size_t gs_param_get_num_annotations(const gs_eparam_t *param)
}
gs_eparam_t *gs_param_get_annotation_by_idx(const gs_eparam_t *param,
size_t annotation)
size_t annotation)
{
if (!param) return NULL;
if (!param)
return NULL;
struct gs_effect_param *params = param->annotations.array;
if (annotation > param->annotations.num)
return NULL;
@ -304,9 +314,10 @@ gs_eparam_t *gs_param_get_annotation_by_idx(const gs_eparam_t *param,
}
gs_eparam_t *gs_param_get_annotation_by_name(const gs_eparam_t *param,
const char *name)
const char *name)
{
if (!param) return NULL;
if (!param)
return NULL;
struct gs_effect_param *params = param->annotations.array;
for (size_t i = 0; i < param->annotations.num; i++) {
@ -318,9 +329,10 @@ gs_eparam_t *gs_param_get_annotation_by_name(const gs_eparam_t *param,
}
gs_epass_t *gs_technique_get_pass_by_idx(const gs_technique_t *technique,
size_t pass)
size_t pass)
{
if (!technique) return NULL;
if (!technique)
return NULL;
struct gs_effect_pass *passes = technique->passes.array;
if (pass > technique->passes.num)
@ -330,9 +342,10 @@ gs_epass_t *gs_technique_get_pass_by_idx(const gs_technique_t *technique,
}
gs_epass_t *gs_technique_get_pass_by_name(const gs_technique_t *technique,
const char *name)
const char *name)
{
if (!technique) return NULL;
if (!technique)
return NULL;
struct gs_effect_pass *passes = technique->passes.array;
for (size_t i = 0; i < technique->passes.num; i++) {
@ -354,7 +367,7 @@ gs_eparam_t *gs_effect_get_world_matrix(const gs_effect_t *effect)
}
void gs_effect_get_param_info(const gs_eparam_t *param,
struct gs_effect_param_info *info)
struct gs_effect_param_info *info)
{
if (!param)
return;
@ -363,8 +376,8 @@ void gs_effect_get_param_info(const gs_eparam_t *param,
info->type = param->type;
}
static inline void effect_setval_inline(gs_eparam_t *param,
const void *data, size_t size)
static inline void effect_setval_inline(gs_eparam_t *param, const void *data,
size_t size)
{
bool size_changed;
@ -390,10 +403,10 @@ static inline void effect_setval_inline(gs_eparam_t *param,
}
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
static inline void effect_getval_inline(gs_eparam_t *param, void *data,
size_t size)
size_t size)
{
if (!param) {
blog(LOG_ERROR, "effect_getval_inline: invalid param");
@ -411,7 +424,7 @@ static inline void effect_getval_inline(gs_eparam_t *param, void *data,
}
static inline void effect_getdefaultval_inline(gs_eparam_t *param, void *data,
size_t size)
size_t size)
{
if (!param) {
blog(LOG_ERROR, "effect_getdefaultval_inline: invalid param");
@ -473,7 +486,7 @@ void gs_effect_set_color(gs_eparam_t *param, uint32_t argb)
void gs_effect_set_texture(gs_eparam_t *param, gs_texture_t *val)
{
effect_setval_inline(param, &val, sizeof(gs_texture_t*));
effect_setval_inline(param, &val, sizeof(gs_texture_t *));
}
void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size)
@ -491,7 +504,7 @@ void *gs_effect_get_val(gs_eparam_t *param)
void *data;
if (size)
data = (void*)bzalloc(size);
data = (void *)bzalloc(size);
else
return NULL;
@ -515,7 +528,7 @@ void *gs_effect_get_default_val(gs_eparam_t *param)
void *data;
if (size)
data = (void*)bzalloc(size);
data = (void *)bzalloc(size);
else
return NULL;
@ -532,7 +545,7 @@ size_t gs_effect_get_default_val_size(gs_eparam_t *param)
void gs_effect_set_default(gs_eparam_t *param)
{
effect_setval_inline(param, param->default_val.array,
param->default_val.num);
param->default_val.num);
}
void gs_effect_set_next_sampler(gs_eparam_t *param, gs_samplerstate_t *sampler)

View file

@ -86,7 +86,7 @@ static inline void effect_param_free(struct gs_effect_param *param)
}
EXPORT void effect_param_parse_property(gs_eparam_t *param,
const char *property);
const char *property);
/* ------------------------------------------------------------------------- */
@ -139,7 +139,7 @@ static inline void effect_technique_free(struct gs_effect_technique *t)
{
size_t i;
for (i = 0; i < t->passes.num; i++)
effect_pass_free(t->passes.array+i);
effect_pass_free(t->passes.array + i);
da_free(t->passes);
bfree(t->name);
@ -176,9 +176,9 @@ static inline void effect_free(gs_effect_t *effect)
{
size_t i;
for (i = 0; i < effect->params.num; i++)
effect_param_free(effect->params.array+i);
effect_param_free(effect->params.array + i);
for (i = 0; i < effect->techniques.num; i++)
effect_technique_free(effect->techniques.array+i);
effect_technique_free(effect->techniques.array + i);
da_free(effect->params);
da_free(effect->techniques);
@ -191,8 +191,9 @@ static inline void effect_free(gs_effect_t *effect)
EXPORT void effect_upload_params(gs_effect_t *effect, bool changed_only);
EXPORT void effect_upload_shader_params(gs_effect_t *effect,
gs_shader_t *shader, struct darray *pass_params,
bool changed_only);
gs_shader_t *shader,
struct darray *pass_params,
bool changed_only);
#ifdef __cplusplus
}

View file

@ -7,42 +7,44 @@
#include "../obs-ffmpeg-compat.h"
struct ffmpeg_image {
const char *file;
AVFormatContext *fmt_ctx;
AVCodecContext *decoder_ctx;
AVCodec *decoder;
AVStream *stream;
int stream_idx;
const char *file;
AVFormatContext *fmt_ctx;
AVCodecContext *decoder_ctx;
AVCodec *decoder;
AVStream *stream;
int stream_idx;
int cx, cy;
int cx, cy;
enum AVPixelFormat format;
};
static bool ffmpeg_image_open_decoder_context(struct ffmpeg_image *info)
{
int ret = av_find_best_stream(info->fmt_ctx, AVMEDIA_TYPE_VIDEO,
-1, 1, NULL, 0);
int ret = av_find_best_stream(info->fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, 1,
NULL, 0);
if (ret < 0) {
blog(LOG_WARNING, "Couldn't find video stream in file '%s': %s",
info->file, av_err2str(ret));
info->file, av_err2str(ret));
return false;
}
info->stream_idx = ret;
info->stream = info->fmt_ctx->streams[ret];
info->stream_idx = ret;
info->stream = info->fmt_ctx->streams[ret];
info->decoder_ctx = info->stream->codec;
info->decoder = avcodec_find_decoder(info->decoder_ctx->codec_id);
info->decoder = avcodec_find_decoder(info->decoder_ctx->codec_id);
if (!info->decoder) {
blog(LOG_WARNING, "Failed to find decoder for file '%s'",
info->file);
info->file);
return false;
}
ret = avcodec_open2(info->decoder_ctx, info->decoder, NULL);
if (ret < 0) {
blog(LOG_WARNING, "Failed to open video codec for file '%s': "
"%s", info->file, av_err2str(ret));
blog(LOG_WARNING,
"Failed to open video codec for file '%s': "
"%s",
info->file, av_err2str(ret));
return false;
}
@ -63,28 +65,30 @@ static bool ffmpeg_image_init(struct ffmpeg_image *info, const char *file)
return false;
memset(info, 0, sizeof(struct ffmpeg_image));
info->file = file;
info->file = file;
info->stream_idx = -1;
ret = avformat_open_input(&info->fmt_ctx, file, NULL, NULL);
if (ret < 0) {
blog(LOG_WARNING, "Failed to open file '%s': %s",
info->file, av_err2str(ret));
blog(LOG_WARNING, "Failed to open file '%s': %s", info->file,
av_err2str(ret));
return false;
}
ret = avformat_find_stream_info(info->fmt_ctx, NULL);
if (ret < 0) {
blog(LOG_WARNING, "Could not find stream info for file '%s':"
" %s", info->file, av_err2str(ret));
blog(LOG_WARNING,
"Could not find stream info for file '%s':"
" %s",
info->file, av_err2str(ret));
goto fail;
}
if (!ffmpeg_image_open_decoder_context(info))
goto fail;
info->cx = info->decoder_ctx->width;
info->cy = info->decoder_ctx->height;
info->cx = info->decoder_ctx->width;
info->cy = info->decoder_ctx->height;
info->format = info->decoder_ctx->pix_fmt;
return true;
@ -94,18 +98,20 @@ fail:
}
static bool ffmpeg_image_reformat_frame(struct ffmpeg_image *info,
AVFrame *frame, uint8_t *out, int linesize)
AVFrame *frame, uint8_t *out,
int linesize)
{
struct SwsContext *sws_ctx = NULL;
int ret = 0;
int ret = 0;
if (info->format == AV_PIX_FMT_RGBA ||
info->format == AV_PIX_FMT_BGRA ||
info->format == AV_PIX_FMT_BGR0) {
if (linesize != frame->linesize[0]) {
int min_line = linesize < frame->linesize[0] ?
linesize : frame->linesize[0];
int min_line = linesize < frame->linesize[0]
? linesize
: frame->linesize[0];
for (int y = 0; y < info->cy; y++)
memcpy(out + y * linesize,
@ -117,21 +123,23 @@ static bool ffmpeg_image_reformat_frame(struct ffmpeg_image *info,
} else {
sws_ctx = sws_getContext(info->cx, info->cy, info->format,
info->cx, info->cy, AV_PIX_FMT_BGRA,
SWS_POINT, NULL, NULL, NULL);
info->cx, info->cy, AV_PIX_FMT_BGRA,
SWS_POINT, NULL, NULL, NULL);
if (!sws_ctx) {
blog(LOG_WARNING, "Failed to create scale context "
"for '%s'", info->file);
blog(LOG_WARNING,
"Failed to create scale context "
"for '%s'",
info->file);
return false;
}
ret = sws_scale(sws_ctx, (const uint8_t *const*)frame->data,
ret = sws_scale(sws_ctx, (const uint8_t *const *)frame->data,
frame->linesize, 0, info->cy, &out, &linesize);
sws_freeContext(sws_ctx);
if (ret < 0) {
blog(LOG_WARNING, "sws_scale failed for '%s': %s",
info->file, av_err2str(ret));
info->file, av_err2str(ret));
return false;
}
@ -142,24 +150,24 @@ static bool ffmpeg_image_reformat_frame(struct ffmpeg_image *info,
}
static bool ffmpeg_image_decode(struct ffmpeg_image *info, uint8_t *out,
int linesize)
int linesize)
{
AVPacket packet = {0};
bool success = false;
AVFrame *frame = av_frame_alloc();
int got_frame = 0;
int ret;
AVPacket packet = {0};
bool success = false;
AVFrame *frame = av_frame_alloc();
int got_frame = 0;
int ret;
if (!frame) {
blog(LOG_WARNING, "Failed to create frame data for '%s'",
info->file);
info->file);
return false;
}
ret = av_read_frame(info->fmt_ctx, &packet);
if (ret < 0) {
blog(LOG_WARNING, "Failed to read image frame from '%s': %s",
info->file, av_err2str(ret));
info->file, av_err2str(ret));
goto fail;
}
@ -175,11 +183,11 @@ static bool ffmpeg_image_decode(struct ffmpeg_image *info, uint8_t *out,
ret = 0;
#else
ret = avcodec_decode_video2(info->decoder_ctx, frame,
&got_frame, &packet);
&got_frame, &packet);
#endif
if (ret < 0) {
blog(LOG_WARNING, "Failed to decode frame for '%s': %s",
info->file, av_err2str(ret));
info->file, av_err2str(ret));
goto fail;
}
}
@ -194,27 +202,30 @@ fail:
void gs_init_image_deps(void)
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
av_register_all();
#endif
}
void gs_free_image_deps(void)
{
}
void gs_free_image_deps(void) {}
static inline enum gs_color_format convert_format(enum AVPixelFormat format)
{
switch ((int)format) {
case AV_PIX_FMT_RGBA: return GS_RGBA;
case AV_PIX_FMT_BGRA: return GS_BGRA;
case AV_PIX_FMT_BGR0: return GS_BGRX;
case AV_PIX_FMT_RGBA:
return GS_RGBA;
case AV_PIX_FMT_BGRA:
return GS_BGRA;
case AV_PIX_FMT_BGR0:
return GS_BGRX;
}
return GS_BGRX;
}
uint8_t *gs_create_texture_file_data(const char *file,
enum gs_color_format *format,
uint32_t *cx_out, uint32_t *cy_out)
enum gs_color_format *format,
uint32_t *cx_out, uint32_t *cy_out)
{
struct ffmpeg_image image;
uint8_t *data = NULL;

View file

@ -20,23 +20,25 @@
#include "../util/platform.h"
#include "graphics-internal.h"
#define GRAPHICS_IMPORT(func) \
do { \
exports->func = os_dlsym(module, #func); \
if (!exports->func) { \
success = false; \
blog(LOG_ERROR, "Could not load function '%s' from " \
"module '%s'", #func, module_name); \
} \
#define GRAPHICS_IMPORT(func) \
do { \
exports->func = os_dlsym(module, #func); \
if (!exports->func) { \
success = false; \
blog(LOG_ERROR, \
"Could not load function '%s' from " \
"module '%s'", \
#func, module_name); \
} \
} while (false)
#define GRAPHICS_IMPORT_OPTIONAL(func) \
do { \
#define GRAPHICS_IMPORT_OPTIONAL(func) \
do { \
exports->func = os_dlsym(module, #func); \
} while (false)
bool load_graphics_imports(struct gs_exports *exports, void *module,
const char *module_name)
const char *module_name)
{
bool success = true;
@ -48,6 +50,7 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
GRAPHICS_IMPORT(device_destroy);
GRAPHICS_IMPORT(device_enter_context);
GRAPHICS_IMPORT(device_leave_context);
GRAPHICS_IMPORT(device_get_device_obj);
GRAPHICS_IMPORT(device_swapchain_create);
GRAPHICS_IMPORT(device_resize);
GRAPHICS_IMPORT(device_get_size);
@ -63,6 +66,8 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
GRAPHICS_IMPORT(device_pixelshader_create);
GRAPHICS_IMPORT(device_vertexbuffer_create);
GRAPHICS_IMPORT(device_indexbuffer_create);
GRAPHICS_IMPORT(device_timer_create);
GRAPHICS_IMPORT(device_timer_range_create);
GRAPHICS_IMPORT(device_get_texture_type);
GRAPHICS_IMPORT(device_load_vertexbuffer);
GRAPHICS_IMPORT(device_load_indexbuffer);
@ -151,6 +156,15 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
GRAPHICS_IMPORT(gs_indexbuffer_get_num_indices);
GRAPHICS_IMPORT(gs_indexbuffer_get_type);
GRAPHICS_IMPORT(gs_timer_destroy);
GRAPHICS_IMPORT(gs_timer_begin);
GRAPHICS_IMPORT(gs_timer_end);
GRAPHICS_IMPORT(gs_timer_get_data);
GRAPHICS_IMPORT(gs_timer_range_destroy);
GRAPHICS_IMPORT(gs_timer_range_begin);
GRAPHICS_IMPORT(gs_timer_range_end);
GRAPHICS_IMPORT(gs_timer_range_get_data);
GRAPHICS_IMPORT(gs_shader_destroy);
GRAPHICS_IMPORT(gs_shader_get_num_params);
GRAPHICS_IMPORT(gs_shader_get_param_by_idx);

View file

@ -26,162 +26,180 @@
struct gs_exports {
const char *(*device_get_name)(void);
int (*device_get_type)(void);
bool (*device_enum_adapters)(
bool (*callback)(void*, const char*, uint32_t),
void*);
bool (*device_enum_adapters)(bool (*callback)(void *, const char *,
uint32_t),
void *);
const char *(*device_preprocessor_name)(void);
int (*device_create)(gs_device_t **device, uint32_t adapter);
void (*device_destroy)(gs_device_t *device);
void (*device_enter_context)(gs_device_t *device);
void (*device_leave_context)(gs_device_t *device);
gs_swapchain_t *(*device_swapchain_create)(gs_device_t *device,
const struct gs_init_data *data);
void *(*device_get_device_obj)(gs_device_t *device);
gs_swapchain_t *(*device_swapchain_create)(
gs_device_t *device, const struct gs_init_data *data);
void (*device_resize)(gs_device_t *device, uint32_t x, uint32_t y);
void (*device_get_size)(const gs_device_t *device,
uint32_t *x, uint32_t *y);
void (*device_get_size)(const gs_device_t *device, uint32_t *x,
uint32_t *y);
uint32_t (*device_get_width)(const gs_device_t *device);
uint32_t (*device_get_height)(const gs_device_t *device);
gs_texture_t *(*device_texture_create)(gs_device_t *device,
uint32_t width, uint32_t height,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
gs_texture_t *(*device_cubetexture_create)(gs_device_t *device,
uint32_t size, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
gs_texture_t *(*device_voltexture_create)(gs_device_t *device,
uint32_t width, uint32_t height, uint32_t depth,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
gs_zstencil_t *(*device_zstencil_create)(gs_device_t *device,
uint32_t width, uint32_t height,
enum gs_zstencil_format format);
gs_stagesurf_t *(*device_stagesurface_create)(gs_device_t *device,
uint32_t width, uint32_t height,
enum gs_color_format color_format);
gs_samplerstate_t *(*device_samplerstate_create)(gs_device_t *device,
const struct gs_sampler_info *info);
gs_texture_t *(*device_texture_create)(
gs_device_t *device, uint32_t width, uint32_t height,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
gs_texture_t *(*device_cubetexture_create)(
gs_device_t *device, uint32_t size,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
gs_texture_t *(*device_voltexture_create)(
gs_device_t *device, uint32_t width, uint32_t height,
uint32_t depth, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
gs_zstencil_t *(*device_zstencil_create)(
gs_device_t *device, uint32_t width, uint32_t height,
enum gs_zstencil_format format);
gs_stagesurf_t *(*device_stagesurface_create)(
gs_device_t *device, uint32_t width, uint32_t height,
enum gs_color_format color_format);
gs_samplerstate_t *(*device_samplerstate_create)(
gs_device_t *device, const struct gs_sampler_info *info);
gs_shader_t *(*device_vertexshader_create)(gs_device_t *device,
const char *shader, const char *file,
char **error_string);
const char *shader,
const char *file,
char **error_string);
gs_shader_t *(*device_pixelshader_create)(gs_device_t *device,
const char *shader, const char *file,
char **error_string);
const char *shader,
const char *file,
char **error_string);
gs_vertbuffer_t *(*device_vertexbuffer_create)(gs_device_t *device,
struct gs_vb_data *data, uint32_t flags);
struct gs_vb_data *data,
uint32_t flags);
gs_indexbuffer_t *(*device_indexbuffer_create)(gs_device_t *device,
enum gs_index_type type, void *indices, size_t num,
uint32_t flags);
enum gs_index_type type,
void *indices,
size_t num,
uint32_t flags);
gs_timer_t *(*device_timer_create)(gs_device_t *device);
gs_timer_range_t *(*device_timer_range_create)(gs_device_t *device);
enum gs_texture_type (*device_get_texture_type)(
const gs_texture_t *texture);
const gs_texture_t *texture);
void (*device_load_vertexbuffer)(gs_device_t *device,
gs_vertbuffer_t *vertbuffer);
gs_vertbuffer_t *vertbuffer);
void (*device_load_indexbuffer)(gs_device_t *device,
gs_indexbuffer_t *indexbuffer);
gs_indexbuffer_t *indexbuffer);
void (*device_load_texture)(gs_device_t *device, gs_texture_t *tex,
int unit);
int unit);
void (*device_load_samplerstate)(gs_device_t *device,
gs_samplerstate_t *samplerstate, int unit);
gs_samplerstate_t *samplerstate,
int unit);
void (*device_load_vertexshader)(gs_device_t *device,
gs_shader_t *vertshader);
gs_shader_t *vertshader);
void (*device_load_pixelshader)(gs_device_t *device,
gs_shader_t *pixelshader);
void (*device_load_default_samplerstate)(gs_device_t *device,
bool b_3d, int unit);
gs_shader_t *pixelshader);
void (*device_load_default_samplerstate)(gs_device_t *device, bool b_3d,
int unit);
gs_shader_t *(*device_get_vertex_shader)(const gs_device_t *device);
gs_shader_t *(*device_get_pixel_shader)(const gs_device_t *device);
gs_texture_t *(*device_get_render_target)(const gs_device_t *device);
gs_zstencil_t *(*device_get_zstencil_target)(const gs_device_t *device);
void (*device_set_render_target)(gs_device_t *device, gs_texture_t *tex,
gs_zstencil_t *zstencil);
gs_zstencil_t *zstencil);
void (*device_set_cube_render_target)(gs_device_t *device,
gs_texture_t *cubetex, int side, gs_zstencil_t *zstencil);
gs_texture_t *cubetex, int side,
gs_zstencil_t *zstencil);
void (*device_copy_texture)(gs_device_t *device, gs_texture_t *dst,
gs_texture_t *src);
gs_texture_t *src);
void (*device_copy_texture_region)(gs_device_t *device,
gs_texture_t *dst, uint32_t dst_x, uint32_t dst_y,
gs_texture_t *src, uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h);
gs_texture_t *dst, uint32_t dst_x,
uint32_t dst_y, gs_texture_t *src,
uint32_t src_x, uint32_t src_y,
uint32_t src_w, uint32_t src_h);
void (*device_stage_texture)(gs_device_t *device, gs_stagesurf_t *dst,
gs_texture_t *src);
gs_texture_t *src);
void (*device_begin_scene)(gs_device_t *device);
void (*device_draw)(gs_device_t *device, enum gs_draw_mode draw_mode,
uint32_t start_vert, uint32_t num_verts);
uint32_t start_vert, uint32_t num_verts);
void (*device_end_scene)(gs_device_t *device);
void (*device_load_swapchain)(gs_device_t *device,
gs_swapchain_t *swaphchain);
gs_swapchain_t *swaphchain);
void (*device_clear)(gs_device_t *device, uint32_t clear_flags,
const struct vec4 *color, float depth, uint8_t stencil);
const struct vec4 *color, float depth,
uint8_t stencil);
void (*device_present)(gs_device_t *device);
void (*device_flush)(gs_device_t *device);
void (*device_set_cull_mode)(gs_device_t *device,
enum gs_cull_mode mode);
enum gs_cull_mode mode);
enum gs_cull_mode (*device_get_cull_mode)(const gs_device_t *device);
void (*device_enable_blending)(gs_device_t *device, bool enable);
void (*device_enable_depth_test)(gs_device_t *device, bool enable);
void (*device_enable_stencil_test)(gs_device_t *device, bool enable);
void (*device_enable_stencil_write)(gs_device_t *device, bool enable);
void (*device_enable_color)(gs_device_t *device, bool red, bool green,
bool blue, bool alpha);
bool blue, bool alpha);
void (*device_blend_function)(gs_device_t *device,
enum gs_blend_type src, enum gs_blend_type dest);
enum gs_blend_type src,
enum gs_blend_type dest);
void (*device_blend_function_separate)(gs_device_t *device,
enum gs_blend_type src_c, enum gs_blend_type dest_c,
enum gs_blend_type src_a, enum gs_blend_type dest_a);
enum gs_blend_type src_c,
enum gs_blend_type dest_c,
enum gs_blend_type src_a,
enum gs_blend_type dest_a);
void (*device_depth_function)(gs_device_t *device,
enum gs_depth_test test);
enum gs_depth_test test);
void (*device_stencil_function)(gs_device_t *device,
enum gs_stencil_side side, enum gs_depth_test test);
enum gs_stencil_side side,
enum gs_depth_test test);
void (*device_stencil_op)(gs_device_t *device,
enum gs_stencil_side side,
enum gs_stencil_op_type fail,
enum gs_stencil_op_type zfail,
enum gs_stencil_op_type zpass);
enum gs_stencil_side side,
enum gs_stencil_op_type fail,
enum gs_stencil_op_type zfail,
enum gs_stencil_op_type zpass);
void (*device_set_viewport)(gs_device_t *device, int x, int y,
int width, int height);
int width, int height);
void (*device_get_viewport)(const gs_device_t *device,
struct gs_rect *rect);
struct gs_rect *rect);
void (*device_set_scissor_rect)(gs_device_t *device,
const struct gs_rect *rect);
const struct gs_rect *rect);
void (*device_ortho)(gs_device_t *device, float left, float right,
float top, float bottom, float znear, float zfar);
float top, float bottom, float znear, float zfar);
void (*device_frustum)(gs_device_t *device, float left, float right,
float top, float bottom, float znear, float zfar);
float top, float bottom, float znear,
float zfar);
void (*device_projection_push)(gs_device_t *device);
void (*device_projection_pop)(gs_device_t *device);
void (*gs_swapchain_destroy)(gs_swapchain_t *swapchain);
void (*gs_swapchain_destroy)(gs_swapchain_t *swapchain);
void (*gs_texture_destroy)(gs_texture_t *tex);
void (*gs_texture_destroy)(gs_texture_t *tex);
uint32_t (*gs_texture_get_width)(const gs_texture_t *tex);
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);
bool (*gs_texture_map)(gs_texture_t *tex, uint8_t **ptr,
uint32_t *linesize);
void (*gs_texture_unmap)(gs_texture_t *tex);
bool (*gs_texture_is_rect)(const gs_texture_t *tex);
void *(*gs_texture_get_obj)(const gs_texture_t *tex);
const gs_texture_t *tex);
bool (*gs_texture_map)(gs_texture_t *tex, uint8_t **ptr,
uint32_t *linesize);
void (*gs_texture_unmap)(gs_texture_t *tex);
bool (*gs_texture_is_rect)(const gs_texture_t *tex);
void *(*gs_texture_get_obj)(const gs_texture_t *tex);
void (*gs_cubetexture_destroy)(gs_texture_t *cubetex);
void (*gs_cubetexture_destroy)(gs_texture_t *cubetex);
uint32_t (*gs_cubetexture_get_size)(const gs_texture_t *cubetex);
enum gs_color_format (*gs_cubetexture_get_color_format)(
const gs_texture_t *cubetex);
const gs_texture_t *cubetex);
void (*gs_voltexture_destroy)(gs_texture_t *voltex);
void (*gs_voltexture_destroy)(gs_texture_t *voltex);
uint32_t (*gs_voltexture_get_width)(const gs_texture_t *voltex);
uint32_t (*gs_voltexture_get_height)(const gs_texture_t *voltex);
uint32_t (*gs_voltexture_get_depth)(const gs_texture_t *voltex);
enum gs_color_format (*gs_voltexture_get_color_format)(
const gs_texture_t *voltex);
const gs_texture_t *voltex);
void (*gs_stagesurface_destroy)(gs_stagesurf_t *stagesurf);
void (*gs_stagesurface_destroy)(gs_stagesurf_t *stagesurf);
uint32_t (*gs_stagesurface_get_width)(const gs_stagesurf_t *stagesurf);
uint32_t (*gs_stagesurface_get_height)(const gs_stagesurf_t *stagesurf);
enum gs_color_format (*gs_stagesurface_get_color_format)(
const gs_stagesurf_t *stagesurf);
bool (*gs_stagesurface_map)(gs_stagesurf_t *stagesurf,
uint8_t **data, uint32_t *linesize);
void (*gs_stagesurface_unmap)(gs_stagesurf_t *stagesurf);
const gs_stagesurf_t *stagesurf);
bool (*gs_stagesurface_map)(gs_stagesurf_t *stagesurf, uint8_t **data,
uint32_t *linesize);
void (*gs_stagesurface_unmap)(gs_stagesurf_t *stagesurf);
void (*gs_zstencil_destroy)(gs_zstencil_t *zstencil);
@ -190,98 +208,113 @@ struct gs_exports {
void (*gs_vertexbuffer_destroy)(gs_vertbuffer_t *vertbuffer);
void (*gs_vertexbuffer_flush)(gs_vertbuffer_t *vertbuffer);
void (*gs_vertexbuffer_flush_direct)(gs_vertbuffer_t *vertbuffer,
const struct gs_vb_data *data);
const struct gs_vb_data *data);
struct gs_vb_data *(*gs_vertexbuffer_get_data)(
const gs_vertbuffer_t *vertbuffer);
const gs_vertbuffer_t *vertbuffer);
void (*gs_indexbuffer_destroy)(gs_indexbuffer_t *indexbuffer);
void (*gs_indexbuffer_flush)(gs_indexbuffer_t *indexbuffer);
void (*gs_indexbuffer_flush_direct)(gs_indexbuffer_t *indexbuffer,
const void *data);
void *(*gs_indexbuffer_get_data)(const gs_indexbuffer_t *indexbuffer);
void (*gs_indexbuffer_destroy)(gs_indexbuffer_t *indexbuffer);
void (*gs_indexbuffer_flush)(gs_indexbuffer_t *indexbuffer);
void (*gs_indexbuffer_flush_direct)(gs_indexbuffer_t *indexbuffer,
const void *data);
void *(*gs_indexbuffer_get_data)(const gs_indexbuffer_t *indexbuffer);
size_t (*gs_indexbuffer_get_num_indices)(
const gs_indexbuffer_t *indexbuffer);
const gs_indexbuffer_t *indexbuffer);
enum gs_index_type (*gs_indexbuffer_get_type)(
const gs_indexbuffer_t *indexbuffer);
const gs_indexbuffer_t *indexbuffer);
void (*gs_timer_destroy)(gs_timer_t *timer);
void (*gs_timer_begin)(gs_timer_t *timer);
void (*gs_timer_end)(gs_timer_t *timer);
bool (*gs_timer_get_data)(gs_timer_t *timer, uint64_t *ticks);
void (*gs_timer_range_destroy)(gs_timer_range_t *range);
bool (*gs_timer_range_begin)(gs_timer_range_t *range);
bool (*gs_timer_range_end)(gs_timer_range_t *range);
bool (*gs_timer_range_get_data)(gs_timer_range_t *range, bool *disjoint,
uint64_t *frequency);
void (*gs_shader_destroy)(gs_shader_t *shader);
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);
uint32_t param);
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);
const char *name);
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);
void (*gs_shader_get_param_info)(const gs_sparam_t *param,
struct gs_shader_param_info *info);
struct gs_shader_param_info *info);
void (*gs_shader_set_bool)(gs_sparam_t *param, bool val);
void (*gs_shader_set_float)(gs_sparam_t *param, float val);
void (*gs_shader_set_int)(gs_sparam_t *param, int val);
void (*gs_shader_set_matrix3)(gs_sparam_t *param,
const struct matrix3 *val);
const struct matrix3 *val);
void (*gs_shader_set_matrix4)(gs_sparam_t *param,
const struct matrix4 *val);
const struct matrix4 *val);
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);
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);
void (*gs_shader_set_val)(gs_sparam_t *param, const void *val,
size_t size);
size_t size);
void (*gs_shader_set_default)(gs_sparam_t *param);
void (*gs_shader_set_next_sampler)(gs_sparam_t *param,
gs_samplerstate_t *sampler);
gs_samplerstate_t *sampler);
bool (*device_nv12_available)(gs_device_t *device);
void (*device_debug_marker_begin)(gs_device_t *device,
const char *markername, const float color[4]);
const char *markername,
const float color[4]);
void (*device_debug_marker_end)(gs_device_t *device);
#ifdef __APPLE__
/* OSX/Cocoa specific functions */
gs_texture_t *(*device_texture_create_from_iosurface)(gs_device_t *dev,
void *iosurf);
void *iosurf);
bool (*gs_texture_rebind_iosurface)(gs_texture_t *texture,
void *iosurf);
void *iosurf);
#elif _WIN32
bool (*device_gdi_texture_available)(void);
bool (*device_shared_texture_available)(void);
bool (*device_get_duplicator_monitor_info)(gs_device_t *device,
int monitor_idx, struct gs_monitor_info *monitor_info);
bool (*device_get_duplicator_monitor_info)(
gs_device_t *device, int monitor_idx,
struct gs_monitor_info *monitor_info);
gs_duplicator_t *(*device_duplicator_create)(gs_device_t *device,
int monitor_idx);
int monitor_idx);
void (*gs_duplicator_destroy)(gs_duplicator_t *duplicator);
bool (*gs_duplicator_update_frame)(gs_duplicator_t *duplicator);
gs_texture_t *(*gs_duplicator_get_texture)(gs_duplicator_t *duplicator);
gs_texture_t *(*device_texture_create_gdi)(gs_device_t *device,
uint32_t width, uint32_t height);
uint32_t width,
uint32_t height);
void *(*gs_texture_get_dc)(gs_texture_t *gdi_tex);
void (*gs_texture_release_dc)(gs_texture_t *gdi_tex);
gs_texture_t *(*device_texture_open_shared)(gs_device_t *device,
uint32_t handle);
uint32_t handle);
uint32_t (*device_texture_get_shared_handle)(gs_texture_t *tex);
int (*device_texture_acquire_sync)(gs_texture_t *tex, uint64_t key,
uint32_t ms);
uint32_t ms);
int (*device_texture_release_sync)(gs_texture_t *tex, uint64_t key);
bool (*device_texture_create_nv12)(gs_device_t *device,
gs_texture_t **tex_y, gs_texture_t **tex_uv,
uint32_t width, uint32_t height, uint32_t flags);
gs_texture_t **tex_y,
gs_texture_t **tex_uv,
uint32_t width, uint32_t height,
uint32_t flags);
gs_stagesurf_t *(*device_stagesurface_create_nv12)(gs_device_t *device,
uint32_t width, uint32_t height);
uint32_t width,
uint32_t height);
#endif
};
struct blend_state {
bool enabled;
bool enabled;
enum gs_blend_type src_c;
enum gs_blend_type dest_c;
enum gs_blend_type src_a;
@ -289,34 +322,34 @@ struct blend_state {
};
struct graphics_subsystem {
void *module;
gs_device_t *device;
struct gs_exports exports;
void *module;
gs_device_t *device;
struct gs_exports exports;
DARRAY(struct gs_rect) viewport_stack;
DARRAY(struct matrix4) matrix_stack;
size_t cur_matrix;
size_t cur_matrix;
struct matrix4 projection;
struct gs_effect *cur_effect;
struct matrix4 projection;
struct gs_effect *cur_effect;
gs_vertbuffer_t *sprite_buffer;
gs_vertbuffer_t *sprite_buffer;
bool using_immediate;
struct gs_vb_data *vbd;
gs_vertbuffer_t *immediate_vertbuffer;
DARRAY(struct vec3) verts;
DARRAY(struct vec3) norms;
DARRAY(uint32_t) colors;
DARRAY(struct vec2) texverts[16];
bool using_immediate;
struct gs_vb_data *vbd;
gs_vertbuffer_t *immediate_vertbuffer;
DARRAY(struct vec3) verts;
DARRAY(struct vec3) norms;
DARRAY(uint32_t) colors;
DARRAY(struct vec2) texverts[16];
pthread_mutex_t effect_mutex;
struct gs_effect *first_effect;
pthread_mutex_t effect_mutex;
struct gs_effect *first_effect;
pthread_mutex_t mutex;
volatile long ref;
pthread_mutex_t mutex;
volatile long ref;
struct blend_state cur_blend_state;
struct blend_state cur_blend_state;
DARRAY(struct blend_state) blend_state_stack;
};

View file

@ -2,7 +2,7 @@
#include "obsconfig.h"
#define MAGICKCORE_QUANTUM_DEPTH 16
#define MAGICKCORE_HDRI_ENABLE 0
#define MAGICKCORE_HDRI_ENABLE 0
#if LIBOBS_IMAGEMAGICK_DIR_STYLE == LIBOBS_IMAGEMAGICK_DIR_STYLE_6L
#include <magick/MagickCore.h>
@ -21,33 +21,34 @@ void gs_free_image_deps()
}
uint8_t *gs_create_texture_file_data(const char *file,
enum gs_color_format *format,
uint32_t *cx_out, uint32_t *cy_out)
enum gs_color_format *format,
uint32_t *cx_out, uint32_t *cy_out)
{
uint8_t *data = NULL;
ImageInfo *info;
uint8_t *data = NULL;
ImageInfo *info;
ExceptionInfo *exception;
Image *image;
Image *image;
if (!file || !*file)
return NULL;
info = CloneImageInfo(NULL);
info = CloneImageInfo(NULL);
exception = AcquireExceptionInfo();
strcpy(info->filename, file);
image = ReadImage(info, exception);
if (image) {
size_t cx = image->magick_columns;
size_t cy = image->magick_rows;
data = bmalloc(cx * cy * 4);
size_t cx = image->magick_columns;
size_t cy = image->magick_rows;
data = bmalloc(cx * cy * 4);
ExportImagePixels(image, 0, 0, cx, cy, "BGRA", CharPixel,
data, exception);
ExportImagePixels(image, 0, 0, cx, cy, "BGRA", CharPixel, data,
exception);
if (exception->severity != UndefinedException) {
blog(LOG_WARNING, "magickcore warning/error getting "
"pixels from file '%s': %s", file,
exception->reason);
blog(LOG_WARNING,
"magickcore warning/error getting "
"pixels from file '%s': %s",
file, exception->reason);
bfree(data);
data = NULL;
}
@ -58,8 +59,10 @@ uint8_t *gs_create_texture_file_data(const char *file,
DestroyImage(image);
} else if (exception->severity != UndefinedException) {
blog(LOG_WARNING, "magickcore warning/error reading file "
"'%s': %s", file, exception->reason);
blog(LOG_WARNING,
"magickcore warning/error reading file "
"'%s': %s",
file, exception->reason);
}
DestroyImageInfo(info);

File diff suppressed because it is too large Load diff

View file

@ -50,7 +50,7 @@ enum gs_draw_mode {
GS_LINES,
GS_LINESTRIP,
GS_TRIS,
GS_TRISTRIP
GS_TRISTRIP,
};
enum gs_color_format {
@ -80,18 +80,18 @@ enum gs_zstencil_format {
GS_Z16,
GS_Z24_S8,
GS_Z32F,
GS_Z32F_S8X24
GS_Z32F_S8X24,
};
enum gs_index_type {
GS_UNSIGNED_SHORT,
GS_UNSIGNED_LONG
GS_UNSIGNED_LONG,
};
enum gs_cull_mode {
GS_BACK,
GS_FRONT,
GS_NEITHER
GS_NEITHER,
};
enum gs_blend_type {
@ -105,7 +105,7 @@ enum gs_blend_type {
GS_BLEND_INVDSTCOLOR,
GS_BLEND_DSTALPHA,
GS_BLEND_INVDSTALPHA,
GS_BLEND_SRCALPHASAT
GS_BLEND_SRCALPHASAT,
};
enum gs_depth_test {
@ -116,13 +116,13 @@ enum gs_depth_test {
GS_GEQUAL,
GS_GREATER,
GS_NOTEQUAL,
GS_ALWAYS
GS_ALWAYS,
};
enum gs_stencil_side {
GS_STENCIL_FRONT=1,
GS_STENCIL_FRONT = 1,
GS_STENCIL_BACK,
GS_STENCIL_BOTH
GS_STENCIL_BOTH,
};
enum gs_stencil_op_type {
@ -131,7 +131,7 @@ enum gs_stencil_op_type {
GS_REPLACE,
GS_INCR,
GS_DECR,
GS_INVERT
GS_INVERT,
};
enum gs_cube_sides {
@ -140,7 +140,7 @@ enum gs_cube_sides {
GS_POSITIVE_Y,
GS_NEGATIVE_Y,
GS_POSITIVE_Z,
GS_NEGATIVE_Z
GS_NEGATIVE_Z,
};
enum gs_sample_filter {
@ -160,13 +160,13 @@ enum gs_address_mode {
GS_ADDRESS_WRAP,
GS_ADDRESS_MIRROR,
GS_ADDRESS_BORDER,
GS_ADDRESS_MIRRORONCE
GS_ADDRESS_MIRRORONCE,
};
enum gs_texture_type {
GS_TEXTURE_2D,
GS_TEXTURE_3D,
GS_TEXTURE_CUBE
GS_TEXTURE_CUBE,
};
struct gs_monitor_info {
@ -195,7 +195,7 @@ struct gs_vb_data {
static inline struct gs_vb_data *gs_vbdata_create(void)
{
return (struct gs_vb_data*)bzalloc(sizeof(struct gs_vb_data));
return (struct gs_vb_data *)bzalloc(sizeof(struct gs_vb_data));
}
static inline void gs_vbdata_destroy(struct gs_vb_data *data)
@ -247,6 +247,7 @@ struct gs_index_buffer;
struct gs_sampler_state;
struct gs_shader;
struct gs_swap_chain;
struct gs_timer;
struct gs_texrender;
struct gs_shader_param;
struct gs_effect;
@ -256,22 +257,24 @@ struct gs_effect_param;
struct gs_device;
struct graphics_subsystem;
typedef struct gs_texture gs_texture_t;
typedef struct gs_stage_surface gs_stagesurf_t;
typedef struct gs_zstencil_buffer gs_zstencil_t;
typedef struct gs_vertex_buffer gs_vertbuffer_t;
typedef struct gs_index_buffer gs_indexbuffer_t;
typedef struct gs_sampler_state gs_samplerstate_t;
typedef struct gs_swap_chain gs_swapchain_t;
typedef struct gs_texture_render gs_texrender_t;
typedef struct gs_shader gs_shader_t;
typedef struct gs_shader_param gs_sparam_t;
typedef struct gs_effect gs_effect_t;
typedef struct gs_texture gs_texture_t;
typedef struct gs_stage_surface gs_stagesurf_t;
typedef struct gs_zstencil_buffer gs_zstencil_t;
typedef struct gs_vertex_buffer gs_vertbuffer_t;
typedef struct gs_index_buffer gs_indexbuffer_t;
typedef struct gs_sampler_state gs_samplerstate_t;
typedef struct gs_swap_chain gs_swapchain_t;
typedef struct gs_timer gs_timer_t;
typedef struct gs_timer_range gs_timer_range_t;
typedef struct gs_texture_render gs_texrender_t;
typedef struct gs_shader gs_shader_t;
typedef struct gs_shader_param gs_sparam_t;
typedef struct gs_effect gs_effect_t;
typedef struct gs_effect_technique gs_technique_t;
typedef struct gs_effect_pass gs_epass_t;
typedef struct gs_effect_param gs_eparam_t;
typedef struct gs_device gs_device_t;
typedef struct graphics_subsystem graphics_t;
typedef struct gs_effect_pass gs_epass_t;
typedef struct gs_effect_param gs_eparam_t;
typedef struct gs_device gs_device_t;
typedef struct graphics_subsystem graphics_t;
/* ---------------------------------------------------
* shader functions
@ -308,20 +311,22 @@ EXPORT void gs_shader_destroy(gs_shader_t *shader);
EXPORT int gs_shader_get_num_params(const gs_shader_t *shader);
EXPORT gs_sparam_t *gs_shader_get_param_by_idx(gs_shader_t *shader,
uint32_t param);
uint32_t param);
EXPORT gs_sparam_t *gs_shader_get_param_by_name(gs_shader_t *shader,
const char *name);
const char *name);
EXPORT gs_sparam_t *gs_shader_get_viewproj_matrix(const gs_shader_t *shader);
EXPORT gs_sparam_t *gs_shader_get_world_matrix(const gs_shader_t *shader);
EXPORT void gs_shader_get_param_info(const gs_sparam_t *param,
struct gs_shader_param_info *info);
struct gs_shader_param_info *info);
EXPORT void gs_shader_set_bool(gs_sparam_t *param, bool val);
EXPORT void gs_shader_set_float(gs_sparam_t *param, float val);
EXPORT void gs_shader_set_int(gs_sparam_t *param, int val);
EXPORT void gs_shader_set_matrix3(gs_sparam_t *param, const struct matrix3 *val);
EXPORT void gs_shader_set_matrix4(gs_sparam_t *param, const struct matrix4 *val);
EXPORT void gs_shader_set_matrix3(gs_sparam_t *param,
const struct matrix3 *val);
EXPORT void gs_shader_set_matrix4(gs_sparam_t *param,
const struct matrix4 *val);
EXPORT void gs_shader_set_vec2(gs_sparam_t *param, const struct vec2 *val);
EXPORT void gs_shader_set_vec3(gs_sparam_t *param, const struct vec3 *val);
EXPORT void gs_shader_set_vec4(gs_sparam_t *param, const struct vec4 *val);
@ -329,7 +334,7 @@ EXPORT void gs_shader_set_texture(gs_sparam_t *param, gs_texture_t *val);
EXPORT void gs_shader_set_val(gs_sparam_t *param, const void *val, size_t size);
EXPORT void gs_shader_set_default(gs_sparam_t *param);
EXPORT void gs_shader_set_next_sampler(gs_sparam_t *param,
gs_samplerstate_t *sampler);
gs_samplerstate_t *sampler);
#endif
/* ---------------------------------------------------
@ -359,32 +364,33 @@ struct gs_effect_param_info {
EXPORT void gs_effect_destroy(gs_effect_t *effect);
EXPORT gs_technique_t *gs_effect_get_technique(const gs_effect_t *effect,
const char *name);
const char *name);
EXPORT gs_technique_t *gs_effect_get_current_technique(
const gs_effect_t *effect);
EXPORT gs_technique_t *
gs_effect_get_current_technique(const gs_effect_t *effect);
EXPORT size_t gs_technique_begin(gs_technique_t *technique);
EXPORT void gs_technique_end(gs_technique_t *technique);
EXPORT bool gs_technique_begin_pass(gs_technique_t *technique, size_t pass);
EXPORT bool gs_technique_begin_pass_by_name(gs_technique_t *technique,
const char *name);
const char *name);
EXPORT void gs_technique_end_pass(gs_technique_t *technique);
EXPORT gs_epass_t *gs_technique_get_pass_by_idx(const gs_technique_t *technique,
size_t pass);
EXPORT gs_epass_t *gs_technique_get_pass_by_name(
const gs_technique_t *technique, const char *name);
size_t pass);
EXPORT gs_epass_t *
gs_technique_get_pass_by_name(const gs_technique_t *technique,
const char *name);
EXPORT size_t gs_effect_get_num_params(const gs_effect_t *effect);
EXPORT gs_eparam_t *gs_effect_get_param_by_idx(const gs_effect_t *effect,
size_t param);
size_t param);
EXPORT gs_eparam_t *gs_effect_get_param_by_name(const gs_effect_t *effect,
const char *name);
const char *name);
EXPORT size_t gs_param_get_num_annotations(const gs_eparam_t *param);
EXPORT gs_eparam_t *gs_param_get_annotation_by_idx(const gs_eparam_t *param,
size_t annotation);
size_t annotation);
EXPORT gs_eparam_t *gs_param_get_annotation_by_name(const gs_eparam_t *param,
const char *name);
const char *name);
/** Helper function to simplify effect usage. Use with a while loop that
* contains drawing functions. Automatically handles techniques, passes, and
@ -399,14 +405,14 @@ EXPORT gs_eparam_t *gs_effect_get_world_matrix(const gs_effect_t *effect);
#ifndef SWIG
EXPORT void gs_effect_get_param_info(const gs_eparam_t *param,
struct gs_effect_param_info *info);
struct gs_effect_param_info *info);
#endif
EXPORT void gs_effect_set_bool(gs_eparam_t *param, bool val);
EXPORT void gs_effect_set_float(gs_eparam_t *param, float val);
EXPORT void gs_effect_set_int(gs_eparam_t *param, int val);
EXPORT void gs_effect_set_matrix4(gs_eparam_t *param,
const struct matrix4 *val);
const struct matrix4 *val);
EXPORT void gs_effect_set_vec2(gs_eparam_t *param, const struct vec2 *val);
EXPORT void gs_effect_set_vec3(gs_eparam_t *param, const struct vec3 *val);
EXPORT void gs_effect_set_vec4(gs_eparam_t *param, const struct vec4 *val);
@ -418,7 +424,7 @@ EXPORT void *gs_effect_get_val(gs_eparam_t *param);
EXPORT size_t gs_effect_get_default_val_size(gs_eparam_t *param);
EXPORT void *gs_effect_get_default_val(gs_eparam_t *param);
EXPORT void gs_effect_set_next_sampler(gs_eparam_t *param,
gs_samplerstate_t *sampler);
gs_samplerstate_t *sampler);
EXPORT void gs_effect_set_color(gs_eparam_t *param, uint32_t argb);
@ -427,10 +433,10 @@ EXPORT void gs_effect_set_color(gs_eparam_t *param, uint32_t argb);
* --------------------------------------------------- */
EXPORT gs_texrender_t *gs_texrender_create(enum gs_color_format format,
enum gs_zstencil_format zsformat);
enum gs_zstencil_format zsformat);
EXPORT void gs_texrender_destroy(gs_texrender_t *texrender);
EXPORT bool gs_texrender_begin(gs_texrender_t *texrender, uint32_t cx,
uint32_t cy);
uint32_t cy);
EXPORT void gs_texrender_end(gs_texrender_t *texrender);
EXPORT void gs_texrender_reset(gs_texrender_t *texrender);
EXPORT gs_texture_t *gs_texrender_get_texture(const gs_texrender_t *texrender);
@ -439,60 +445,62 @@ EXPORT gs_texture_t *gs_texrender_get_texture(const gs_texrender_t *texrender);
* graphics subsystem
* --------------------------------------------------- */
#define GS_BUILD_MIPMAPS (1<<0)
#define GS_DYNAMIC (1<<1)
#define GS_RENDER_TARGET (1<<2)
#define GS_GL_DUMMYTEX (1<<3) /**<< texture with no allocated texture data */
#define GS_DUP_BUFFER (1<<4) /**<< do not pass buffer ownership when
#define GS_BUILD_MIPMAPS (1 << 0)
#define GS_DYNAMIC (1 << 1)
#define GS_RENDER_TARGET (1 << 2)
#define GS_GL_DUMMYTEX (1 << 3) /**<< texture with no allocated texture data */
#define GS_DUP_BUFFER \
(1 << 4) /**<< do not pass buffer ownership when
* creating a vertex/index buffer */
#define GS_SHARED_TEX (1<<5)
#define GS_SHARED_KM_TEX (1<<6)
#define GS_SHARED_TEX (1 << 5)
#define GS_SHARED_KM_TEX (1 << 6)
/* ---------------- */
/* global functions */
#define GS_SUCCESS 0
#define GS_ERROR_FAIL -1
#define GS_SUCCESS 0
#define GS_ERROR_FAIL -1
#define GS_ERROR_MODULE_NOT_FOUND -2
#define GS_ERROR_NOT_SUPPORTED -3
#define GS_ERROR_NOT_SUPPORTED -3
struct gs_window {
#if defined(_WIN32)
void *hwnd;
void *hwnd;
#elif defined(__APPLE__)
__unsafe_unretained id view;
__unsafe_unretained id view;
#elif defined(__linux__) || defined(__FreeBSD__)
/* I'm not sure how portable defining id to uint32_t is. */
uint32_t id;
void* display;
void *display;
#endif
};
struct gs_init_data {
struct gs_window window;
uint32_t cx, cy;
uint32_t num_backbuffers;
enum gs_color_format format;
struct gs_window window;
uint32_t cx, cy;
uint32_t num_backbuffers;
enum gs_color_format format;
enum gs_zstencil_format zsformat;
uint32_t adapter;
uint32_t adapter;
};
#define GS_DEVICE_OPENGL 1
#define GS_DEVICE_OPENGL 1
#define GS_DEVICE_DIRECT3D_11 2
EXPORT const char *gs_get_device_name(void);
EXPORT int gs_get_device_type(void);
EXPORT void gs_enum_adapters(
bool (*callback)(void *param, const char *name, uint32_t id),
void *param);
EXPORT void gs_enum_adapters(bool (*callback)(void *param, const char *name,
uint32_t id),
void *param);
EXPORT int gs_create(graphics_t **graphics, const char *module,
uint32_t adapter);
uint32_t adapter);
EXPORT void gs_destroy(graphics_t *graphics);
EXPORT void gs_enter_context(graphics_t *graphics);
EXPORT void gs_leave_context(void);
EXPORT graphics_t *gs_get_context(void);
EXPORT void *gs_get_device_obj(void);
EXPORT void gs_matrix_push(void);
EXPORT void gs_matrix_pop(void);
@ -527,21 +535,22 @@ EXPORT input_t *gs_get_input(void);
EXPORT gs_effect_t *gs_get_effect(void);
EXPORT gs_effect_t *gs_effect_create_from_file(const char *file,
char **error_string);
char **error_string);
EXPORT gs_effect_t *gs_effect_create(const char *effect_string,
const char *filename, char **error_string);
const char *filename, char **error_string);
EXPORT gs_shader_t *gs_vertexshader_create_from_file(const char *file,
char **error_string);
char **error_string);
EXPORT gs_shader_t *gs_pixelshader_create_from_file(const char *file,
char **error_string);
char **error_string);
EXPORT gs_texture_t *gs_texture_create_from_file(const char *file);
EXPORT uint8_t *gs_create_texture_file_data(const char *file,
enum gs_color_format *format, uint32_t *cx, uint32_t *cy);
enum gs_color_format *format,
uint32_t *cx, uint32_t *cy);
#define GS_FLIP_U (1<<0)
#define GS_FLIP_V (1<<1)
#define GS_FLIP_U (1 << 0)
#define GS_FLIP_V (1 << 1)
/**
* Draws a 2D sprite
@ -551,13 +560,15 @@ EXPORT uint8_t *gs_create_texture_file_data(const char *file,
* axis with GS_FLIP_U and GS_FLIP_V.
*/
EXPORT void gs_draw_sprite(gs_texture_t *tex, uint32_t flip, uint32_t width,
uint32_t height);
uint32_t height);
EXPORT void gs_draw_sprite_subregion(gs_texture_t *tex, uint32_t flip,
uint32_t x, uint32_t y, uint32_t cx, uint32_t cy);
uint32_t x, uint32_t y, uint32_t cx,
uint32_t cy);
EXPORT void gs_draw_cube_backdrop(gs_texture_t *cubetex, const struct quat *rot,
float left, float right, float top, float bottom, float znear);
float left, float right, float top,
float bottom, float znear);
/** sets the viewport to current swap chain size */
EXPORT void gs_reset_viewport(void);
@ -571,9 +582,10 @@ EXPORT void gs_viewport_push(void);
EXPORT void gs_viewport_pop(void);
EXPORT void gs_texture_set_image(gs_texture_t *tex, const uint8_t *data,
uint32_t linesize, bool invert);
uint32_t linesize, bool invert);
EXPORT void gs_cubetexture_set_image(gs_texture_t *cubetex, uint32_t side,
const void *data, uint32_t linesize, bool invert);
const void *data, uint32_t linesize,
bool invert);
EXPORT void gs_perspective(float fovy, float aspect, float znear, float zfar);
@ -592,33 +604,41 @@ EXPORT uint32_t gs_get_width(void);
EXPORT uint32_t gs_get_height(void);
EXPORT gs_texture_t *gs_texture_create(uint32_t width, uint32_t height,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *gs_cubetexture_create(uint32_t size,
enum gs_color_format color_format, uint32_t levels,
const uint8_t **data, uint32_t flags);
enum gs_color_format color_format,
uint32_t levels, const uint8_t **data,
uint32_t flags);
EXPORT gs_texture_t *
gs_cubetexture_create(uint32_t size, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
EXPORT gs_texture_t *gs_voltexture_create(uint32_t width, uint32_t height,
uint32_t depth, enum gs_color_format color_format,
uint32_t levels, const uint8_t **data, uint32_t flags);
uint32_t depth,
enum gs_color_format color_format,
uint32_t levels, const uint8_t **data,
uint32_t flags);
EXPORT gs_zstencil_t *gs_zstencil_create(uint32_t width, uint32_t height,
enum gs_zstencil_format format);
enum gs_zstencil_format format);
EXPORT gs_stagesurf_t *gs_stagesurface_create(uint32_t width, uint32_t height,
enum gs_color_format color_format);
EXPORT gs_stagesurf_t *
gs_stagesurface_create(uint32_t width, uint32_t height,
enum gs_color_format color_format);
EXPORT gs_samplerstate_t *gs_samplerstate_create(
const struct gs_sampler_info *info);
EXPORT gs_samplerstate_t *
gs_samplerstate_create(const struct gs_sampler_info *info);
EXPORT gs_shader_t *gs_vertexshader_create(const char *shader,
const char *file, char **error_string);
EXPORT gs_shader_t *gs_pixelshader_create(const char *shader,
const char *file, char **error_string);
EXPORT gs_shader_t *gs_vertexshader_create(const char *shader, const char *file,
char **error_string);
EXPORT gs_shader_t *gs_pixelshader_create(const char *shader, const char *file,
char **error_string);
EXPORT gs_vertbuffer_t *gs_vertexbuffer_create(struct gs_vb_data *data,
uint32_t flags);
uint32_t flags);
EXPORT gs_indexbuffer_t *gs_indexbuffer_create(enum gs_index_type type,
void *indices, size_t num, uint32_t flags);
void *indices, size_t num,
uint32_t flags);
EXPORT gs_timer_t *gs_timer_create();
EXPORT gs_timer_range_t *gs_timer_range_create();
EXPORT enum gs_texture_type gs_get_texture_type(const gs_texture_t *texture);
@ -634,32 +654,32 @@ EXPORT void gs_load_default_samplerstate(bool b_3d, int unit);
EXPORT gs_shader_t *gs_get_vertex_shader(void);
EXPORT gs_shader_t *gs_get_pixel_shader(void);
EXPORT gs_texture_t *gs_get_render_target(void);
EXPORT gs_texture_t *gs_get_render_target(void);
EXPORT gs_zstencil_t *gs_get_zstencil_target(void);
EXPORT void gs_set_render_target(gs_texture_t *tex, gs_zstencil_t *zstencil);
EXPORT void gs_set_cube_render_target(gs_texture_t *cubetex, int side,
gs_zstencil_t *zstencil);
gs_zstencil_t *zstencil);
EXPORT void gs_copy_texture(gs_texture_t *dst, gs_texture_t *src);
EXPORT 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,
uint32_t src_w, uint32_t src_h);
EXPORT 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,
uint32_t src_w, uint32_t src_h);
EXPORT void gs_stage_texture(gs_stagesurf_t *dst, gs_texture_t *src);
EXPORT void gs_begin_scene(void);
EXPORT void gs_draw(enum gs_draw_mode draw_mode, uint32_t start_vert,
uint32_t num_verts);
uint32_t num_verts);
EXPORT void gs_end_scene(void);
#define GS_CLEAR_COLOR (1<<0)
#define GS_CLEAR_DEPTH (1<<1)
#define GS_CLEAR_STENCIL (1<<2)
#define GS_CLEAR_COLOR (1 << 0)
#define GS_CLEAR_DEPTH (1 << 1)
#define GS_CLEAR_STENCIL (1 << 2)
EXPORT void gs_load_swapchain(gs_swapchain_t *swapchain);
EXPORT void gs_clear(uint32_t clear_flags, const struct vec4 *color,
float depth, uint8_t stencil);
float depth, uint8_t stencil);
EXPORT void gs_present(void);
EXPORT void gs_flush(void);
@ -673,109 +693,119 @@ EXPORT void gs_enable_stencil_write(bool enable);
EXPORT void gs_enable_color(bool red, bool green, bool blue, bool alpha);
EXPORT void gs_blend_function(enum gs_blend_type src, enum gs_blend_type dest);
EXPORT void gs_blend_function_separate(
enum gs_blend_type src_c, enum gs_blend_type dest_c,
enum gs_blend_type src_a, enum gs_blend_type dest_a);
EXPORT void gs_blend_function_separate(enum gs_blend_type src_c,
enum gs_blend_type dest_c,
enum gs_blend_type src_a,
enum gs_blend_type dest_a);
EXPORT void gs_depth_function(enum gs_depth_test test);
EXPORT void gs_stencil_function(enum gs_stencil_side side,
enum gs_depth_test test);
enum gs_depth_test test);
EXPORT 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);
enum gs_stencil_op_type fail,
enum gs_stencil_op_type zfail,
enum gs_stencil_op_type zpass);
EXPORT void gs_set_viewport(int x, int y, int width, int height);
EXPORT void gs_get_viewport(struct gs_rect *rect);
EXPORT void gs_set_scissor_rect(const struct gs_rect *rect);
EXPORT void gs_ortho(float left, float right, float top, float bottom,
float znear, float zfar);
float znear, float zfar);
EXPORT void gs_frustum(float left, float right, float top, float bottom,
float znear, float zfar);
float znear, float zfar);
EXPORT void gs_projection_push(void);
EXPORT void gs_projection_pop(void);
EXPORT void gs_swapchain_destroy(gs_swapchain_t *swapchain);
EXPORT void gs_swapchain_destroy(gs_swapchain_t *swapchain);
EXPORT void gs_texture_destroy(gs_texture_t *tex);
EXPORT void gs_texture_destroy(gs_texture_t *tex);
EXPORT uint32_t gs_texture_get_width(const gs_texture_t *tex);
EXPORT uint32_t gs_texture_get_height(const gs_texture_t *tex);
EXPORT enum gs_color_format gs_texture_get_color_format(
const gs_texture_t *tex);
EXPORT bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr,
uint32_t *linesize);
EXPORT void gs_texture_unmap(gs_texture_t *tex);
EXPORT enum gs_color_format
gs_texture_get_color_format(const gs_texture_t *tex);
EXPORT bool gs_texture_map(gs_texture_t *tex, uint8_t **ptr,
uint32_t *linesize);
EXPORT void gs_texture_unmap(gs_texture_t *tex);
/** special-case function (GL only) - specifies whether the texture is a
* GL_TEXTURE_RECTANGLE type, which doesn't use normalized texture
* coordinates, doesn't support mipmapping, and requires address clamping */
EXPORT bool gs_texture_is_rect(const gs_texture_t *tex);
EXPORT bool gs_texture_is_rect(const gs_texture_t *tex);
/**
* Gets a pointer to the context-specific object associated with the texture.
* For example, for GL, this is a GLuint*. For D3D11, ID3D11Texture2D*.
*/
EXPORT void *gs_texture_get_obj(gs_texture_t *tex);
EXPORT void *gs_texture_get_obj(gs_texture_t *tex);
EXPORT void gs_cubetexture_destroy(gs_texture_t *cubetex);
EXPORT void gs_cubetexture_destroy(gs_texture_t *cubetex);
EXPORT uint32_t gs_cubetexture_get_size(const gs_texture_t *cubetex);
EXPORT enum gs_color_format gs_cubetexture_get_color_format(
const gs_texture_t *cubetex);
EXPORT enum gs_color_format
gs_cubetexture_get_color_format(const gs_texture_t *cubetex);
EXPORT void gs_voltexture_destroy(gs_texture_t *voltex);
EXPORT void gs_voltexture_destroy(gs_texture_t *voltex);
EXPORT uint32_t gs_voltexture_get_width(const gs_texture_t *voltex);
EXPORT uint32_t gs_voltexture_get_height(const gs_texture_t *voltex);
EXPORT uint32_t gs_voltexture_get_depth(const gs_texture_t *voltex);
EXPORT enum gs_color_format gs_voltexture_get_color_format(
const gs_texture_t *voltex);
EXPORT enum gs_color_format
gs_voltexture_get_color_format(const gs_texture_t *voltex);
EXPORT void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf);
EXPORT void gs_stagesurface_destroy(gs_stagesurf_t *stagesurf);
EXPORT uint32_t gs_stagesurface_get_width(const gs_stagesurf_t *stagesurf);
EXPORT uint32_t gs_stagesurface_get_height(const gs_stagesurf_t *stagesurf);
EXPORT enum gs_color_format gs_stagesurface_get_color_format(
const gs_stagesurf_t *stagesurf);
EXPORT bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data,
uint32_t *linesize);
EXPORT void gs_stagesurface_unmap(gs_stagesurf_t *stagesurf);
EXPORT enum gs_color_format
gs_stagesurface_get_color_format(const gs_stagesurf_t *stagesurf);
EXPORT bool gs_stagesurface_map(gs_stagesurf_t *stagesurf, uint8_t **data,
uint32_t *linesize);
EXPORT void gs_stagesurface_unmap(gs_stagesurf_t *stagesurf);
EXPORT void gs_zstencil_destroy(gs_zstencil_t *zstencil);
EXPORT void gs_zstencil_destroy(gs_zstencil_t *zstencil);
EXPORT void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate);
EXPORT void gs_samplerstate_destroy(gs_samplerstate_t *samplerstate);
EXPORT void gs_vertexbuffer_destroy(gs_vertbuffer_t *vertbuffer);
EXPORT void gs_vertexbuffer_flush(gs_vertbuffer_t *vertbuffer);
EXPORT void gs_vertexbuffer_flush_direct(gs_vertbuffer_t *vertbuffer,
const struct gs_vb_data *data);
EXPORT struct gs_vb_data *gs_vertexbuffer_get_data(
const gs_vertbuffer_t *vertbuffer);
EXPORT void gs_vertexbuffer_destroy(gs_vertbuffer_t *vertbuffer);
EXPORT void gs_vertexbuffer_flush(gs_vertbuffer_t *vertbuffer);
EXPORT void gs_vertexbuffer_flush_direct(gs_vertbuffer_t *vertbuffer,
const struct gs_vb_data *data);
EXPORT struct gs_vb_data *
gs_vertexbuffer_get_data(const gs_vertbuffer_t *vertbuffer);
EXPORT void gs_indexbuffer_destroy(gs_indexbuffer_t *indexbuffer);
EXPORT void gs_indexbuffer_flush(gs_indexbuffer_t *indexbuffer);
EXPORT void gs_indexbuffer_flush_direct(gs_indexbuffer_t *indexbuffer,
const void *data);
EXPORT void *gs_indexbuffer_get_data(const gs_indexbuffer_t *indexbuffer);
EXPORT size_t gs_indexbuffer_get_num_indices(
const gs_indexbuffer_t *indexbuffer);
EXPORT enum gs_index_type gs_indexbuffer_get_type(
const gs_indexbuffer_t *indexbuffer);
EXPORT void gs_indexbuffer_destroy(gs_indexbuffer_t *indexbuffer);
EXPORT void gs_indexbuffer_flush(gs_indexbuffer_t *indexbuffer);
EXPORT void gs_indexbuffer_flush_direct(gs_indexbuffer_t *indexbuffer,
const void *data);
EXPORT void *gs_indexbuffer_get_data(const gs_indexbuffer_t *indexbuffer);
EXPORT size_t
gs_indexbuffer_get_num_indices(const gs_indexbuffer_t *indexbuffer);
EXPORT enum gs_index_type
gs_indexbuffer_get_type(const gs_indexbuffer_t *indexbuffer);
EXPORT bool gs_nv12_available(void);
EXPORT void gs_timer_destroy(gs_timer_t *timer);
EXPORT void gs_timer_begin(gs_timer_t *timer);
EXPORT void gs_timer_end(gs_timer_t *timer);
EXPORT bool gs_timer_get_data(gs_timer_t *timer, uint64_t *ticks);
EXPORT void gs_timer_range_destroy(gs_timer_range_t *timer);
EXPORT void gs_timer_range_begin(gs_timer_range_t *range);
EXPORT void gs_timer_range_end(gs_timer_range_t *range);
EXPORT bool gs_timer_range_get_data(gs_timer_range_t *range, bool *disjoint,
uint64_t *frequency);
EXPORT bool gs_nv12_available(void);
#define GS_USE_DEBUG_MARKERS 0
#if GS_USE_DEBUG_MARKERS
static const float GS_DEBUG_COLOR_DEFAULT[] = { 0.5f, 0.5f, 0.5f, 1.0f };
static const float GS_DEBUG_COLOR_RENDER_VIDEO[] = { 0.0f, 0.5f, 0.0f, 1.0f };
static const float GS_DEBUG_COLOR_MAIN_TEXTURE[] = { 0.0f, 0.25f, 0.0f, 1.0f };
static const float GS_DEBUG_COLOR_DISPLAY[] = { 0.0f, 0.5f, 0.5f, 1.0f };
static const float GS_DEBUG_COLOR_SOURCE[] = { 0.0f, 0.5f, 5.0f, 1.0f };
static const float GS_DEBUG_COLOR_ITEM[] = { 0.5f, 0.0f, 0.0f, 1.0f };
static const float GS_DEBUG_COLOR_ITEM_TEXTURE[] = { 0.25f, 0.0f, 0.0f, 1.0f };
static const float GS_DEBUG_COLOR_CONVERT_FORMAT[] = { 0.5f, 0.5f, 0.0f, 1.0f };
static const float GS_DEBUG_COLOR_DEFAULT[] = {0.5f, 0.5f, 0.5f, 1.0f};
static const float GS_DEBUG_COLOR_RENDER_VIDEO[] = {0.0f, 0.5f, 0.0f, 1.0f};
static const float GS_DEBUG_COLOR_MAIN_TEXTURE[] = {0.0f, 0.25f, 0.0f, 1.0f};
static const float GS_DEBUG_COLOR_DISPLAY[] = {0.0f, 0.5f, 0.5f, 1.0f};
static const float GS_DEBUG_COLOR_SOURCE[] = {0.0f, 0.5f, 5.0f, 1.0f};
static const float GS_DEBUG_COLOR_ITEM[] = {0.5f, 0.0f, 0.0f, 1.0f};
static const float GS_DEBUG_COLOR_ITEM_TEXTURE[] = {0.25f, 0.0f, 0.0f, 1.0f};
static const float GS_DEBUG_COLOR_CONVERT_FORMAT[] = {0.5f, 0.5f, 0.0f, 1.0f};
#define GS_DEBUG_MARKER_BEGIN(color, markername) \
gs_debug_marker_begin(color, markername)
gs_debug_marker_begin(color, markername)
#define GS_DEBUG_MARKER_BEGIN_FORMAT(color, format, ...) \
gs_debug_marker_begin_format(color, format, \
__VA_ARGS__)
gs_debug_marker_begin_format(color, format, __VA_ARGS__)
#define GS_DEBUG_MARKER_END() gs_debug_marker_end()
#else
#define GS_DEBUG_MARKER_BEGIN(color, markername) ((void)0)
@ -783,19 +813,17 @@ static const float GS_DEBUG_COLOR_CONVERT_FORMAT[] = { 0.5f, 0.5f, 0.0f, 1.0f };
#define GS_DEBUG_MARKER_END() ((void)0)
#endif
EXPORT void gs_debug_marker_begin(const float color[4],
const char *markername);
EXPORT void gs_debug_marker_begin_format(const float color[4],
const char *format, ...);
EXPORT void gs_debug_marker_end(void);
EXPORT void gs_debug_marker_begin(const float color[4], const char *markername);
EXPORT void gs_debug_marker_begin_format(const float color[4],
const char *format, ...);
EXPORT void gs_debug_marker_end(void);
#ifdef __APPLE__
/** platform specific function for creating (GL_TEXTURE_RECTANGLE) textures
* from shared surface resources */
EXPORT gs_texture_t *gs_texture_create_from_iosurface(void *iosurf);
EXPORT bool gs_texture_rebind_iosurface(gs_texture_t *texture,
void *iosurf);
EXPORT bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf);
#elif _WIN32
@ -809,8 +837,9 @@ typedef struct gs_duplicator gs_duplicator_t;
* Gets information about the monitor at the specific index, returns false
* when there is no monitor at the specified index
*/
EXPORT bool gs_get_duplicator_monitor_info(int monitor_idx,
struct gs_monitor_info *monitor_info);
EXPORT bool
gs_get_duplicator_monitor_info(int monitor_idx,
struct gs_monitor_info *monitor_info);
/** creates a windows 8+ output duplicator (monitor capture) */
EXPORT gs_duplicator_t *gs_duplicator_create(int monitor_idx);
@ -828,16 +857,17 @@ EXPORT void gs_texture_release_dc(gs_texture_t *gdi_tex);
/** creates a windows shared texture from a texture handle */
EXPORT gs_texture_t *gs_texture_open_shared(uint32_t handle);
#define GS_INVALID_HANDLE (uint32_t)-1
#define GS_INVALID_HANDLE (uint32_t) - 1
EXPORT uint32_t gs_texture_get_shared_handle(gs_texture_t *tex);
#define GS_WAIT_INFINITE (uint32_t)-1
#define GS_WAIT_INFINITE (uint32_t) - 1
/**
* acquires a lock on a keyed mutex texture.
* returns -1 on generic failure, ETIMEDOUT if timed out
*/
EXPORT int gs_texture_acquire_sync(gs_texture_t *tex, uint64_t key, uint32_t ms);
EXPORT int gs_texture_acquire_sync(gs_texture_t *tex, uint64_t key,
uint32_t ms);
/**
* releases a lock on a keyed mutex texture to another device.
@ -846,10 +876,11 @@ EXPORT int gs_texture_acquire_sync(gs_texture_t *tex, uint64_t key, uint32_t ms)
EXPORT int gs_texture_release_sync(gs_texture_t *tex, uint64_t key);
EXPORT bool gs_texture_create_nv12(gs_texture_t **tex_y, gs_texture_t **tex_uv,
uint32_t width, uint32_t height, uint32_t flags);
uint32_t width, uint32_t height,
uint32_t flags);
EXPORT gs_stagesurf_t *gs_stagesurface_create_nv12(
uint32_t width, uint32_t height);
EXPORT gs_stagesurf_t *gs_stagesurface_create_nv12(uint32_t width,
uint32_t height);
#endif
@ -858,25 +889,44 @@ EXPORT gs_stagesurf_t *gs_stagesurface_create_nv12(
static inline uint32_t gs_get_format_bpp(enum gs_color_format format)
{
switch (format) {
case GS_A8: return 8;
case GS_R8: return 8;
case GS_RGBA: return 32;
case GS_BGRX: return 32;
case GS_BGRA: return 32;
case GS_R10G10B10A2: return 32;
case GS_RGBA16: return 64;
case GS_R16: return 16;
case GS_RGBA16F: return 64;
case GS_RGBA32F: return 128;
case GS_RG16F: return 32;
case GS_RG32F: return 64;
case GS_R16F: return 16;
case GS_R32F: return 32;
case GS_DXT1: return 4;
case GS_DXT3: return 8;
case GS_DXT5: return 8;
case GS_R8G8: return 16;
case GS_UNKNOWN: return 0;
case GS_A8:
return 8;
case GS_R8:
return 8;
case GS_RGBA:
return 32;
case GS_BGRX:
return 32;
case GS_BGRA:
return 32;
case GS_R10G10B10A2:
return 32;
case GS_RGBA16:
return 64;
case GS_R16:
return 16;
case GS_RGBA16F:
return 64;
case GS_RGBA32F:
return 128;
case GS_RG16F:
return 32;
case GS_RG32F:
return 64;
case GS_R16F:
return 16;
case GS_R32F:
return 32;
case GS_DXT1:
return 4;
case GS_DXT3:
return 8;
case GS_DXT5:
return 8;
case GS_R8G8:
return 16;
case GS_UNKNOWN:
return 0;
}
return 0;

View file

@ -41,7 +41,7 @@ static bool bi_def_bitmap_test_opaque(void *bitmap)
static unsigned char *bi_def_bitmap_get_buffer(void *bitmap)
{
return (unsigned char*)bitmap;
return (unsigned char *)bitmap;
}
static void bi_def_bitmap_destroy(void *bitmap)
@ -56,11 +56,12 @@ static void bi_def_bitmap_modified(void *bitmap)
static inline int get_full_decoded_gif_size(gs_image_file_t *image)
{
return image->gif.width * image->gif.height * 4 * image->gif.frame_count;
return image->gif.width * image->gif.height * 4 *
image->gif.frame_count;
}
static inline void *alloc_mem(gs_image_file_t *image, uint64_t *mem_usage,
size_t size)
size_t size)
{
UNUSED_PARAMETER(image);
@ -70,7 +71,7 @@ static inline void *alloc_mem(gs_image_file_t *image, uint64_t *mem_usage,
}
static bool init_animated_gif(gs_image_file_t *image, const char *path,
uint64_t *mem_usage)
uint64_t *mem_usage)
{
bool is_animated_gif = true;
gif_result result;
@ -107,24 +108,26 @@ static bool init_animated_gif(gs_image_file_t *image, const char *path,
do {
result = gif_initialise(&image->gif, size, image->gif_data);
if (result < 0) {
blog(LOG_WARNING, "Failed to initialize gif '%s', "
"possible file corruption", path);
blog(LOG_WARNING,
"Failed to initialize gif '%s', "
"possible file corruption",
path);
goto fail;
}
} while (result != GIF_OK);
if (image->gif.width > 4096 || image->gif.height > 4096) {
blog(LOG_WARNING, "Bad texture dimensions (%dx%d) in '%s'",
image->gif.width, image->gif.height, path);
image->gif.width, image->gif.height, path);
goto fail;
}
max_size = (uint64_t)image->gif.width * (uint64_t)image->gif.height *
(uint64_t)image->gif.frame_count * 4LLU;
(uint64_t)image->gif.frame_count * 4LLU;
if ((uint64_t)get_full_decoded_gif_size(image) != max_size) {
blog(LOG_WARNING, "Gif '%s' overflowed maximum pointer size",
path);
path);
goto fail;
}
@ -132,15 +135,18 @@ static bool init_animated_gif(gs_image_file_t *image, const char *path,
if (image->is_animated_gif) {
gif_decode_frame(&image->gif, 0);
image->animation_frame_cache = alloc_mem(image, mem_usage,
image->gif.frame_count * sizeof(uint8_t*));
image->animation_frame_data = alloc_mem(image, mem_usage,
get_full_decoded_gif_size(image));
image->animation_frame_cache =
alloc_mem(image, mem_usage,
image->gif.frame_count * sizeof(uint8_t *));
image->animation_frame_data = alloc_mem(
image, mem_usage, get_full_decoded_gif_size(image));
for (unsigned int i = 0; i < image->gif.frame_count; i++) {
if (gif_decode_frame(&image->gif, i) != GIF_OK)
blog(LOG_WARNING, "Couldn't decode frame %u "
"of '%s'", i, path);
blog(LOG_WARNING,
"Couldn't decode frame %u "
"of '%s'",
i, path);
}
gif_decode_frame(&image->gif, 0);
@ -174,7 +180,7 @@ not_animated:
}
static void gs_image_file_init_internal(gs_image_file_t *image,
const char *file, uint64_t *mem_usage)
const char *file, uint64_t *mem_usage)
{
size_t len;
@ -193,12 +199,12 @@ static void gs_image_file_init_internal(gs_image_file_t *image,
return;
}
image->texture_data = gs_create_texture_file_data(file,
&image->format, &image->cx, &image->cy);
image->texture_data = gs_create_texture_file_data(
file, &image->format, &image->cx, &image->cy);
if (mem_usage) {
*mem_usage += image->cx * image->cy *
gs_get_format_bpp(image->format) / 8;
gs_get_format_bpp(image->format) / 8;
}
image->loaded = !!image->texture_data;
@ -245,14 +251,13 @@ void gs_image_file_init_texture(gs_image_file_t *image)
if (image->is_animated_gif) {
image->texture = gs_texture_create(
image->cx, image->cy, image->format, 1,
(const uint8_t**)&image->gif.frame_image,
GS_DYNAMIC);
image->cx, image->cy, image->format, 1,
(const uint8_t **)&image->gif.frame_image, GS_DYNAMIC);
} else {
image->texture = gs_texture_create(
image->cx, image->cy, image->format, 1,
(const uint8_t**)&image->texture_data, 0);
image->cx, image->cy, image->format, 1,
(const uint8_t **)&image->texture_data, 0);
bfree(image->texture_data);
image->texture_data = NULL;
}
@ -267,7 +272,7 @@ static inline uint64_t get_time(gs_image_file_t *image, int i)
}
static inline int calculate_new_frame(gs_image_file_t *image,
uint64_t elapsed_time_ns, int loops)
uint64_t elapsed_time_ns, int loops)
{
int new_frame = image->cur_frame;
@ -297,8 +302,9 @@ static void decode_new_frame(gs_image_file_t *image, int new_frame)
int last_frame;
/* if looped, decode frame 0 */
last_frame = (new_frame < image->last_decoded_frame) ?
0 : image->last_decoded_frame + 1;
last_frame = (new_frame < image->last_decoded_frame)
? 0
: image->last_decoded_frame + 1;
/* decode missed frames */
for (int i = last_frame; i < new_frame; i++) {
@ -309,14 +315,13 @@ static void decode_new_frame(gs_image_file_t *image, int new_frame)
/* decode actual desired frame */
if (gif_decode_frame(&image->gif, new_frame) == GIF_OK) {
size_t pos = new_frame * image->gif.width *
image->gif.height * 4;
image->gif.height * 4;
image->animation_frame_cache[new_frame] =
image->animation_frame_data + pos;
memcpy(image->animation_frame_cache[new_frame],
image->gif.frame_image,
image->gif.width *
image->gif.height * 4);
image->gif.frame_image,
image->gif.width * image->gif.height * 4);
image->last_decoded_frame = new_frame;
}
@ -337,8 +342,8 @@ bool gs_image_file_tick(gs_image_file_t *image, uint64_t elapsed_time_ns)
loops = 0;
if (!loops || image->cur_loop < loops) {
int new_frame = calculate_new_frame(image, elapsed_time_ns,
loops);
int new_frame =
calculate_new_frame(image, elapsed_time_ns, loops);
if (new_frame != image->cur_frame) {
decode_new_frame(image, new_frame);
@ -358,6 +363,6 @@ void gs_image_file_update_texture(gs_image_file_t *image)
decode_new_frame(image, image->cur_frame);
gs_texture_set_image(image->texture,
image->animation_frame_cache[image->cur_frame],
image->gif.width * 4, false);
image->animation_frame_cache[image->cur_frame],
image->gif.width * 4, false);
}

View file

@ -59,7 +59,7 @@ EXPORT void gs_image_file_free(gs_image_file_t *image);
EXPORT void gs_image_file_init_texture(gs_image_file_t *image);
EXPORT bool gs_image_file_tick(gs_image_file_t *image,
uint64_t elapsed_time_ns);
uint64_t elapsed_time_ns);
EXPORT void gs_image_file_update_texture(gs_image_file_t *image);
EXPORT void gs_image_file2_init(gs_image_file2_t *if2, const char *file);
@ -76,7 +76,7 @@ static inline void gs_image_file2_init_texture(gs_image_file2_t *if2)
}
static inline bool gs_image_file2_tick(gs_image_file2_t *if2,
uint64_t elapsed_time_ns)
uint64_t elapsed_time_ns)
{
return gs_image_file_tick(&if2->image, elapsed_time_ns);
}

View file

@ -23,123 +23,123 @@
extern "C" {
#endif
#define KBC_ESCAPE 0x0
#define KBC_1 0x1
#define KBC_2 0x2
#define KBC_3 0x3
#define KBC_4 0x4
#define KBC_5 0x5
#define KBC_6 0x6
#define KBC_7 0x7
#define KBC_8 0x8
#define KBC_9 0x9
#define KBC_0 0xA
#define KBC_MINUS 0xB
#define KBC_EQUALS 0xC
#define KBC_BACK 0xD
#define KBC_TAB 0xE
#define KBC_Q 0xF
#define KBC_W 0x10
#define KBC_E 0x11
#define KBC_R 0x12
#define KBC_T 0x13
#define KBC_Y 0x14
#define KBC_U 0x15
#define KBC_I 0x16
#define KBC_O 0x17
#define KBC_P 0x18
#define KBC_LBRACKET 0x19
#define KBC_RBRACKET 0x1A
#define KBC_RETURN 0x1B
#define KBC_LCONTROL 0x1C
#define KBC_A 0x1D
#define KBC_S 0x1E
#define KBC_D 0x1F
#define KBC_F 0x20
#define KBC_G 0x21
#define KBC_H 0x22
#define KBC_J 0x23
#define KBC_K 0x24
#define KBC_L 0x25
#define KBC_SEMICOLON 0x26
#define KBC_APOSTROPHE 0x27
#define KBC_TILDE 0x28
#define KBC_LSHIFT 0x29
#define KBC_BACKSLASH 0x2A
#define KBC_Z 0x2B
#define KBC_X 0x2C
#define KBC_C 0x2D
#define KBC_V 0x2E
#define KBC_B 0x2F
#define KBC_N 0x30
#define KBC_M 0x31
#define KBC_COMMA 0x32
#define KBC_PERIOD 0x33
#define KBC_SLASH 0x34
#define KBC_RSHIFT 0x35
#define KBC_MULTIPLY 0x36
#define KBC_LALT 0x37
#define KBC_SPACE 0x38
#define KBC_CAPSLOCK 0x39
#define KBC_F1 0x3A
#define KBC_F2 0x3B
#define KBC_F3 0x3C
#define KBC_F4 0x3D
#define KBC_F5 0x3E
#define KBC_F6 0x3F
#define KBC_F7 0x40
#define KBC_F8 0x41
#define KBC_F9 0x42
#define KBC_F10 0x43
#define KBC_NUMLOCK 0x44
#define KBC_SCROLLLOCK 0x45
#define KBC_NUMPAD7 0x46
#define KBC_NUMPAD8 0x47
#define KBC_NUMPAD9 0x48
#define KBC_SUBTRACT 0x49
#define KBC_NUMPAD4 0x4A
#define KBC_NUMPAD5 0x4B
#define KBC_NUMPAD6 0x4C
#define KBC_ADD 0x4D
#define KBC_NUMPAD1 0x4E
#define KBC_NUMPAD2 0x4F
#define KBC_NUMPAD3 0x50
#define KBC_NUMPAD0 0x51
#define KBC_DECIMAL 0x52
#define KBC_F11 0x53
#define KBC_F12 0x54
#define KBC_NUMPADENTER 0x55
#define KBC_RCONTROL 0x56
#define KBC_DIVIDE 0x57
#define KBC_SYSRQ 0x58
#define KBC_RALT 0x59
#define KBC_PAUSE 0x5A
#define KBC_HOME 0x5B
#define KBC_UP 0x5C
#define KBC_PAGEDOWN 0x5D
#define KBC_LEFT 0x5E
#define KBC_RIGHT 0x5F
#define KBC_END 0x60
#define KBC_DOWN 0x61
#define KBC_PAGEUP 0x62
#define KBC_INSERT 0x63
#define KBC_DELETE 0x64
#define KBC_ESCAPE 0x0
#define KBC_1 0x1
#define KBC_2 0x2
#define KBC_3 0x3
#define KBC_4 0x4
#define KBC_5 0x5
#define KBC_6 0x6
#define KBC_7 0x7
#define KBC_8 0x8
#define KBC_9 0x9
#define KBC_0 0xA
#define KBC_MINUS 0xB
#define KBC_EQUALS 0xC
#define KBC_BACK 0xD
#define KBC_TAB 0xE
#define KBC_Q 0xF
#define KBC_W 0x10
#define KBC_E 0x11
#define KBC_R 0x12
#define KBC_T 0x13
#define KBC_Y 0x14
#define KBC_U 0x15
#define KBC_I 0x16
#define KBC_O 0x17
#define KBC_P 0x18
#define KBC_LBRACKET 0x19
#define KBC_RBRACKET 0x1A
#define KBC_RETURN 0x1B
#define KBC_LCONTROL 0x1C
#define KBC_A 0x1D
#define KBC_S 0x1E
#define KBC_D 0x1F
#define KBC_F 0x20
#define KBC_G 0x21
#define KBC_H 0x22
#define KBC_J 0x23
#define KBC_K 0x24
#define KBC_L 0x25
#define KBC_SEMICOLON 0x26
#define KBC_APOSTROPHE 0x27
#define KBC_TILDE 0x28
#define KBC_LSHIFT 0x29
#define KBC_BACKSLASH 0x2A
#define KBC_Z 0x2B
#define KBC_X 0x2C
#define KBC_C 0x2D
#define KBC_V 0x2E
#define KBC_B 0x2F
#define KBC_N 0x30
#define KBC_M 0x31
#define KBC_COMMA 0x32
#define KBC_PERIOD 0x33
#define KBC_SLASH 0x34
#define KBC_RSHIFT 0x35
#define KBC_MULTIPLY 0x36
#define KBC_LALT 0x37
#define KBC_SPACE 0x38
#define KBC_CAPSLOCK 0x39
#define KBC_F1 0x3A
#define KBC_F2 0x3B
#define KBC_F3 0x3C
#define KBC_F4 0x3D
#define KBC_F5 0x3E
#define KBC_F6 0x3F
#define KBC_F7 0x40
#define KBC_F8 0x41
#define KBC_F9 0x42
#define KBC_F10 0x43
#define KBC_NUMLOCK 0x44
#define KBC_SCROLLLOCK 0x45
#define KBC_NUMPAD7 0x46
#define KBC_NUMPAD8 0x47
#define KBC_NUMPAD9 0x48
#define KBC_SUBTRACT 0x49
#define KBC_NUMPAD4 0x4A
#define KBC_NUMPAD5 0x4B
#define KBC_NUMPAD6 0x4C
#define KBC_ADD 0x4D
#define KBC_NUMPAD1 0x4E
#define KBC_NUMPAD2 0x4F
#define KBC_NUMPAD3 0x50
#define KBC_NUMPAD0 0x51
#define KBC_DECIMAL 0x52
#define KBC_F11 0x53
#define KBC_F12 0x54
#define KBC_NUMPADENTER 0x55
#define KBC_RCONTROL 0x56
#define KBC_DIVIDE 0x57
#define KBC_SYSRQ 0x58
#define KBC_RALT 0x59
#define KBC_PAUSE 0x5A
#define KBC_HOME 0x5B
#define KBC_UP 0x5C
#define KBC_PAGEDOWN 0x5D
#define KBC_LEFT 0x5E
#define KBC_RIGHT 0x5F
#define KBC_END 0x60
#define KBC_DOWN 0x61
#define KBC_PAGEUP 0x62
#define KBC_INSERT 0x63
#define KBC_DELETE 0x64
#define MOUSE_LEFTBUTTON 0x65
#define MOUSE_MIDDLEBUTTON 0x66
#define MOUSE_RIGHTBUTTON 0x67
#define MOUSE_WHEEL 0x68
#define MOUSE_MOVE 0x69
#define MOUSE_LEFTBUTTON 0x65
#define MOUSE_MIDDLEBUTTON 0x66
#define MOUSE_RIGHTBUTTON 0x67
#define MOUSE_WHEEL 0x68
#define MOUSE_MOVE 0x69
#define KBC_CONTROL 0xFFFFFFFE
#define KBC_ALT 0xFFFFFFFD
#define KBC_SHIFT 0xFFFFFFFC
#define KBC_CONTROL 0xFFFFFFFE
#define KBC_ALT 0xFFFFFFFD
#define KBC_SHIFT 0xFFFFFFFC
#define STATE_LBUTTONDOWN (1<<0)
#define STATE_RBUTTONDOWN (1<<1)
#define STATE_MBUTTONDOWN (1<<2)
#define STATE_X4BUTTONDOWN (1<<3)
#define STATE_X5BUTTONDOWN (1<<4)
#define STATE_LBUTTONDOWN (1 << 0)
#define STATE_RBUTTONDOWN (1 << 1)
#define STATE_MBUTTONDOWN (1 << 2)
#define STATE_X4BUTTONDOWN (1 << 3)
#define STATE_X5BUTTONDOWN (1 << 4)
/* wrapped opaque data types */
struct input_subsystem;

View file

@ -0,0 +1,3 @@
Language: Cpp
SortIncludes: false
DisableFormat: true

View file

@ -25,19 +25,19 @@ extern "C" {
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795f
#define M_PI 3.1415926535897932384626433832795f
#endif
#define RAD(val) ((val)*0.0174532925199432957692369076848f)
#define DEG(val) ((val)*57.295779513082320876798154814105f)
#define LARGE_EPSILON 1e-2f
#define EPSILON 1e-4f
#define TINY_EPSILON 1e-5f
#define M_INFINITE 3.4e38f
#define RAD(val) ((val)*0.0174532925199432957692369076848f)
#define DEG(val) ((val)*57.295779513082320876798154814105f)
#define LARGE_EPSILON 1e-2f
#define EPSILON 1e-4f
#define TINY_EPSILON 1e-5f
#define M_INFINITE 3.4e38f
static inline bool close_float(float f1, float f2, float precision)
{
return fabsf(f1-f2) <= precision;
return fabsf(f1 - f2) <= precision;
}
#ifdef __cplusplus

View file

@ -24,12 +24,12 @@
void polar_to_cart(struct vec3 *dst, const struct vec3 *v)
{
struct vec3 cart;
float sinx = cosf(v->x);
float sinx_z = v->z * sinx;
float sinx = cosf(v->x);
float sinx_z = v->z * sinx;
cart.x = sinx_z * sinf(v->y);
cart.z = sinx_z * cosf(v->y);
cart.y = v->z * sinf(v->x);
cart.y = v->z * sinf(v->x);
vec3_copy(dst, &cart);
}
@ -65,28 +65,28 @@ void polar_to_norm(struct vec3 *dst, const struct vec2 *polar)
}
float calc_torquef(float val1, float val2, float torque, float min_adjust,
float t)
float t)
{
float out = val1;
float dist;
bool over;
bool over;
if (close_float(val1, val2, EPSILON))
return val1;
dist = (val2-val1)*torque;
dist = (val2 - val1) * torque;
over = dist > 0.0f;
if (over) {
if (dist < min_adjust) /* prevents from going too slow */
dist = min_adjust;
out += dist*t; /* add torque */
if (out > val2) /* clamp if overshoot */
out += dist * t; /* add torque */
if (out > val2) /* clamp if overshoot */
out = val2;
} else {
if (dist > -min_adjust)
dist = -min_adjust;
out += dist*t;
out += dist * t;
if (out < val2)
out = val2;
}
@ -94,9 +94,8 @@ float calc_torquef(float val1, float val2, float torque, float min_adjust,
return out;
}
void calc_torque(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2, float torque, float min_adjust,
float t)
void calc_torque(struct vec3 *dst, const struct vec3 *v1, const struct vec3 *v2,
float torque, float min_adjust, float t)
{
struct vec3 line, dir;
float orig_dist, torque_dist, adjust_dist;
@ -108,26 +107,26 @@ void calc_torque(struct vec3 *dst, const struct vec3 *v1,
vec3_sub(&line, v2, v1);
orig_dist = vec3_len(&line);
vec3_mulf(&dir, &line, 1.0f/orig_dist);
vec3_mulf(&dir, &line, 1.0f / orig_dist);
torque_dist = orig_dist*torque; /* use distance to determine speed */
if (torque_dist < min_adjust) /* prevent from going too slow */
torque_dist = orig_dist * torque; /* use distance to determine speed */
if (torque_dist < min_adjust) /* prevent from going too slow */
torque_dist = min_adjust;
adjust_dist = torque_dist*t;
adjust_dist = torque_dist * t;
if (adjust_dist <= (orig_dist-LARGE_EPSILON)) {
if (adjust_dist <= (orig_dist - LARGE_EPSILON)) {
vec3_mulf(dst, &dir, adjust_dist);
vec3_add(dst, dst, v1); /* add torque */
} else {
vec3_copy(dst, v2); /* clamp if overshoot */
vec3_copy(dst, v2); /* clamp if overshoot */
}
}
float rand_float(int positive_only)
{
if (positive_only)
return (float)((double)rand()/(double)RAND_MAX);
return (float)((double)rand() / (double)RAND_MAX);
else
return (float)(((double)rand()/(double)RAND_MAX*2.0)-1.0);
return (float)(((double)rand() / (double)RAND_MAX * 2.0) - 1.0);
}

View file

@ -40,20 +40,20 @@ EXPORT void norm_to_polar(struct vec2 *dst, const struct vec3 *norm);
EXPORT void polar_to_norm(struct vec3 *dst, const struct vec2 *polar);
EXPORT float calc_torquef(float val1, float val2, float torque,
float min_adjust, float t);
float min_adjust, float t);
EXPORT void calc_torque(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2, float torque, float min_adjust,
float t);
const struct vec3 *v2, float torque, float min_adjust,
float t);
static inline float get_percentage(float start, float end, float mid)
{
return (mid-start) / (end-start);
return (mid - start) / (end - start);
}
static inline float get_percentagei(int start, int end, int mid)
{
return (float)(mid-start) / (float)(end-start);
return (float)(mid - start) / (float)(end - start);
}
EXPORT float rand_float(int positive_only);

View file

@ -21,11 +21,10 @@
#include "plane.h"
#include "quat.h"
void matrix3_from_quat(struct matrix3 *dst, const struct quat *q)
{
float norm = quat_dot(q, q);
float s = (norm > 0.0f) ? (2.0f/norm) : 0.0f;
float s = (norm > 0.0f) ? (2.0f / norm) : 0.0f;
float xx = q->x * q->x * s;
float yy = q->y * q->y * s;
@ -63,7 +62,7 @@ void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m)
}
void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
const struct matrix3 *m2)
const struct matrix3 *m2)
{
if (dst == m2) {
struct matrix3 temp;
@ -81,7 +80,7 @@ void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
}
void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m,
const struct quat *q)
const struct quat *q)
{
struct matrix3 temp;
matrix3_from_quat(&temp, q);
@ -89,7 +88,7 @@ void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m,
}
void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m,
const struct axisang *aa)
const struct axisang *aa)
{
struct matrix3 temp;
matrix3_from_axisang(&temp, aa);
@ -97,7 +96,7 @@ void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m,
}
void matrix3_scale(struct matrix3 *dst, const struct matrix3 *m,
const struct vec3 *v)
const struct vec3 *v)
{
vec3_mul(&dst->x, &m->x, v);
vec3_mul(&dst->y, &m->y, v);
@ -122,12 +121,12 @@ void matrix3_inv(struct matrix3 *dst, const struct matrix3 *m)
{
struct matrix4 m4;
matrix4_from_matrix3(&m4, m);
matrix4_inv((struct matrix4*)dst, &m4);
matrix4_inv((struct matrix4 *)dst, &m4);
dst->t.w = 0.0f;
}
void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m,
const struct plane *p)
const struct plane *p)
{
vec3_mirrorv(&dst->x, &m->x, &p->dir);
vec3_mirrorv(&dst->y, &m->y, &p->dir);
@ -136,7 +135,7 @@ void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m,
}
void matrix3_mirrorv(struct matrix3 *dst, const struct matrix3 *m,
const struct vec3 *v)
const struct vec3 *v)
{
vec3_mirrorv(&dst->x, &m->x, v);
vec3_mirrorv(&dst->y, &m->y, v);

View file

@ -53,34 +53,35 @@ static inline void matrix3_identity(struct matrix3 *dst)
}
EXPORT void matrix3_from_quat(struct matrix3 *dst, const struct quat *q);
EXPORT void matrix3_from_axisang(struct matrix3 *dst,
const struct axisang *aa);
EXPORT void matrix3_from_axisang(struct matrix3 *dst, const struct axisang *aa);
EXPORT void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m);
EXPORT void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
const struct matrix3 *m2);
const struct matrix3 *m2);
static inline void matrix3_translate(struct matrix3 *dst,
const struct matrix3 *m, const struct vec3 *v)
const struct matrix3 *m,
const struct vec3 *v)
{
vec3_sub(&dst->t, &m->t, v);
}
EXPORT void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m,
const struct quat *q);
const struct quat *q);
EXPORT void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m,
const struct axisang *aa);
const struct axisang *aa);
EXPORT void matrix3_scale(struct matrix3 *dst, const struct matrix3 *m,
const struct vec3 *v);
const struct vec3 *v);
EXPORT void matrix3_transpose(struct matrix3 *dst, const struct matrix3 *m);
EXPORT void matrix3_inv(struct matrix3 *dst, const struct matrix3 *m);
EXPORT void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m,
const struct plane *p);
const struct plane *p);
EXPORT void matrix3_mirrorv(struct matrix3 *dst, const struct matrix3 *m,
const struct vec3 *v);
const struct vec3 *v);
static inline void matrix3_translate3f(struct matrix3 *dst,
const struct matrix3 *m, float x, float y, float z)
const struct matrix3 *m, float x,
float y, float z)
{
struct vec3 v;
vec3_set(&v, x, y, z);
@ -88,15 +89,16 @@ static inline void matrix3_translate3f(struct matrix3 *dst,
}
static inline void matrix3_rotate_aa4f(struct matrix3 *dst,
const struct matrix3 *m, float x, float y, float z, float rot)
const struct matrix3 *m, float x,
float y, float z, float rot)
{
struct axisang aa;
axisang_set(&aa, x, y, z, rot);
matrix3_rotate_aa(dst, m, &aa);
}
static inline void matrix3_scale3f(struct matrix3 *dst,
const struct matrix3 *m, float x, float y, float z)
static inline void matrix3_scale3f(struct matrix3 *dst, const struct matrix3 *m,
float x, float y, float z)
{
struct vec3 v;
vec3_set(&v, x, y, z);

View file

@ -32,7 +32,7 @@ void matrix4_from_matrix3(struct matrix4 *dst, const struct matrix3 *m)
void matrix4_from_quat(struct matrix4 *dst, const struct quat *q)
{
float norm = quat_dot(q, q);
float s = (norm > 0.0f) ? (2.0f/norm) : 0.0f;
float s = (norm > 0.0f) ? (2.0f / norm) : 0.0f;
float xx = q->x * q->x * s;
float yy = q->y * q->y * s;
@ -58,26 +58,27 @@ void matrix4_from_axisang(struct matrix4 *dst, const struct axisang *aa)
}
void matrix4_mul(struct matrix4 *dst, const struct matrix4 *m1,
const struct matrix4 *m2)
const struct matrix4 *m2)
{
const struct vec4 *m1v = (const struct vec4*)m1;
const float *m2f = (const float*)m2;
const struct vec4 *m1v = (const struct vec4 *)m1;
const float *m2f = (const float *)m2;
struct vec4 out[4];
int i, j;
for (i = 0; i < 4; i++) {
for (j=0; j<4; j++) {
for (j = 0; j < 4; j++) {
struct vec4 temp;
vec4_set(&temp, m2f[j], m2f[j+4], m2f[j+8], m2f[j+12]);
vec4_set(&temp, m2f[j], m2f[j + 4], m2f[j + 8],
m2f[j + 12]);
out[i].ptr[j] = vec4_dot(&m1v[i], &temp);
}
}
matrix4_copy(dst, (struct matrix4*)out);
matrix4_copy(dst, (struct matrix4 *)out);
}
static inline void get_3x3_submatrix(float *dst, const struct matrix4 *m,
int i, int j)
static inline void get_3x3_submatrix(float *dst, const struct matrix4 *m, int i,
int j)
{
const float *mf = (const float *)m;
int ti, tj, idst, jdst;
@ -86,7 +87,7 @@ static inline void get_3x3_submatrix(float *dst, const struct matrix4 *m,
if (ti < i)
idst = ti;
else if (ti > i)
idst = ti-1;
idst = ti - 1;
else
continue;
@ -94,20 +95,20 @@ static inline void get_3x3_submatrix(float *dst, const struct matrix4 *m,
if (tj < j)
jdst = tj;
else if (tj > j)
jdst = tj-1;
jdst = tj - 1;
else
continue;
dst[(idst*3) + jdst] = mf[(ti*4) + tj];
dst[(idst * 3) + jdst] = mf[(ti * 4) + tj];
}
}
}
static inline float get_3x3_determinant(const float *m)
{
return (m[0] * ((m[4]*m[8]) - (m[7]*m[5]))) -
(m[1] * ((m[3]*m[8]) - (m[6]*m[5]))) +
(m[2] * ((m[3]*m[7]) - (m[6]*m[4])));
return (m[0] * ((m[4] * m[8]) - (m[7] * m[5]))) -
(m[1] * ((m[3] * m[8]) - (m[6] * m[5]))) +
(m[2] * ((m[3] * m[7]) - (m[6] * m[4])));
}
float matrix4_determinant(const struct matrix4 *m)
@ -117,10 +118,10 @@ float matrix4_determinant(const struct matrix4 *m)
float m3x3[9];
int n;
for (n = 0; n < 4; n++, i *= -1.0f) {
for (n = 0; n < 4; n++, i = -i) { // NOLINT(clang-tidy-cert-flp30-c)
get_3x3_submatrix(m3x3, m, 0, n);
det = get_3x3_determinant(m3x3);
det = get_3x3_determinant(m3x3);
result += mf[n] * det * i;
}
@ -128,7 +129,7 @@ float matrix4_determinant(const struct matrix4 *m)
}
void matrix4_translate3v(struct matrix4 *dst, const struct matrix4 *m,
const struct vec3 *v)
const struct vec3 *v)
{
struct matrix4 temp;
vec4_set(&temp.x, 1.0f, 0.0f, 0.0f, 0.0f);
@ -140,7 +141,7 @@ void matrix4_translate3v(struct matrix4 *dst, const struct matrix4 *m,
}
void matrix4_translate4v(struct matrix4 *dst, const struct matrix4 *m,
const struct vec4 *v)
const struct vec4 *v)
{
struct matrix4 temp;
vec4_set(&temp.x, 1.0f, 0.0f, 0.0f, 0.0f);
@ -152,7 +153,7 @@ void matrix4_translate4v(struct matrix4 *dst, const struct matrix4 *m,
}
void matrix4_rotate(struct matrix4 *dst, const struct matrix4 *m,
const struct quat *q)
const struct quat *q)
{
struct matrix4 temp;
matrix4_from_quat(&temp, q);
@ -160,7 +161,7 @@ void matrix4_rotate(struct matrix4 *dst, const struct matrix4 *m,
}
void matrix4_rotate_aa(struct matrix4 *dst, const struct matrix4 *m,
const struct axisang *aa)
const struct axisang *aa)
{
struct matrix4 temp;
matrix4_from_axisang(&temp, aa);
@ -168,7 +169,7 @@ void matrix4_rotate_aa(struct matrix4 *dst, const struct matrix4 *m,
}
void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m,
const struct vec3 *v)
const struct vec3 *v)
{
struct matrix4 temp;
vec4_set(&temp.x, v->x, 0.0f, 0.0f, 0.0f);
@ -179,7 +180,7 @@ void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m,
}
void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct matrix4 temp;
vec4_set(&temp.x, 1.0f, 0.0f, 0.0f, 0.0f);
@ -191,7 +192,7 @@ void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v,
}
void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct matrix4 temp;
vec4_set(&temp.x, 1.0f, 0.0f, 0.0f, 0.0f);
@ -203,7 +204,7 @@ void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v,
}
void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct matrix4 temp;
matrix4_from_quat(&temp, q);
@ -211,7 +212,7 @@ void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q,
}
void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct matrix4 temp;
matrix4_from_axisang(&temp, aa);
@ -219,7 +220,7 @@ void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa,
}
void matrix4_scale_i(struct matrix4 *dst, const struct vec3 *v,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct matrix4 temp;
vec4_set(&temp.x, v->x, 0.0f, 0.0f, 0.0f);
@ -234,7 +235,7 @@ bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m)
struct vec4 *dstv;
float det;
float m3x3[9];
int i, j, sign;
int i, j, sign;
if (dst == m) {
struct matrix4 temp = *m;
@ -242,17 +243,17 @@ bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m)
}
dstv = (struct vec4 *)dst;
det = matrix4_determinant(m);
det = matrix4_determinant(m);
if (fabs(det) < 0.0005f)
return false;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
sign = 1 - ((i+j) % 2) * 2;
sign = 1 - ((i + j) % 2) * 2;
get_3x3_submatrix(m3x3, m, i, j);
dstv[j].ptr[i] = get_3x3_determinant(m3x3) *
(float)sign / det;
dstv[j].ptr[i] =
get_3x3_determinant(m3x3) * (float)sign / det;
}
}

View file

@ -55,40 +55,40 @@ static inline void matrix4_identity(struct matrix4 *dst)
EXPORT void matrix4_from_matrix3(struct matrix4 *dst, const struct matrix3 *m);
EXPORT void matrix4_from_quat(struct matrix4 *dst, const struct quat *q);
EXPORT void matrix4_from_axisang(struct matrix4 *dst,
const struct axisang *aa);
EXPORT void matrix4_from_axisang(struct matrix4 *dst, const struct axisang *aa);
EXPORT void matrix4_mul(struct matrix4 *dst, const struct matrix4 *m1,
const struct matrix4 *m2);
const struct matrix4 *m2);
EXPORT float matrix4_determinant(const struct matrix4 *m);
EXPORT void matrix4_translate3v(struct matrix4 *dst, const struct matrix4 *m,
const struct vec3 *v);
const struct vec3 *v);
EXPORT void matrix4_translate4v(struct matrix4 *dst, const struct matrix4 *m,
const struct vec4 *v);
const struct vec4 *v);
EXPORT void matrix4_rotate(struct matrix4 *dst, const struct matrix4 *m,
const struct quat *q);
const struct quat *q);
EXPORT void matrix4_rotate_aa(struct matrix4 *dst, const struct matrix4 *m,
const struct axisang *aa);
const struct axisang *aa);
EXPORT void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m,
const struct vec3 *v);
const struct vec3 *v);
EXPORT bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m);
EXPORT void matrix4_transpose(struct matrix4 *dst, const struct matrix4 *m);
EXPORT void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void matrix4_scale_i(struct matrix4 *dst, const struct vec3 *v,
const struct matrix4 *m);
const struct matrix4 *m);
static inline void matrix4_translate3f(struct matrix4 *dst,
const struct matrix4 *m, float x, float y, float z)
const struct matrix4 *m, float x,
float y, float z)
{
struct vec3 v;
vec3_set(&v, x, y, z);
@ -96,15 +96,16 @@ static inline void matrix4_translate3f(struct matrix4 *dst,
}
static inline void matrix4_rotate_aa4f(struct matrix4 *dst,
const struct matrix4 *m, float x, float y, float z, float rot)
const struct matrix4 *m, float x,
float y, float z, float rot)
{
struct axisang aa;
axisang_set(&aa, x, y, z, rot);
matrix4_rotate_aa(dst, m, &aa);
}
static inline void matrix4_scale3f(struct matrix4 *dst,
const struct matrix4 *m, float x, float y, float z)
static inline void matrix4_scale3f(struct matrix4 *dst, const struct matrix4 *m,
float x, float y, float z)
{
struct vec3 v;
vec3_set(&v, x, y, z);

View file

@ -19,10 +19,8 @@
#include "matrix3.h"
#include "plane.h"
void plane_from_tri(struct plane *dst,
const struct vec3 *v1,
const struct vec3 *v2,
const struct vec3 *v3)
void plane_from_tri(struct plane *dst, const struct vec3 *v1,
const struct vec3 *v2, const struct vec3 *v3)
{
struct vec3 temp;
@ -34,7 +32,7 @@ void plane_from_tri(struct plane *dst,
}
void plane_transform(struct plane *dst, const struct plane *p,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct vec3 temp;
@ -48,7 +46,7 @@ void plane_transform(struct plane *dst, const struct plane *p,
}
void plane_transform3x4(struct plane *dst, const struct plane *p,
const struct matrix3 *m)
const struct matrix3 *m)
{
struct vec3 temp;
@ -60,7 +58,7 @@ void plane_transform3x4(struct plane *dst, const struct plane *p,
}
bool plane_intersection_ray(const struct plane *p, const struct vec3 *orig,
const struct vec3 *dir, float *t)
const struct vec3 *dir, float *t)
{
float c = vec3_dot(&p->dir, dir);
@ -74,10 +72,10 @@ bool plane_intersection_ray(const struct plane *p, const struct vec3 *orig,
}
bool plane_intersection_line(const struct plane *p, const struct vec3 *v1,
const struct vec3 *v2, float *t)
const struct vec3 *v2, float *t)
{
float p1_dist, p2_dist, p1_abs_dist, dist2;
bool p1_over, p2_over;
bool p1_over, p2_over;
p1_dist = vec3_plane_dist(v1, p);
p2_dist = vec3_plane_dist(v2, p);
@ -108,11 +106,9 @@ bool plane_intersection_line(const struct plane *p, const struct vec3 *v1,
return true;
}
bool plane_tri_inside(const struct plane *p,
const struct vec3 *v1,
const struct vec3 *v2,
const struct vec3 *v3,
float precision)
bool plane_tri_inside(const struct plane *p, const struct vec3 *v1,
const struct vec3 *v2, const struct vec3 *v3,
float precision)
{
/* bit 1: part or all is behind the plane */
/* bit 2: part or all is in front of the plane */
@ -140,7 +136,7 @@ bool plane_tri_inside(const struct plane *p,
}
bool plane_line_inside(const struct plane *p, const struct vec3 *v1,
const struct vec3 *v2, float precision)
const struct vec3 *v2, float precision)
{
/* bit 1: part or all is behind the plane */
/* bit 2: part or all is in front of the plane */

View file

@ -29,7 +29,7 @@ struct matrix4;
struct plane {
struct vec3 dir;
float dist;
float dist;
};
static inline void plane_copy(struct plane *dst, const struct plane *p)
@ -39,52 +39,50 @@ static inline void plane_copy(struct plane *dst, const struct plane *p)
}
static inline void plane_set(struct plane *dst, const struct vec3 *dir,
float dist)
float dist)
{
vec3_copy(&dst->dir, dir);
dst->dist = dist;
}
static inline void plane_setf(struct plane *dst, float a, float b, float c,
float d)
float d)
{
vec3_set(&dst->dir, a, b, c);
dst->dist = d;
}
EXPORT void plane_from_tri(struct plane *dst,
const struct vec3 *v1,
const struct vec3 *v2,
const struct vec3 *v3);
EXPORT void plane_from_tri(struct plane *dst, const struct vec3 *v1,
const struct vec3 *v2, const struct vec3 *v3);
EXPORT void plane_transform(struct plane *dst, const struct plane *p,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void plane_transform3x4(struct plane *dst, const struct plane *p,
const struct matrix3 *m);
const struct matrix3 *m);
EXPORT bool plane_intersection_ray(const struct plane *p,
const struct vec3 *orig, const struct vec3 *dir, float *t);
const struct vec3 *orig,
const struct vec3 *dir, float *t);
EXPORT bool plane_intersection_line(const struct plane *p,
const struct vec3 *v1, const struct vec3 *v2, float *t);
const struct vec3 *v1,
const struct vec3 *v2, float *t);
EXPORT bool plane_tri_inside(const struct plane *p,
const struct vec3 *v1,
const struct vec3 *v2,
const struct vec3 *v3,
float precision);
EXPORT bool plane_tri_inside(const struct plane *p, const struct vec3 *v1,
const struct vec3 *v2, const struct vec3 *v3,
float precision);
EXPORT bool plane_line_inside(const struct plane *p, const struct vec3 *v1,
const struct vec3 *v2, float precision);
const struct vec3 *v2, float precision);
static inline bool plane_close(const struct plane *p1, const struct plane *p2,
float precision)
float precision)
{
return vec3_close(&p1->dir, &p2->dir, precision) &&
close_float(p1->dist, p2->dist, precision);
}
static inline bool plane_coplanar(const struct plane *p1,
const struct plane *p2, float precision)
const struct plane *p2, float precision)
{
float cos_angle = vec3_dot(&p1->dir, &p2->dir);

View file

@ -47,12 +47,12 @@ void quat_mul(struct quat *dst, const struct quat *q1, const struct quat *q2)
void quat_from_axisang(struct quat *dst, const struct axisang *aa)
{
float halfa = aa->w * 0.5f;
float sine = sinf(halfa);
float sine = sinf(halfa);
dst->x = aa->x * sine;
dst->y = aa->y * sine;
dst->z = aa->z * sine;
dst->w = cosf(halfa);
dst->w = cosf(halfa);
}
struct f4x4 {
@ -61,7 +61,7 @@ struct f4x4 {
void quat_from_matrix3(struct quat *dst, const struct matrix3 *m)
{
quat_from_matrix4(dst, (const struct matrix4*)m);
quat_from_matrix4(dst, (const struct matrix4 *)m);
}
void quat_from_matrix4(struct quat *dst, const struct matrix4 *m)
@ -69,7 +69,7 @@ void quat_from_matrix4(struct quat *dst, const struct matrix4 *m)
float tr = (m->x.x + m->y.y + m->z.z);
float inv_half;
float four_d;
int i,j,k;
int i, j, k;
if (tr > 0.0f) {
four_d = sqrtf(tr + 1.0f);
@ -80,27 +80,28 @@ void quat_from_matrix4(struct quat *dst, const struct matrix4 *m)
dst->y = (m->z.x - m->x.z) * inv_half;
dst->z = (m->x.y - m->y.x) * inv_half;
} else {
struct f4x4 *val = (struct f4x4*)m;
struct f4x4 *val = (struct f4x4 *)m;
i = (m->x.x > m->y.y) ? 0 : 1;
if (m->z.z > val->ptr[i][i])
i = 2;
j = (i+1) % 3;
k = (i+2) % 3;
j = (i + 1) % 3;
k = (i + 2) % 3;
/* ---------------------------------- */
four_d = sqrtf((val->ptr[i][i] - val->ptr[j][j] -
val->ptr[k][k]) + 1.0f);
four_d = sqrtf(
(val->ptr[i][i] - val->ptr[j][j] - val->ptr[k][k]) +
1.0f);
dst->ptr[i] = four_d * 0.5f;
inv_half = 0.5f / four_d;
dst->ptr[j] = (val->ptr[i][j] + val->ptr[j][i]) * inv_half;
dst->ptr[k] = (val->ptr[i][k] + val->ptr[k][i]) * inv_half;
dst->w = (val->ptr[j][k] - val->ptr[k][j]) * inv_half;
dst->ptr[j] = (val->ptr[i][j] + val->ptr[j][i]) * inv_half;
dst->ptr[k] = (val->ptr[i][k] + val->ptr[k][i]) * inv_half;
dst->w = (val->ptr[j][k] - val->ptr[k][j]) * inv_half;
}
}
@ -115,8 +116,8 @@ void quat_set_look_dir(struct quat *dst, const struct vec3 *dir)
{
struct vec3 new_dir;
struct quat xz_rot, yz_rot;
bool xz_valid;
bool yz_valid;
bool xz_valid;
bool yz_valid;
struct axisang aa;
vec3_norm(&new_dir, dir);
@ -126,12 +127,12 @@ void quat_set_look_dir(struct quat *dst, const struct vec3 *dir)
quat_identity(&yz_rot);
xz_valid = close_float(new_dir.x, 0.0f, EPSILON) ||
close_float(new_dir.z, 0.0f, EPSILON);
close_float(new_dir.z, 0.0f, EPSILON);
yz_valid = close_float(new_dir.y, 0.0f, EPSILON);
if (xz_valid) {
axisang_set(&aa, 0.0f, 1.0f, 0.0f,
atan2f(new_dir.x, new_dir.z));
atan2f(new_dir.x, new_dir.z));
quat_from_axisang(&xz_rot, &aa);
}
@ -151,31 +152,31 @@ void quat_set_look_dir(struct quat *dst, const struct vec3 *dir)
void quat_log(struct quat *dst, const struct quat *q)
{
float angle = acosf(q->w);
float sine = sinf(angle);
float w = q->w;
float sine = sinf(angle);
float w = q->w;
quat_copy(dst, q);
dst->w = 0.0f;
if ((fabsf(w) < 1.0f) && (fabsf(sine) >= EPSILON)) {
sine = angle/sine;
sine = angle / sine;
quat_mulf(dst, dst, sine);
}
}
void quat_exp(struct quat *dst, const struct quat *q)
{
float length = sqrtf(q->x*q->x + q->y*q->y + q->z*q->z);
float sine = sinf(length);
float length = sqrtf(q->x * q->x + q->y * q->y + q->z * q->z);
float sine = sinf(length);
quat_copy(dst, q);
sine = (length > EPSILON) ? (sine/length) : 1.0f;
sine = (length > EPSILON) ? (sine / length) : 1.0f;
quat_mulf(dst, dst, sine);
dst->w = cosf(length);
}
void quat_interpolate(struct quat *dst, const struct quat *q1,
const struct quat *q2, float t)
const struct quat *q2, float t)
{
float dot = quat_dot(q1, q2);
float anglef = acosf(dot);
@ -183,10 +184,10 @@ void quat_interpolate(struct quat *dst, const struct quat *q1,
struct quat temp;
if (anglef >= EPSILON) {
sine = sinf(anglef);
sinei = 1/sine;
sinet = sinf(anglef*t)*sinei;
sineti = sinf(anglef*(1.0f-t))*sinei;
sine = sinf(anglef);
sinei = 1 / sine;
sinet = sinf(anglef * t) * sinei;
sineti = sinf(anglef * (1.0f - t)) * sinei;
quat_mulf(&temp, q1, sineti);
quat_mulf(dst, q2, sinet);
@ -199,7 +200,7 @@ void quat_interpolate(struct quat *dst, const struct quat *q1,
}
void quat_get_tangent(struct quat *dst, const struct quat *prev,
const struct quat *q, const struct quat *next)
const struct quat *q, const struct quat *next)
{
struct quat temp;
@ -209,14 +210,13 @@ void quat_get_tangent(struct quat *dst, const struct quat *prev,
quat_mulf(dst, &temp, 0.5f);
}
void quat_interpolate_cubic(struct quat *dst,
const struct quat *q1, const struct quat *q2,
const struct quat *m1, const struct quat *m2,
float t)
void quat_interpolate_cubic(struct quat *dst, const struct quat *q1,
const struct quat *q2, const struct quat *m1,
const struct quat *m2, float t)
{
struct quat temp1, temp2;
quat_interpolate(&temp1, q1, q2, t);
quat_interpolate(&temp2, m1, m2, t);
quat_interpolate(dst, &temp1, &temp2, 2.0f*(1.0f-t)*t);
quat_interpolate(dst, &temp1, &temp2, 2.0f * (1.0f - t) * t);
}

View file

@ -40,7 +40,9 @@ struct axisang;
struct quat {
union {
struct {float x, y, z, w;};
struct {
float x, y, z, w;
};
float ptr[4];
__m128 m;
};
@ -53,7 +55,7 @@ static inline void quat_identity(struct quat *q)
}
static inline void quat_set(struct quat *dst, float x, float y, float z,
float w)
float w)
{
dst->m = _mm_set_ps(x, y, z, w);
}
@ -64,40 +66,36 @@ static inline void quat_copy(struct quat *dst, const struct quat *q)
}
static inline void quat_add(struct quat *dst, const struct quat *q1,
const struct quat *q2)
const struct quat *q2)
{
dst->m = _mm_add_ps(q1->m, q2->m);
}
static inline void quat_sub(struct quat *dst, const struct quat *q1,
const struct quat *q2)
const struct quat *q2)
{
dst->m = _mm_sub_ps(q1->m, q2->m);
}
EXPORT void quat_mul(struct quat *dst, const struct quat *q1,
const struct quat *q2);
const struct quat *q2);
static inline void quat_addf(struct quat *dst, const struct quat *q,
float f)
static inline void quat_addf(struct quat *dst, const struct quat *q, float f)
{
dst->m = _mm_add_ps(q->m, _mm_set1_ps(f));
}
static inline void quat_subf(struct quat *dst, const struct quat *q,
float f)
static inline void quat_subf(struct quat *dst, const struct quat *q, float f)
{
dst->m = _mm_sub_ps(q->m, _mm_set1_ps(f));
}
static inline void quat_mulf(struct quat *dst, const struct quat *q,
float f)
static inline void quat_mulf(struct quat *dst, const struct quat *q, float f)
{
dst->m = _mm_mul_ps(q->m, _mm_set1_ps(f));
}
static inline void quat_divf(struct quat *dst, const struct quat *q,
float f)
static inline void quat_divf(struct quat *dst, const struct quat *q, float f)
{
dst->m = _mm_div_ps(q->m, _mm_set1_ps(f));
}
@ -145,19 +143,17 @@ static inline float quat_dist(const struct quat *q1, const struct quat *q2)
static inline void quat_norm(struct quat *dst, const struct quat *q)
{
float dot_val = quat_dot(q, q);
dst->m = (dot_val > 0.0f) ?
_mm_mul_ps(q->m, _mm_set1_ps(1.0f/sqrtf(dot_val))) :
_mm_setzero_ps();
dst->m = (dot_val > 0.0f)
? _mm_mul_ps(q->m, _mm_set1_ps(1.0f / sqrtf(dot_val)))
: _mm_setzero_ps();
}
static inline bool quat_close(const struct quat *q1, const struct quat *q2,
float epsilon)
float epsilon)
{
struct quat test;
quat_sub(&test, q1, q2);
return test.x < epsilon &&
test.y < epsilon &&
test.z < epsilon &&
return test.x < epsilon && test.y < epsilon && test.z < epsilon &&
test.w < epsilon;
}
@ -172,12 +168,12 @@ EXPORT void quat_log(struct quat *dst, const struct quat *q);
EXPORT void quat_exp(struct quat *dst, const struct quat *q);
EXPORT void quat_interpolate(struct quat *dst, const struct quat *q1,
const struct quat *q2, float t);
const struct quat *q2, float t);
EXPORT void quat_get_tangent(struct quat *dst, const struct quat *prev,
const struct quat *q, const struct quat *next);
const struct quat *q, const struct quat *next);
EXPORT void quat_interpolate_cubic(struct quat *dst, const struct quat *q1,
const struct quat *q2, const struct quat *m1,
const struct quat *m2, float t);
const struct quat *q2, const struct quat *m1,
const struct quat *m2, float t);
#ifdef __cplusplus
}

View file

@ -53,12 +53,12 @@ enum gs_sample_filter get_sample_filter(const char *filter)
if (astrcmpi(filter, "Anisotropy") == 0)
return GS_FILTER_ANISOTROPIC;
else if (astrcmpi(filter, "Point") == 0 ||
strcmp(filter, "MIN_MAG_MIP_POINT") == 0)
else if (astrcmpi(filter, "Point") == 0 ||
strcmp(filter, "MIN_MAG_MIP_POINT") == 0)
return GS_FILTER_POINT;
else if (astrcmpi(filter, "Linear") == 0 ||
strcmp(filter, "MIN_MAG_MIP_LINEAR") == 0)
else if (astrcmpi(filter, "Linear") == 0 ||
strcmp(filter, "MIN_MAG_MIP_LINEAR") == 0)
return GS_FILTER_LINEAR;
else if (strcmp(filter, "MIN_MAG_POINT_MIP_LINEAR") == 0)
@ -99,7 +99,7 @@ extern enum gs_address_mode get_address_mode(const char *mode)
}
void shader_sampler_convert(struct shader_sampler *ss,
struct gs_sampler_info *info)
struct gs_sampler_info *info)
{
size_t i;
memset(info, 0, sizeof(struct gs_sampler_info));
@ -128,22 +128,26 @@ void shader_sampler_convert(struct shader_sampler *ss,
/* ------------------------------------------------------------------------- */
static int sp_parse_sampler_state_item(struct shader_parser *sp,
struct shader_sampler *ss)
struct shader_sampler *ss)
{
int ret;
char *state = NULL, *value = NULL;
ret = cf_next_name(&sp->cfp, &state, "state name", ";");
if (ret != PARSE_SUCCESS) goto fail;
if (ret != PARSE_SUCCESS)
goto fail;
ret = cf_next_token_should_be(&sp->cfp, "=", ";", NULL);
if (ret != PARSE_SUCCESS) goto fail;
if (ret != PARSE_SUCCESS)
goto fail;
ret = cf_next_token_copy(&sp->cfp, &value);
if (ret != PARSE_SUCCESS) goto fail;
if (ret != PARSE_SUCCESS)
goto fail;
ret = cf_next_token_should_be(&sp->cfp, ";", ";", NULL);
if (ret != PARSE_SUCCESS) goto fail;
if (ret != PARSE_SUCCESS)
goto fail;
da_push_back(ss->states, &state);
da_push_back(ss->values, &value);
@ -191,17 +195,20 @@ error:
}
static inline int sp_parse_struct_var(struct shader_parser *sp,
struct shader_var *var)
struct shader_var *var)
{
int code;
/* -------------------------------------- */
/* variable type */
if (!cf_next_valid_token(&sp->cfp)) return PARSE_EOF;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ";")) return PARSE_CONTINUE;
if (cf_token_is(&sp->cfp, "}")) return PARSE_BREAK;
if (cf_token_is(&sp->cfp, ";"))
return PARSE_CONTINUE;
if (cf_token_is(&sp->cfp, "}"))
return PARSE_BREAK;
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "type name", ";");
if (code != PARSE_SUCCESS)
@ -212,13 +219,15 @@ static inline int sp_parse_struct_var(struct shader_parser *sp,
/* -------------------------------------- */
/* variable name */
if (!cf_next_valid_token(&sp->cfp)) return PARSE_EOF;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ";")) return PARSE_UNEXPECTED_CONTINUE;
if (cf_token_is(&sp->cfp, "}")) return PARSE_UNEXPECTED_BREAK;
if (cf_token_is(&sp->cfp, ";"))
return PARSE_UNEXPECTED_CONTINUE;
if (cf_token_is(&sp->cfp, "}"))
return PARSE_UNEXPECTED_BREAK;
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "variable name",
";");
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "variable name", ";");
if (code != PARSE_SUCCESS)
return code;
@ -227,24 +236,27 @@ static inline int sp_parse_struct_var(struct shader_parser *sp,
/* -------------------------------------- */
/* variable mapping if any (POSITION, TEXCOORD, etc) */
if (!cf_next_valid_token(&sp->cfp)) return PARSE_EOF;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ":")) {
if (!cf_next_valid_token(&sp->cfp)) return PARSE_EOF;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
if (cf_token_is(&sp->cfp, ";"))
return PARSE_UNEXPECTED_CONTINUE;
if (cf_token_is(&sp->cfp, "}"))
return PARSE_UNEXPECTED_BREAK;
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME,
"mapping name", ";");
code = cf_token_is_type(&sp->cfp, CFTOKEN_NAME, "mapping name",
";");
if (code != PARSE_SUCCESS)
return code;
cf_copy_token(&sp->cfp, &var->mapping);
if (!cf_next_valid_token(&sp->cfp)) return PARSE_EOF;
if (!cf_next_valid_token(&sp->cfp))
return PARSE_EOF;
}
/* -------------------------------------- */
@ -314,7 +326,7 @@ error:
}
static inline int sp_check_for_keyword(struct shader_parser *sp,
const char *keyword, bool *val)
const char *keyword, bool *val)
{
bool new_val = cf_token_is(&sp->cfp, keyword);
if (new_val) {
@ -323,7 +335,7 @@ static inline int sp_check_for_keyword(struct shader_parser *sp,
if (new_val && *val)
cf_adderror(&sp->cfp, "'$1' keyword already specified",
LEX_WARNING, keyword, NULL, NULL);
LEX_WARNING, keyword, NULL, NULL);
*val = new_val;
return PARSE_CONTINUE;
@ -333,7 +345,7 @@ static inline int sp_check_for_keyword(struct shader_parser *sp,
}
static inline int sp_parse_func_param(struct shader_parser *sp,
struct shader_var *var)
struct shader_var *var)
{
int code;
bool var_type_keyword = false;
@ -384,7 +396,7 @@ static inline int sp_parse_func_param(struct shader_parser *sp,
if (cf_token_is(&sp->cfp, ":")) {
code = cf_next_name(&sp->cfp, &var->mapping,
"mapping specifier", ")");
"mapping specifier", ")");
if (code != PARSE_SUCCESS)
return code;
@ -396,7 +408,7 @@ static inline int sp_parse_func_param(struct shader_parser *sp,
}
static bool sp_parse_func_params(struct shader_parser *sp,
struct shader_func *func)
struct shader_func *func)
{
struct cf_token peek;
int code;
@ -449,8 +461,8 @@ static void sp_parse_function(struct shader_parser *sp, char *type, char *name)
/* if function is mapped to something, for example COLOR */
if (cf_token_is(&sp->cfp, ":")) {
char *mapping = NULL;
int errorcode = cf_next_name(&sp->cfp, &mapping, "mapping",
"{");
int errorcode =
cf_next_name(&sp->cfp, &mapping, "mapping", "{");
if (errorcode != PARSE_SUCCESS)
goto error;
@ -482,17 +494,18 @@ error:
/* parses "array[count]" */
static bool sp_parse_param_array(struct shader_parser *sp,
struct shader_var *param)
struct shader_var *param)
{
if (!cf_next_valid_token(&sp->cfp))
return false;
if (sp->cfp.cur_token->type != CFTOKEN_NUM ||
!valid_int_str(sp->cfp.cur_token->str.array,
sp->cfp.cur_token->str.len))
sp->cfp.cur_token->str.len))
return false;
param->array_count =(int)strtol(sp->cfp.cur_token->str.array, NULL, 10);
param->array_count =
(int)strtol(sp->cfp.cur_token->str.array, NULL, 10);
if (cf_next_token_should_be(&sp->cfp, "]", ";", NULL) == PARSE_EOF)
return false;
@ -504,7 +517,8 @@ static bool sp_parse_param_array(struct shader_parser *sp,
}
static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
struct shader_var *param, bool is_float)
struct shader_var *param,
bool is_float)
{
int code;
bool is_negative = false;
@ -525,11 +539,13 @@ static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
if (is_float) {
float f = (float)os_strtod(sp->cfp.cur_token->str.array);
if (is_negative) f = -f;
if (is_negative)
f = -f;
da_push_back_array(param->default_val, &f, sizeof(float));
} else {
long l = strtol(sp->cfp.cur_token->str.array, NULL, 10);
if (is_negative) l = -l;
if (is_negative)
l = -l;
da_push_back_array(param->default_val, &l, sizeof(long));
}
@ -541,47 +557,50 @@ static inline int sp_parse_param_assign_intfloat(struct shader_parser *sp,
* for float3x3, float4x4, etc
*/
static inline int sp_parse_param_assign_float_array(struct shader_parser *sp,
struct shader_var *param)
struct shader_var *param)
{
const char *float_type = param->type+5;
const char *float_type = param->type + 5;
int float_count = 0, code, i;
/* -------------------------------------------- */
if (float_type[0] < '1' || float_type[0] > '4')
cf_adderror(&sp->cfp, "Invalid row count", LEX_ERROR,
NULL, NULL, NULL);
cf_adderror(&sp->cfp, "Invalid row count", LEX_ERROR, NULL,
NULL, NULL);
float_count = float_type[0]-'0';
float_count = float_type[0] - '0';
if (float_type[1] == 'x') {
if (float_type[2] < '1' || float_type[2] > '4')
cf_adderror(&sp->cfp, "Invalid column count",
LEX_ERROR, NULL, NULL, NULL);
cf_adderror(&sp->cfp, "Invalid column count", LEX_ERROR,
NULL, NULL, NULL);
float_count *= float_type[2]-'0';
float_count *= float_type[2] - '0';
}
/* -------------------------------------------- */
code = cf_next_token_should_be(&sp->cfp, "{", ";", NULL);
if (code != PARSE_SUCCESS) return code;
if (code != PARSE_SUCCESS)
return code;
for (i = 0; i < float_count; i++) {
char *next = ((i+1) < float_count) ? "," : "}";
char *next = ((i + 1) < float_count) ? "," : "}";
code = sp_parse_param_assign_intfloat(sp, param, true);
if (code != PARSE_SUCCESS) return code;
if (code != PARSE_SUCCESS)
return code;
code = cf_next_token_should_be(&sp->cfp, next, ";", NULL);
if (code != PARSE_SUCCESS) return code;
if (code != PARSE_SUCCESS)
return code;
}
return PARSE_SUCCESS;
}
static int sp_parse_param_assignment_val(struct shader_parser *sp,
struct shader_var *param)
struct shader_var *param)
{
if (strcmp(param->type, "int") == 0)
return sp_parse_param_assign_intfloat(sp, param, false);
@ -591,13 +610,13 @@ static int sp_parse_param_assignment_val(struct shader_parser *sp,
return sp_parse_param_assign_float_array(sp, param);
cf_adderror(&sp->cfp, "Invalid type '$1' used for assignment",
LEX_ERROR, param->type, NULL, NULL);
LEX_ERROR, param->type, NULL, NULL);
return PARSE_CONTINUE;
}
static inline bool sp_parse_param_assign(struct shader_parser *sp,
struct shader_var *param)
struct shader_var *param)
{
if (sp_parse_param_assignment_val(sp, param) != PARSE_SUCCESS)
return false;
@ -608,8 +627,8 @@ static inline bool sp_parse_param_assign(struct shader_parser *sp,
return true;
}
static void sp_parse_param(struct shader_parser *sp,
char *type, char *name, bool is_const, bool is_uniform)
static void sp_parse_param(struct shader_parser *sp, char *type, char *name,
bool is_const, bool is_uniform)
{
struct shader_var param;
shader_var_init_param(&param, type, name, is_uniform, is_const);
@ -631,10 +650,10 @@ error:
shader_var_free(&param);
}
static bool sp_get_var_specifiers(struct shader_parser *sp,
bool *is_const, bool *is_uniform)
static bool sp_get_var_specifiers(struct shader_parser *sp, bool *is_const,
bool *is_uniform)
{
while(true) {
while (true) {
int code = sp_check_for_keyword(sp, "const", is_const);
if (code == PARSE_EOF)
return false;
@ -654,12 +673,13 @@ static bool sp_get_var_specifiers(struct shader_parser *sp,
}
static inline void report_invalid_func_keyword(struct shader_parser *sp,
const char *name, bool val)
const char *name, bool val)
{
if (val)
cf_adderror(&sp->cfp, "'$1' keyword cannot be used with a "
"function", LEX_ERROR,
name, NULL, NULL);
cf_adderror(&sp->cfp,
"'$1' keyword cannot be used with a "
"function",
LEX_ERROR, name, NULL, NULL);
}
static void sp_parse_other(struct shader_parser *sp)
@ -679,8 +699,8 @@ static void sp_parse_other(struct shader_parser *sp)
goto error;
if (cf_token_is(&sp->cfp, "(")) {
report_invalid_func_keyword(sp, "const", is_const);
report_invalid_func_keyword(sp, "uniform", is_uniform);
report_invalid_func_keyword(sp, "const", is_const);
report_invalid_func_keyword(sp, "uniform", is_uniform);
sp_parse_function(sp, type, name);
return;
@ -695,7 +715,7 @@ error:
}
bool shader_parse(struct shader_parser *sp, const char *shader,
const char *file)
const char *file)
{
if (!cf_parser_parse(&sp->cfp, shader, file))
return false;
@ -713,7 +733,7 @@ bool shader_parse(struct shader_parser *sp, const char *shader,
} else if (cf_token_is(&sp->cfp, "{")) {
cf_adderror(&sp->cfp, "Unexpected code segment",
LEX_ERROR, NULL, NULL, NULL);
LEX_ERROR, NULL, NULL, NULL);
cf_pass_pair(&sp->cfp, '{', '}');
} else {

View file

@ -61,9 +61,9 @@ static inline void shader_var_init(struct shader_var *sv)
memset(sv, 0, sizeof(struct shader_var));
}
static inline void shader_var_init_param(struct shader_var *sv,
char *type, char *name, bool is_uniform,
bool is_const)
static inline void shader_var_init_param(struct shader_var *sv, char *type,
char *name, bool is_uniform,
bool is_const)
{
if (is_uniform)
sv->var_type = SHADER_VAR_UNIFORM;
@ -72,10 +72,11 @@ static inline void shader_var_init_param(struct shader_var *sv,
else
sv->var_type = SHADER_VAR_NONE;
sv->type = type;
sv->name = name;
sv->mapping = NULL;
sv->type = type;
sv->name = name;
sv->mapping = NULL;
sv->array_count = 0;
sv->gl_sampler_id = (size_t)-1;
da_init(sv->default_val);
}
@ -91,8 +92,8 @@ static inline void shader_var_free(struct shader_var *sv)
struct shader_sampler {
char *name;
DARRAY(char*) states;
DARRAY(char*) values;
DARRAY(char *) states;
DARRAY(char *) values;
};
static inline void shader_sampler_init(struct shader_sampler *ss)
@ -114,7 +115,7 @@ static inline void shader_sampler_free(struct shader_sampler *ss)
}
EXPORT void shader_sampler_convert(struct shader_sampler *ss,
struct gs_sampler_info *info);
struct gs_sampler_info *info);
/* ------------------------------------------------------------------------- */
@ -133,7 +134,7 @@ static inline void shader_struct_free(struct shader_struct *ss)
size_t i;
for (i = 0; i < ss->vars.num; i++)
shader_var_free(ss->vars.array+i);
shader_var_free(ss->vars.array + i);
bfree(ss->name);
da_free(ss->vars);
@ -150,16 +151,16 @@ struct shader_func {
struct cf_token *start, *end;
};
static inline void shader_func_init(struct shader_func *sf,
char *return_type, char *name)
static inline void shader_func_init(struct shader_func *sf, char *return_type,
char *name)
{
da_init(sf->params);
sf->return_type = return_type;
sf->return_type = return_type;
sf->mapping = NULL;
sf->name = name;
sf->start = NULL;
sf->end = NULL;
sf->name = name;
sf->start = NULL;
sf->end = NULL;
}
static inline void shader_func_free(struct shader_func *sf)
@ -167,7 +168,7 @@ static inline void shader_func_free(struct shader_func *sf)
size_t i;
for (i = 0; i < sf->params.num; i++)
shader_var_free(sf->params.array+i);
shader_var_free(sf->params.array + i);
bfree(sf->name);
bfree(sf->return_type);
@ -180,10 +181,10 @@ static inline void shader_func_free(struct shader_func *sf)
struct shader_parser {
struct cf_parser cfp;
DARRAY(struct shader_var) params;
DARRAY(struct shader_struct) structs;
DARRAY(struct shader_var) params;
DARRAY(struct shader_struct) structs;
DARRAY(struct shader_sampler) samplers;
DARRAY(struct shader_func) funcs;
DARRAY(struct shader_func) funcs;
};
static inline void shader_parser_init(struct shader_parser *sp)
@ -201,13 +202,13 @@ static inline void shader_parser_free(struct shader_parser *sp)
size_t i;
for (i = 0; i < sp->params.num; i++)
shader_var_free(sp->params.array+i);
shader_var_free(sp->params.array + i);
for (i = 0; i < sp->structs.num; i++)
shader_struct_free(sp->structs.array+i);
shader_struct_free(sp->structs.array + i);
for (i = 0; i < sp->samplers.num; i++)
shader_sampler_free(sp->samplers.array+i);
shader_sampler_free(sp->samplers.array + i);
for (i = 0; i < sp->funcs.num; i++)
shader_func_free(sp->funcs.array+i);
shader_func_free(sp->funcs.array + i);
cf_parser_free(&sp->cfp);
da_free(sp->params);
@ -217,19 +218,19 @@ static inline void shader_parser_free(struct shader_parser *sp)
}
EXPORT bool shader_parse(struct shader_parser *sp, const char *shader,
const char *file);
const char *file);
static inline char *shader_parser_geterrors(struct shader_parser *sp)
{
return error_data_buildstring(&sp->cfp.error_list);
}
static inline struct shader_var *shader_parser_getparam(
struct shader_parser *sp, const char *param_name)
static inline struct shader_var *
shader_parser_getparam(struct shader_parser *sp, const char *param_name)
{
size_t i;
for (i = 0; i < sp->params.num; i++) {
struct shader_var *param = sp->params.array+i;
struct shader_var *param = sp->params.array + i;
if (strcmp(param->name, param_name) == 0)
return param;
}
@ -237,12 +238,12 @@ static inline struct shader_var *shader_parser_getparam(
return NULL;
}
static inline struct shader_struct *shader_parser_getstruct(
struct shader_parser *sp, const char *struct_name)
static inline struct shader_struct *
shader_parser_getstruct(struct shader_parser *sp, const char *struct_name)
{
size_t i;
for (i = 0; i < sp->structs.num; i++) {
struct shader_struct *st = sp->structs.array+i;
struct shader_struct *st = sp->structs.array + i;
if (strcmp(st->name, struct_name) == 0)
return st;
}
@ -250,12 +251,12 @@ static inline struct shader_struct *shader_parser_getstruct(
return NULL;
}
static inline struct shader_sampler *shader_parser_getsampler(
struct shader_parser *sp, const char *sampler_name)
static inline struct shader_sampler *
shader_parser_getsampler(struct shader_parser *sp, const char *sampler_name)
{
size_t i;
for (i = 0; i < sp->samplers.num; i++) {
struct shader_sampler *sampler = sp->samplers.array+i;
struct shader_sampler *sampler = sp->samplers.array + i;
if (strcmp(sampler->name, sampler_name) == 0)
return sampler;
}
@ -263,12 +264,12 @@ static inline struct shader_sampler *shader_parser_getsampler(
return NULL;
}
static inline struct shader_func *shader_parser_getfunc(
struct shader_parser *sp, const char *func_name)
static inline struct shader_func *
shader_parser_getfunc(struct shader_parser *sp, const char *func_name)
{
size_t i;
for (i = 0; i < sp->funcs.num; i++) {
struct shader_func *func = sp->funcs.array+i;
struct shader_func *func = sp->funcs.array + i;
if (strcmp(func->name, func_name) == 0)
return func;
}

View file

@ -24,23 +24,23 @@
#include "graphics.h"
struct gs_texture_render {
gs_texture_t *target, *prev_target;
gs_texture_t *target, *prev_target;
gs_zstencil_t *zs, *prev_zs;
uint32_t cx, cy;
enum gs_color_format format;
enum gs_color_format format;
enum gs_zstencil_format zsformat;
bool rendered;
};
gs_texrender_t *gs_texrender_create(enum gs_color_format format,
enum gs_zstencil_format zsformat)
enum gs_zstencil_format zsformat)
{
struct gs_texture_render *texrender;
texrender = bzalloc(sizeof(struct gs_texture_render));
texrender->format = format;
texrender->format = format;
texrender->zsformat = zsformat;
return texrender;
@ -56,7 +56,7 @@ void gs_texrender_destroy(gs_texrender_t *texrender)
}
static bool texrender_resetbuffer(gs_texrender_t *texrender, uint32_t cx,
uint32_t cy)
uint32_t cy)
{
if (!texrender)
return false;
@ -65,12 +65,12 @@ static bool texrender_resetbuffer(gs_texrender_t *texrender, uint32_t cx,
gs_zstencil_destroy(texrender->zs);
texrender->target = NULL;
texrender->zs = NULL;
texrender->cx = cx;
texrender->cy = cy;
texrender->zs = NULL;
texrender->cx = cx;
texrender->cy = cy;
texrender->target = gs_texture_create(cx, cy, texrender->format,
1, NULL, GS_RENDER_TARGET);
texrender->target = gs_texture_create(cx, cy, texrender->format, 1,
NULL, GS_RENDER_TARGET);
if (!texrender->target)
return false;
@ -108,7 +108,7 @@ bool gs_texrender_begin(gs_texrender_t *texrender, uint32_t cx, uint32_t cy)
gs_matrix_identity();
texrender->prev_target = gs_get_render_target();
texrender->prev_zs = gs_get_zstencil_target();
texrender->prev_zs = gs_get_zstencil_target();
gs_set_render_target(texrender->target, texrender->zs);
gs_set_viewport(0, 0, texrender->cx, texrender->cy);

View file

@ -52,51 +52,47 @@ static inline void vec2_copy(struct vec2 *dst, const struct vec2 *v)
}
static inline void vec2_add(struct vec2 *dst, const struct vec2 *v1,
const struct vec2 *v2)
const struct vec2 *v2)
{
vec2_set(dst, v1->x+v2->x, v1->y+v2->y);
vec2_set(dst, v1->x + v2->x, v1->y + v2->y);
}
static inline void vec2_sub(struct vec2 *dst, const struct vec2 *v1,
const struct vec2 *v2)
const struct vec2 *v2)
{
vec2_set(dst, v1->x-v2->x, v1->y-v2->y);
vec2_set(dst, v1->x - v2->x, v1->y - v2->y);
}
static inline void vec2_mul(struct vec2 *dst, const struct vec2 *v1,
const struct vec2 *v2)
const struct vec2 *v2)
{
vec2_set(dst, v1->x*v2->x, v1->y*v2->y);
vec2_set(dst, v1->x * v2->x, v1->y * v2->y);
}
static inline void vec2_div(struct vec2 *dst, const struct vec2 *v1,
const struct vec2 *v2)
const struct vec2 *v2)
{
vec2_set(dst, v1->x/v2->x, v1->y/v2->y);
vec2_set(dst, v1->x / v2->x, v1->y / v2->y);
}
static inline void vec2_addf(struct vec2 *dst, const struct vec2 *v,
float f)
static inline void vec2_addf(struct vec2 *dst, const struct vec2 *v, float f)
{
vec2_set(dst, v->x+f, v->y+f);
vec2_set(dst, v->x + f, v->y + f);
}
static inline void vec2_subf(struct vec2 *dst, const struct vec2 *v,
float f)
static inline void vec2_subf(struct vec2 *dst, const struct vec2 *v, float f)
{
vec2_set(dst, v->x-f, v->y-f);
vec2_set(dst, v->x - f, v->y - f);
}
static inline void vec2_mulf(struct vec2 *dst, const struct vec2 *v,
float f)
static inline void vec2_mulf(struct vec2 *dst, const struct vec2 *v, float f)
{
vec2_set(dst, v->x*f, v->y*f);
vec2_set(dst, v->x * f, v->y * f);
}
static inline void vec2_divf(struct vec2 *dst, const struct vec2 *v,
float f)
static inline void vec2_divf(struct vec2 *dst, const struct vec2 *v, float f)
{
vec2_set(dst, v->x/f, v->y/f);
vec2_set(dst, v->x / f, v->y / f);
}
static inline void vec2_neg(struct vec2 *dst, const struct vec2 *v)
@ -106,12 +102,12 @@ static inline void vec2_neg(struct vec2 *dst, const struct vec2 *v)
static inline float vec2_dot(const struct vec2 *v1, const struct vec2 *v2)
{
return v1->x*v2->x + v1->y*v2->y;
return v1->x * v2->x + v1->y * v2->y;
}
static inline float vec2_len(const struct vec2 *v)
{
return sqrtf(v->x*v->x + v->y*v->y);
return sqrtf(v->x * v->x + v->y * v->y);
}
static inline float vec2_dist(const struct vec2 *v1, const struct vec2 *v2)
@ -121,8 +117,7 @@ static inline float vec2_dist(const struct vec2 *v1, const struct vec2 *v2)
return vec2_len(&temp);
}
static inline void vec2_minf(struct vec2 *dst, const struct vec2 *v,
float val)
static inline void vec2_minf(struct vec2 *dst, const struct vec2 *v, float val)
{
if (v->x < val)
dst->x = val;
@ -131,7 +126,7 @@ static inline void vec2_minf(struct vec2 *dst, const struct vec2 *v,
}
static inline void vec2_min(struct vec2 *dst, const struct vec2 *v,
const struct vec2 *min_v)
const struct vec2 *min_v)
{
if (v->x < min_v->x)
dst->x = min_v->x;
@ -139,8 +134,7 @@ static inline void vec2_min(struct vec2 *dst, const struct vec2 *v,
dst->y = min_v->y;
}
static inline void vec2_maxf(struct vec2 *dst, const struct vec2 *v,
float val)
static inline void vec2_maxf(struct vec2 *dst, const struct vec2 *v, float val)
{
if (v->x > val)
dst->x = val;
@ -149,7 +143,7 @@ static inline void vec2_maxf(struct vec2 *dst, const struct vec2 *v,
}
static inline void vec2_max(struct vec2 *dst, const struct vec2 *v,
const struct vec2 *max_v)
const struct vec2 *max_v)
{
if (v->x > max_v->x)
dst->x = max_v->x;
@ -161,7 +155,7 @@ EXPORT void vec2_abs(struct vec2 *dst, const struct vec2 *v);
EXPORT void vec2_floor(struct vec2 *dst, const struct vec2 *v);
EXPORT void vec2_ceil(struct vec2 *dst, const struct vec2 *v);
EXPORT int vec2_close(const struct vec2 *v1, const struct vec2 *v2,
float epsilon);
float epsilon);
EXPORT void vec2_norm(struct vec2 *dst, const struct vec2 *v);
#ifdef __cplusplus

View file

@ -35,7 +35,7 @@ float vec3_plane_dist(const struct vec3 *v, const struct plane *p)
}
void vec3_rotate(struct vec3 *dst, const struct vec3 *v,
const struct matrix3 *m)
const struct matrix3 *m)
{
struct vec3 temp;
vec3_copy(&temp, v);
@ -47,7 +47,7 @@ void vec3_rotate(struct vec3 *dst, const struct vec3 *v,
}
void vec3_transform(struct vec3 *dst, const struct vec3 *v,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct vec4 v4;
vec4_from_vec3(&v4, v);
@ -56,7 +56,7 @@ void vec3_transform(struct vec3 *dst, const struct vec3 *v,
}
void vec3_transform3x4(struct vec3 *dst, const struct vec3 *v,
const struct matrix3 *m)
const struct matrix3 *m)
{
struct vec3 temp;
vec3_sub(&temp, v, &m->t);
@ -75,7 +75,7 @@ void vec3_mirror(struct vec3 *dst, const struct vec3 *v, const struct plane *p)
}
void vec3_mirrorv(struct vec3 *dst, const struct vec3 *v,
const struct vec3 *vec)
const struct vec3 *vec)
{
struct vec3 temp;
vec3_mulf(&temp, vec, vec3_dot(v, vec) * 2.0f);

View file

@ -58,54 +58,50 @@ static inline void vec3_copy(struct vec3 *dst, const struct vec3 *v)
EXPORT void vec3_from_vec4(struct vec3 *dst, const struct vec4 *v);
static inline void vec3_add(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
dst->m = _mm_add_ps(v1->m, v2->m);
dst->w = 0.0f;
}
static inline void vec3_sub(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
dst->m = _mm_sub_ps(v1->m, v2->m);
dst->w = 0.0f;
}
static inline void vec3_mul(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
dst->m = _mm_mul_ps(v1->m, v2->m);
}
static inline void vec3_div(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
dst->m = _mm_div_ps(v1->m, v2->m);
dst->w = 0.0f;
}
static inline void vec3_addf(struct vec3 *dst, const struct vec3 *v,
float f)
static inline void vec3_addf(struct vec3 *dst, const struct vec3 *v, float f)
{
dst->m = _mm_add_ps(v->m, _mm_set1_ps(f));
dst->w = 0.0f;
}
static inline void vec3_subf(struct vec3 *dst, const struct vec3 *v,
float f)
static inline void vec3_subf(struct vec3 *dst, const struct vec3 *v, float f)
{
dst->m = _mm_sub_ps(v->m, _mm_set1_ps(f));
dst->w = 0.0f;
}
static inline void vec3_mulf(struct vec3 *dst, const struct vec3 *v,
float f)
static inline void vec3_mulf(struct vec3 *dst, const struct vec3 *v, float f)
{
dst->m = _mm_mul_ps(v->m, _mm_set1_ps(f));
}
static inline void vec3_divf(struct vec3 *dst, const struct vec3 *v,
float f)
static inline void vec3_divf(struct vec3 *dst, const struct vec3 *v, float f)
{
dst->m = _mm_div_ps(v->m, _mm_set1_ps(f));
dst->w = 0.0f;
@ -121,7 +117,7 @@ static inline float vec3_dot(const struct vec3 *v1, const struct vec3 *v2)
}
static inline void vec3_cross(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
__m128 s1v1 = _mm_shuffle_ps(v1->m, v1->m, _MM_SHUFFLE(3, 0, 2, 1));
__m128 s1v2 = _mm_shuffle_ps(v2->m, v2->m, _MM_SHUFFLE(3, 1, 0, 2));
@ -157,13 +153,13 @@ static inline float vec3_dist(const struct vec3 *v1, const struct vec3 *v2)
static inline void vec3_norm(struct vec3 *dst, const struct vec3 *v)
{
float dot_val = vec3_dot(v, v);
dst->m = (dot_val > 0.0f) ?
_mm_mul_ps(v->m, _mm_set1_ps(1.0f/sqrtf(dot_val))) :
_mm_setzero_ps();
dst->m = (dot_val > 0.0f)
? _mm_mul_ps(v->m, _mm_set1_ps(1.0f / sqrtf(dot_val)))
: _mm_setzero_ps();
}
static inline bool vec3_close(const struct vec3 *v1, const struct vec3 *v2,
float epsilon)
float epsilon)
{
struct vec3 test;
vec3_sub(&test, v1, v2);
@ -171,28 +167,26 @@ static inline bool vec3_close(const struct vec3 *v1, const struct vec3 *v2,
}
static inline void vec3_min(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
dst->m = _mm_min_ps(v1->m, v2->m);
dst->w = 0.0f;
}
static inline void vec3_minf(struct vec3 *dst, const struct vec3 *v,
float f)
static inline void vec3_minf(struct vec3 *dst, const struct vec3 *v, float f)
{
dst->m = _mm_min_ps(v->m, _mm_set1_ps(f));
dst->w = 0.0f;
}
static inline void vec3_max(struct vec3 *dst, const struct vec3 *v1,
const struct vec3 *v2)
const struct vec3 *v2)
{
dst->m = _mm_max_ps(v1->m, v2->m);
dst->w = 0.0f;
}
static inline void vec3_maxf(struct vec3 *dst, const struct vec3 *v,
float f)
static inline void vec3_maxf(struct vec3 *dst, const struct vec3 *v, float f)
{
dst->m = _mm_max_ps(v->m, _mm_set1_ps(f));
dst->w = 0.0f;
@ -225,17 +219,17 @@ static inline void vec3_ceil(struct vec3 *dst, const struct vec3 *v)
EXPORT float vec3_plane_dist(const struct vec3 *v, const struct plane *p);
EXPORT void vec3_transform(struct vec3 *dst, const struct vec3 *v,
const struct matrix4 *m);
const struct matrix4 *m);
EXPORT void vec3_rotate(struct vec3 *dst, const struct vec3 *v,
const struct matrix3 *m);
const struct matrix3 *m);
EXPORT void vec3_transform3x4(struct vec3 *dst, const struct vec3 *v,
const struct matrix3 *m);
const struct matrix3 *m);
EXPORT void vec3_mirror(struct vec3 *dst, const struct vec3 *v,
const struct plane *p);
const struct plane *p);
EXPORT void vec3_mirrorv(struct vec3 *dst, const struct vec3 *v,
const struct vec3 *vec);
const struct vec3 *vec);
EXPORT void vec3_rand(struct vec3 *dst, int positive_only);

View file

@ -26,7 +26,7 @@ void vec4_from_vec3(struct vec4 *dst, const struct vec3 *v)
}
void vec4_transform(struct vec4 *dst, const struct vec4 *v,
const struct matrix4 *m)
const struct matrix4 *m)
{
struct vec4 temp;
struct matrix4 transpose;

View file

@ -43,7 +43,7 @@ static inline void vec4_zero(struct vec4 *v)
}
static inline void vec4_set(struct vec4 *dst, float x, float y, float z,
float w)
float w)
{
dst->m = _mm_set_ps(w, z, y, x);
}
@ -56,49 +56,45 @@ static inline void vec4_copy(struct vec4 *dst, const struct vec4 *v)
EXPORT void vec4_from_vec3(struct vec4 *dst, const struct vec3 *v);
static inline void vec4_add(struct vec4 *dst, const struct vec4 *v1,
const struct vec4 *v2)
const struct vec4 *v2)
{
dst->m = _mm_add_ps(v1->m, v2->m);
}
static inline void vec4_sub(struct vec4 *dst, const struct vec4 *v1,
const struct vec4 *v2)
const struct vec4 *v2)
{
dst->m = _mm_sub_ps(v1->m, v2->m);
}
static inline void vec4_mul(struct vec4 *dst, const struct vec4 *v1,
const struct vec4 *v2)
const struct vec4 *v2)
{
dst->m = _mm_mul_ps(v1->m, v2->m);
}
static inline void vec4_div(struct vec4 *dst, const struct vec4 *v1,
const struct vec4 *v2)
const struct vec4 *v2)
{
dst->m = _mm_div_ps(v1->m, v2->m);
}
static inline void vec4_addf(struct vec4 *dst, const struct vec4 *v,
float f)
static inline void vec4_addf(struct vec4 *dst, const struct vec4 *v, float f)
{
dst->m = _mm_add_ps(v->m, _mm_set1_ps(f));
}
static inline void vec4_subf(struct vec4 *dst, const struct vec4 *v,
float f)
static inline void vec4_subf(struct vec4 *dst, const struct vec4 *v, float f)
{
dst->m = _mm_sub_ps(v->m, _mm_set1_ps(f));
}
static inline void vec4_mulf(struct vec4 *dst, const struct vec4 *v,
float f)
static inline void vec4_mulf(struct vec4 *dst, const struct vec4 *v, float f)
{
dst->m = _mm_mul_ps(v->m, _mm_set1_ps(f));
}
static inline void vec4_divf(struct vec4 *dst, const struct vec4 *v,
float f)
static inline void vec4_divf(struct vec4 *dst, const struct vec4 *v, float f)
{
dst->m = _mm_div_ps(v->m, _mm_set1_ps(f));
}
@ -139,42 +135,38 @@ static inline float vec4_dist(const struct vec4 *v1, const struct vec4 *v2)
static inline void vec4_norm(struct vec4 *dst, const struct vec4 *v)
{
float dot_val = vec4_dot(v, v);
dst->m = (dot_val > 0.0f) ?
_mm_mul_ps(v->m, _mm_set1_ps(1.0f/sqrtf(dot_val))) :
_mm_setzero_ps();
dst->m = (dot_val > 0.0f)
? _mm_mul_ps(v->m, _mm_set1_ps(1.0f / sqrtf(dot_val)))
: _mm_setzero_ps();
}
static inline int vec4_close(const struct vec4 *v1, const struct vec4 *v2,
float epsilon)
float epsilon)
{
struct vec4 test;
vec4_sub(&test, v1, v2);
return test.x < epsilon &&
test.y < epsilon &&
test.z < epsilon &&
return test.x < epsilon && test.y < epsilon && test.z < epsilon &&
test.w < epsilon;
}
static inline void vec4_min(struct vec4 *dst, const struct vec4 *v1,
const struct vec4 *v2)
const struct vec4 *v2)
{
dst->m = _mm_min_ps(v1->m, v2->m);
}
static inline void vec4_minf(struct vec4 *dst, const struct vec4 *v,
float f)
static inline void vec4_minf(struct vec4 *dst, const struct vec4 *v, float f)
{
dst->m = _mm_min_ps(v->m, _mm_set1_ps(f));
}
static inline void vec4_max(struct vec4 *dst, const struct vec4 *v1,
const struct vec4 *v2)
const struct vec4 *v2)
{
dst->m = _mm_max_ps(v1->m, v2->m);
}
static inline void vec4_maxf(struct vec4 *dst, const struct vec4 *v,
float f)
static inline void vec4_maxf(struct vec4 *dst, const struct vec4 *v, float f)
{
dst->m = _mm_max_ps(v->m, _mm_set1_ps(f));
}
@ -206,7 +198,7 @@ static inline void vec4_ceil(struct vec4 *dst, const struct vec4 *v)
static inline uint32_t vec4_to_rgba(const struct vec4 *src)
{
uint32_t val;
val = (uint32_t)((double)src->x * 255.0);
val = (uint32_t)((double)src->x * 255.0);
val |= (uint32_t)((double)src->y * 255.0) << 8;
val |= (uint32_t)((double)src->z * 255.0) << 16;
val |= (uint32_t)((double)src->w * 255.0) << 24;
@ -216,7 +208,7 @@ static inline uint32_t vec4_to_rgba(const struct vec4 *src)
static inline uint32_t vec4_to_bgra(const struct vec4 *src)
{
uint32_t val;
val = (uint32_t)((double)src->z * 255.0);
val = (uint32_t)((double)src->z * 255.0);
val |= (uint32_t)((double)src->y * 255.0) << 8;
val |= (uint32_t)((double)src->x * 255.0) << 16;
val |= (uint32_t)((double)src->w * 255.0) << 24;
@ -225,28 +217,28 @@ static inline uint32_t vec4_to_bgra(const struct vec4 *src)
static inline void vec4_from_rgba(struct vec4 *dst, uint32_t rgba)
{
dst->x = (float)((double)(rgba&0xFF) * (1.0/255.0));
dst->x = (float)((double)(rgba & 0xFF) * (1.0 / 255.0));
rgba >>= 8;
dst->y = (float)((double)(rgba&0xFF) * (1.0/255.0));
dst->y = (float)((double)(rgba & 0xFF) * (1.0 / 255.0));
rgba >>= 8;
dst->z = (float)((double)(rgba&0xFF) * (1.0/255.0));
dst->z = (float)((double)(rgba & 0xFF) * (1.0 / 255.0));
rgba >>= 8;
dst->w = (float)((double)(rgba&0xFF) * (1.0/255.0));
dst->w = (float)((double)(rgba & 0xFF) * (1.0 / 255.0));
}
static inline void vec4_from_bgra(struct vec4 *dst, uint32_t bgra)
{
dst->z = (float)((double)(bgra&0xFF) * (1.0/255.0));
dst->z = (float)((double)(bgra & 0xFF) * (1.0 / 255.0));
bgra >>= 8;
dst->y = (float)((double)(bgra&0xFF) * (1.0/255.0));
dst->y = (float)((double)(bgra & 0xFF) * (1.0 / 255.0));
bgra >>= 8;
dst->x = (float)((double)(bgra&0xFF) * (1.0/255.0));
dst->x = (float)((double)(bgra & 0xFF) * (1.0 / 255.0));
bgra >>= 8;
dst->w = (float)((double)(bgra&0xFF) * (1.0/255.0));
dst->w = (float)((double)(bgra & 0xFF) * (1.0 / 255.0));
}
EXPORT void vec4_transform(struct vec4 *dst, const struct vec4 *v,
const struct matrix4 *m);
const struct matrix4 *m);
#ifdef __cplusplus
}