summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2019-03-26 18:00:16 +0100
committerAndre Weissflog <floooh@gmail.com>2019-03-26 18:00:16 +0100
commit095fa795df61a01e95cde166623ba94961fc5f36 (patch)
treef468ba6ce04b631e8aca0dd4bf810952cf71cfe7 /util
parent556000ebf93a31866deab24f05710aec5d32b1ef (diff)
sokol_gl.h impl stuff:
- bugfix in sgl_perspective() - default front-face winding ccw - push/pop matrix
Diffstat (limited to 'util')
-rw-r--r--util/sokol_gl.h36
1 files changed, 31 insertions, 5 deletions
diff --git a/util/sokol_gl.h b/util/sokol_gl.h
index 3e03a639..3e91be06 100644
--- a/util/sokol_gl.h
+++ b/util/sokol_gl.h
@@ -101,6 +101,7 @@ typedef struct sgl_desc_t {
sg_pixel_format color_format;
sg_pixel_format depth_format;
int sample_count;
+ sg_face_winding face_winding; /* default front face winding is CCW */
} sgl_desc_t;
/* setup/shutdown */
@@ -658,17 +659,16 @@ static void _sgl_rotate(_sgl_matrix_t* dst, float a, float x, float y, float z)
float s = sinf(a);
float c = cosf(a);
- float xx = x * x;
- float yy = y * y;
- float zz = z * z;
- float mag = sqrtf(xx + yy + zz);
+ float mag = sqrtf(x*x + y*y + z*z);
if (mag < 1.0e-4F) {
return;
}
x /= mag;
y /= mag;
z /= mag;
-
+ float xx = x * x;
+ float yy = y * y;
+ float zz = z * z;
float xy = x * y;
float yz = y * z;
float zx = z * x;
@@ -890,6 +890,7 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
_sgl.pip_desc.blend.color_format = desc->color_format;
_sgl.pip_desc.blend.depth_format = desc->depth_format;
_sgl.pip_desc.rasterizer.sample_count = desc->sample_count;
+ _sgl.pip_desc.rasterizer.face_winding = _sgl_def(desc->face_winding, SG_FACEWINDING_CCW);
}
SOKOL_API_IMPL void sgl_shutdown(void) {
@@ -1287,6 +1288,31 @@ SOKOL_API_IMPL void sgl_perspective(float fov_y, float aspect, float z_near, flo
_sgl_perspective(_sgl_matrix(), fov_y, aspect, z_near, z_far);
}
+SOKOL_API_DECL void sgl_push_matrix(void) {
+ SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
+ SOKOL_ASSERT((_sgl.cur_matrix_mode >= 0) && (_sgl.cur_matrix_mode < SGL_NUM_MATRIXMODES));
+ if (_sgl.top_of_stack[_sgl.cur_matrix_mode] < (_SGL_MAX_STACK_DEPTH - 1)) {
+ const _sgl_matrix_t* src = _sgl_matrix();
+ _sgl.top_of_stack[_sgl.cur_matrix_mode]++;
+ _sgl_matrix_t* dst = _sgl_matrix();
+ *dst = *src;
+ }
+ else {
+ _sgl.error = SGL_ERROR_STACK_OVERFLOW;
+ }
+}
+
+SOKOL_API_DECL void sgl_pop_matrix(void) {
+ SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
+ SOKOL_ASSERT((_sgl.cur_matrix_mode >= 0) && (_sgl.cur_matrix_mode < SGL_NUM_MATRIXMODES));
+ if (_sgl.top_of_stack[_sgl.cur_matrix_mode] > 0) {
+ _sgl.top_of_stack[_sgl.cur_matrix_mode]--;
+ }
+ else {
+ _sgl.error = SGL_ERROR_STACK_UNDERFLOW;
+ }
+}
+
/* this draw the accumulated draw commands via sokol-gfx */
SOKOL_API_IMPL void sgl_draw(void) {
SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);