1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Larpon
2021-04-07 20:39:23 +02:00
committed by GitHub
parent 9541eb816b
commit 8caabf0e9e
29 changed files with 4825 additions and 2965 deletions

View File

@@ -1,3 +1,6 @@
#if defined(SOKOL_IMPL) && !defined(SOKOL_FONTSTASH_IMPL)
#define SOKOL_FONTSTASH_IMPL
#endif
#ifndef SOKOL_FONTSTASH_INCLUDED
/*
sokol_fontstash.h -- renderer for https://github.com/memononen/fontstash
@@ -6,7 +9,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
#define SOKOL_IMPL or
#define SOKOL_FONTSTASH_IMPL
before you include this file in *one* C or C++ file to create the
@@ -27,7 +30,8 @@
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_MALLOC(s) - your own malloc function (default: malloc(s))
SOKOL_FREE(p) - your own free function (default: free(p))
SOKOL_API_DECL - public function declaration prefix (default: extern)
SOKOL_FONTSTASH_API_DECL - public function declaration prefix (default: extern)
SOKOL_API_DECL - same as SOKOL_FONTSTASH_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
@@ -159,23 +163,26 @@
#error "Please include sokol_gfx.h before sokol_fontstash.h"
#endif
#ifndef SOKOL_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
#define SOKOL_API_DECL __declspec(dllexport)
#if defined(SOKOL_API_DECL) && !defined(SOKOL_FONTSTASH_API_DECL)
#define SOKOL_FONTSTASH_API_DECL SOKOL_API_DECL
#endif
#ifndef SOKOL_FONTSTASH_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_FONTSTASH_IMPL)
#define SOKOL_FONTSTASH_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
#define SOKOL_API_DECL __declspec(dllimport)
#define SOKOL_FONTSTASH_API_DECL __declspec(dllimport)
#else
#define SOKOL_API_DECL extern
#define SOKOL_FONTSTASH_API_DECL extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
SOKOL_API_DECL FONScontext* sfons_create(int width, int height, int flags);
SOKOL_API_DECL void sfons_destroy(FONScontext* ctx);
SOKOL_API_DECL void sfons_flush(FONScontext* ctx);
SOKOL_API_DECL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_FONTSTASH_API_DECL FONScontext* sfons_create(int width, int height, int flags);
SOKOL_FONTSTASH_API_DECL void sfons_destroy(FONScontext* ctx);
SOKOL_FONTSTASH_API_DECL void sfons_flush(FONScontext* ctx);
SOKOL_FONTSTASH_API_DECL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
#ifdef __cplusplus
} /* extern "C" */
@@ -1603,7 +1610,7 @@ static int _sfons_render_create(void* user_ptr, int width, int height) {
ub->uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
ub->uniforms[0].array_count = 8;
shd_desc.fs.images[0].name = "tex";
shd_desc.fs.images[0].type = SG_IMAGETYPE_2D;
shd_desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
shd_desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
shd_desc.label = "sokol-fontstash-shader";
#if defined(SOKOL_GLCORE33)
@@ -1617,16 +1624,12 @@ static int _sfons_render_create(void* user_ptr, int width, int height) {
shd_desc.fs.entry = "main0";
switch (sg_query_backend()) {
case SG_BACKEND_METAL_MACOS:
shd_desc.vs.byte_code = _sfons_vs_bytecode_metal_macos;
shd_desc.vs.byte_code_size = sizeof(_sfons_vs_bytecode_metal_macos);
shd_desc.fs.byte_code = _sfons_fs_bytecode_metal_macos;
shd_desc.fs.byte_code_size = sizeof(_sfons_fs_bytecode_metal_macos);
shd_desc.vs.bytecode = SG_RANGE(_sfons_vs_bytecode_metal_macos);
shd_desc.fs.bytecode = SG_RANGE(_sfons_fs_bytecode_metal_macos);
break;
case SG_BACKEND_METAL_IOS:
shd_desc.vs.byte_code = _sfons_vs_bytecode_metal_ios;
shd_desc.vs.byte_code_size = sizeof(_sfons_vs_bytecode_metal_ios);
shd_desc.fs.byte_code = _sfons_fs_bytecode_metal_ios;
shd_desc.fs.byte_code_size = sizeof(_sfons_fs_bytecode_metal_ios);
shd_desc.vs.bytecode = SG_RANGE(_sfons_vs_bytecode_metal_ios);
shd_desc.fs.bytecode = SG_RANGE(_sfons_fs_bytecode_metal_ios);
break;
default:
shd_desc.vs.source = _sfons_vs_source_metal_sim;
@@ -1634,10 +1637,8 @@ static int _sfons_render_create(void* user_ptr, int width, int height) {
break;
}
#elif defined(SOKOL_D3D11)
shd_desc.vs.byte_code = _sfons_vs_bytecode_hlsl4;
shd_desc.vs.byte_code_size = sizeof(_sfons_vs_bytecode_hlsl4);
shd_desc.fs.byte_code = _sfons_fs_bytecode_hlsl4;
shd_desc.fs.byte_code_size = sizeof(_sfons_fs_bytecode_hlsl4);
shd_desc.vs.bytecode = SG_RANGE(_sfons_vs_bytecode_hlsl4);
shd_desc.fs.bytecode = SG_RANGE(_sfons_fs_bytecode_hlsl4);
#elif defined(SOKOL_WGPU)
shd_desc.vs.byte_code = _sfons_vs_bytecode_wgpu;
shd_desc.vs.byte_code_size = sizeof(_sfons_vs_bytecode_wgpu);
@@ -1656,9 +1657,9 @@ static int _sfons_render_create(void* user_ptr, int width, int height) {
sg_pipeline_desc pip_desc;
memset(&pip_desc, 0, sizeof(pip_desc));
pip_desc.shader = sfons->shd;
pip_desc.blend.enabled = true;
pip_desc.blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA;
pip_desc.blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
pip_desc.colors[0].blend.enabled = true;
pip_desc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA;
pip_desc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
sfons->pip = sgl_make_pipeline(&pip_desc);
}
@@ -1769,16 +1770,16 @@ SOKOL_API_IMPL void sfons_flush(FONScontext* ctx) {
_sfons_t* sfons = (_sfons_t*) ctx->params.userPtr;
if (sfons->img_dirty) {
sfons->img_dirty = false;
sg_image_content content;
memset(&content, 0, sizeof(content));
content.subimage[0][0].ptr = ctx->texData;
content.subimage[0][0].size = sfons->width * sfons->height;
sg_update_image(sfons->img, &content);
sg_image_data data;
memset(&data, 0, sizeof(data));
data.subimage[0][0].ptr = ctx->texData;
data.subimage[0][0].size = (size_t) (sfons->width * sfons->height);
sg_update_image(sfons->img, &data);
}
}
SOKOL_API_IMPL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
return (r) | (g<<8) | (b<<16) | (a<<24);
return ((uint32_t)r) | ((uint32_t)g<<8) | ((uint32_t)b<<16) | ((uint32_t)a<<24);
}
#endif /* SOKOL_FONTSTASH_IMPL */

View File

@@ -1,3 +1,6 @@
#if defined(SOKOL_IMPL) && !defined(SOKOL_GL_IMPL)
#define SOKOL_GL_IMPL
#endif
#ifndef SOKOL_GL_INCLUDED
/*
sokol_gl.h -- OpenGL 1.x style rendering on top of sokol_gfx.h
@@ -5,6 +8,7 @@
Project URL: https://github.com/floooh/sokol
Do this:
#define SOKOL_IMPL or
#define SOKOL_GL_IMPL
before you include this file in *one* C or C++ file to create the
implementation.
@@ -25,7 +29,8 @@
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
SOKOL_MALLOC(s) - your own malloc function (default: malloc(s))
SOKOL_FREE(p) - your own free function (default: free(p))
SOKOL_API_DECL - public function declaration prefix (default: extern)
SOKOL_GL_API_DECL - public function declaration prefix (default: extern)
SOKOL_API_DECL - same as SOKOL_GL_API_DECL
SOKOL_API_IMPL - public function implementation prefix (default: -)
SOKOL_LOG(msg) - your own logging function (default: puts(msg))
SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
@@ -35,7 +40,7 @@
SOKOL_DLL
On Windows, SOKOL_DLL will define SOKOL_API_DECL as __declspec(dllexport)
On Windows, SOKOL_DLL will define SOKOL_GL_API_DECL as __declspec(dllexport)
or __declspec(dllimport) as needed.
Include the following headers before including sokol_gl.h:
@@ -201,6 +206,13 @@
sgl_viewport(int x, int y, int w, int h, bool origin_top_left)
sgl_scissor_rect(int x, int y, int w, int h, bool origin_top_left)
...or call these alternatives which take float arguments (this might allow
to avoid casting between float and integer in more strongly typed languages
when floating point pixel coordinates are used):
sgl_viewportf(float x, float y, float w, float h, bool origin_top_left)
sgl_scissor_rectf(float x, float y, float w, float h, bool origin_top_left)
...these calls add a new command to the internal command queue, so
that the viewport or scissor rect are set at the right time relative
to other sokol-gl calls.
@@ -445,13 +457,16 @@
#error "Please include sokol_gfx.h before sokol_gl.h"
#endif
#ifndef SOKOL_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_IMPL)
#define SOKOL_API_DECL __declspec(dllexport)
#if defined(SOKOL_API_DECL) && !defined(SOKOL_GL_API_DECL)
#define SOKOL_GL_API_DECL SOKOL_API_DECL
#endif
#ifndef SOKOL_GL_API_DECL
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_GL_IMPL)
#define SOKOL_GL_API_DECL __declspec(dllexport)
#elif defined(_WIN32) && defined(SOKOL_DLL)
#define SOKOL_API_DECL __declspec(dllimport)
#define SOKOL_GL_API_DECL __declspec(dllimport)
#else
#define SOKOL_API_DECL extern
#define SOKOL_GL_API_DECL extern
#endif
#endif
@@ -488,92 +503,94 @@ typedef struct sgl_desc_t {
} sgl_desc_t;
/* setup/shutdown/misc */
SOKOL_API_DECL void sgl_setup(const sgl_desc_t* desc);
SOKOL_API_DECL void sgl_shutdown(void);
SOKOL_API_DECL sgl_error_t sgl_error(void);
SOKOL_API_DECL void sgl_defaults(void);
SOKOL_API_DECL float sgl_rad(float deg);
SOKOL_API_DECL float sgl_deg(float rad);
SOKOL_GL_API_DECL void sgl_setup(const sgl_desc_t* desc);
SOKOL_GL_API_DECL void sgl_shutdown(void);
SOKOL_GL_API_DECL sgl_error_t sgl_error(void);
SOKOL_GL_API_DECL void sgl_defaults(void);
SOKOL_GL_API_DECL float sgl_rad(float deg);
SOKOL_GL_API_DECL float sgl_deg(float rad);
/* create and destroy pipeline objects */
SOKOL_API_DECL sgl_pipeline sgl_make_pipeline(const sg_pipeline_desc* desc);
SOKOL_API_DECL void sgl_destroy_pipeline(sgl_pipeline pip);
SOKOL_GL_API_DECL sgl_pipeline sgl_make_pipeline(const sg_pipeline_desc* desc);
SOKOL_GL_API_DECL void sgl_destroy_pipeline(sgl_pipeline pip);
/* render state functions */
SOKOL_API_DECL void sgl_viewport(int x, int y, int w, int h, bool origin_top_left);
SOKOL_API_DECL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_top_left);
SOKOL_API_DECL void sgl_enable_texture(void);
SOKOL_API_DECL void sgl_disable_texture(void);
SOKOL_API_DECL void sgl_texture(sg_image img);
SOKOL_GL_API_DECL void sgl_viewport(int x, int y, int w, int h, bool origin_top_left);
SOKOL_GL_API_DECL void sgl_viewportf(float x, float y, float w, float h, bool origin_top_left);
SOKOL_GL_API_DECL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_top_left);
SOKOL_GL_API_DECL void sgl_scissor_rectf(float x, float y, float w, float h, bool origin_top_left);
SOKOL_GL_API_DECL void sgl_enable_texture(void);
SOKOL_GL_API_DECL void sgl_disable_texture(void);
SOKOL_GL_API_DECL void sgl_texture(sg_image img);
/* pipeline stack functions */
SOKOL_API_DECL void sgl_default_pipeline(void);
SOKOL_API_DECL void sgl_load_pipeline(sgl_pipeline pip);
SOKOL_API_DECL void sgl_push_pipeline(void);
SOKOL_API_DECL void sgl_pop_pipeline(void);
SOKOL_GL_API_DECL void sgl_default_pipeline(void);
SOKOL_GL_API_DECL void sgl_load_pipeline(sgl_pipeline pip);
SOKOL_GL_API_DECL void sgl_push_pipeline(void);
SOKOL_GL_API_DECL void sgl_pop_pipeline(void);
/* matrix stack functions */
SOKOL_API_DECL void sgl_matrix_mode_modelview(void);
SOKOL_API_DECL void sgl_matrix_mode_projection(void);
SOKOL_API_DECL void sgl_matrix_mode_texture(void);
SOKOL_API_DECL void sgl_load_identity(void);
SOKOL_API_DECL void sgl_load_matrix(const float m[16]);
SOKOL_API_DECL void sgl_load_transpose_matrix(const float m[16]);
SOKOL_API_DECL void sgl_mult_matrix(const float m[16]);
SOKOL_API_DECL void sgl_mult_transpose_matrix(const float m[16]);
SOKOL_API_DECL void sgl_rotate(float angle_rad, float x, float y, float z);
SOKOL_API_DECL void sgl_scale(float x, float y, float z);
SOKOL_API_DECL void sgl_translate(float x, float y, float z);
SOKOL_API_DECL void sgl_frustum(float l, float r, float b, float t, float n, float f);
SOKOL_API_DECL void sgl_ortho(float l, float r, float b, float t, float n, float f);
SOKOL_API_DECL void sgl_perspective(float fov_y, float aspect, float z_near, float z_far);
SOKOL_API_DECL void sgl_lookat(float eye_x, float eye_y, float eye_z, float center_x, float center_y, float center_z, float up_x, float up_y, float up_z);
SOKOL_API_DECL void sgl_push_matrix(void);
SOKOL_API_DECL void sgl_pop_matrix(void);
SOKOL_GL_API_DECL void sgl_matrix_mode_modelview(void);
SOKOL_GL_API_DECL void sgl_matrix_mode_projection(void);
SOKOL_GL_API_DECL void sgl_matrix_mode_texture(void);
SOKOL_GL_API_DECL void sgl_load_identity(void);
SOKOL_GL_API_DECL void sgl_load_matrix(const float m[16]);
SOKOL_GL_API_DECL void sgl_load_transpose_matrix(const float m[16]);
SOKOL_GL_API_DECL void sgl_mult_matrix(const float m[16]);
SOKOL_GL_API_DECL void sgl_mult_transpose_matrix(const float m[16]);
SOKOL_GL_API_DECL void sgl_rotate(float angle_rad, float x, float y, float z);
SOKOL_GL_API_DECL void sgl_scale(float x, float y, float z);
SOKOL_GL_API_DECL void sgl_translate(float x, float y, float z);
SOKOL_GL_API_DECL void sgl_frustum(float l, float r, float b, float t, float n, float f);
SOKOL_GL_API_DECL void sgl_ortho(float l, float r, float b, float t, float n, float f);
SOKOL_GL_API_DECL void sgl_perspective(float fov_y, float aspect, float z_near, float z_far);
SOKOL_GL_API_DECL void sgl_lookat(float eye_x, float eye_y, float eye_z, float center_x, float center_y, float center_z, float up_x, float up_y, float up_z);
SOKOL_GL_API_DECL void sgl_push_matrix(void);
SOKOL_GL_API_DECL void sgl_pop_matrix(void);
/* these functions only set the internal 'current texcoord / color' (valid inside or outside begin/end) */
SOKOL_API_DECL void sgl_t2f(float u, float v);
SOKOL_API_DECL void sgl_c3f(float r, float g, float b);
SOKOL_API_DECL void sgl_c4f(float r, float g, float b, float a);
SOKOL_API_DECL void sgl_c3b(uint8_t r, uint8_t g, uint8_t b);
SOKOL_API_DECL void sgl_c4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_API_DECL void sgl_c1i(uint32_t rgba);
SOKOL_GL_API_DECL void sgl_t2f(float u, float v);
SOKOL_GL_API_DECL void sgl_c3f(float r, float g, float b);
SOKOL_GL_API_DECL void sgl_c4f(float r, float g, float b, float a);
SOKOL_GL_API_DECL void sgl_c3b(uint8_t r, uint8_t g, uint8_t b);
SOKOL_GL_API_DECL void sgl_c4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_GL_API_DECL void sgl_c1i(uint32_t rgba);
/* define primitives, each begin/end is one draw command */
SOKOL_API_DECL void sgl_begin_points(void);
SOKOL_API_DECL void sgl_begin_lines(void);
SOKOL_API_DECL void sgl_begin_line_strip(void);
SOKOL_API_DECL void sgl_begin_triangles(void);
SOKOL_API_DECL void sgl_begin_triangle_strip(void);
SOKOL_API_DECL void sgl_begin_quads(void);
SOKOL_API_DECL void sgl_v2f(float x, float y);
SOKOL_API_DECL void sgl_v3f(float x, float y, float z);
SOKOL_API_DECL void sgl_v2f_t2f(float x, float y, float u, float v);
SOKOL_API_DECL void sgl_v3f_t2f(float x, float y, float z, float u, float v);
SOKOL_API_DECL void sgl_v2f_c3f(float x, float y, float r, float g, float b);
SOKOL_API_DECL void sgl_v2f_c3b(float x, float y, uint8_t r, uint8_t g, uint8_t b);
SOKOL_API_DECL void sgl_v2f_c4f(float x, float y, float r, float g, float b, float a);
SOKOL_API_DECL void sgl_v2f_c4b(float x, float y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_API_DECL void sgl_v2f_c1i(float x, float y, uint32_t rgba);
SOKOL_API_DECL void sgl_v3f_c3f(float x, float y, float z, float r, float g, float b);
SOKOL_API_DECL void sgl_v3f_c3b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b);
SOKOL_API_DECL void sgl_v3f_c4f(float x, float y, float z, float r, float g, float b, float a);
SOKOL_API_DECL void sgl_v3f_c4b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_API_DECL void sgl_v3f_c1i(float x, float y, float z, uint32_t rgba);
SOKOL_API_DECL void sgl_v2f_t2f_c3f(float x, float y, float u, float v, float r, float g, float b);
SOKOL_API_DECL void sgl_v2f_t2f_c3b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b);
SOKOL_API_DECL void sgl_v2f_t2f_c4f(float x, float y, float u, float v, float r, float g, float b, float a);
SOKOL_API_DECL void sgl_v2f_t2f_c4b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_API_DECL void sgl_v2f_t2f_c1i(float x, float y, float u, float v, uint32_t rgba);
SOKOL_API_DECL void sgl_v3f_t2f_c3f(float x, float y, float z, float u, float v, float r, float g, float b);
SOKOL_API_DECL void sgl_v3f_t2f_c3b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b);
SOKOL_API_DECL void sgl_v3f_t2f_c4f(float x, float y, float z, float u, float v, float r, float g, float b, float a);
SOKOL_API_DECL void sgl_v3f_t2f_c4b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_API_DECL void sgl_v3f_t2f_c1i(float x, float y, float z, float u, float v, uint32_t rgba);
SOKOL_API_DECL void sgl_end(void);
SOKOL_GL_API_DECL void sgl_begin_points(void);
SOKOL_GL_API_DECL void sgl_begin_lines(void);
SOKOL_GL_API_DECL void sgl_begin_line_strip(void);
SOKOL_GL_API_DECL void sgl_begin_triangles(void);
SOKOL_GL_API_DECL void sgl_begin_triangle_strip(void);
SOKOL_GL_API_DECL void sgl_begin_quads(void);
SOKOL_GL_API_DECL void sgl_v2f(float x, float y);
SOKOL_GL_API_DECL void sgl_v3f(float x, float y, float z);
SOKOL_GL_API_DECL void sgl_v2f_t2f(float x, float y, float u, float v);
SOKOL_GL_API_DECL void sgl_v3f_t2f(float x, float y, float z, float u, float v);
SOKOL_GL_API_DECL void sgl_v2f_c3f(float x, float y, float r, float g, float b);
SOKOL_GL_API_DECL void sgl_v2f_c3b(float x, float y, uint8_t r, uint8_t g, uint8_t b);
SOKOL_GL_API_DECL void sgl_v2f_c4f(float x, float y, float r, float g, float b, float a);
SOKOL_GL_API_DECL void sgl_v2f_c4b(float x, float y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_GL_API_DECL void sgl_v2f_c1i(float x, float y, uint32_t rgba);
SOKOL_GL_API_DECL void sgl_v3f_c3f(float x, float y, float z, float r, float g, float b);
SOKOL_GL_API_DECL void sgl_v3f_c3b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b);
SOKOL_GL_API_DECL void sgl_v3f_c4f(float x, float y, float z, float r, float g, float b, float a);
SOKOL_GL_API_DECL void sgl_v3f_c4b(float x, float y, float z, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_GL_API_DECL void sgl_v3f_c1i(float x, float y, float z, uint32_t rgba);
SOKOL_GL_API_DECL void sgl_v2f_t2f_c3f(float x, float y, float u, float v, float r, float g, float b);
SOKOL_GL_API_DECL void sgl_v2f_t2f_c3b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b);
SOKOL_GL_API_DECL void sgl_v2f_t2f_c4f(float x, float y, float u, float v, float r, float g, float b, float a);
SOKOL_GL_API_DECL void sgl_v2f_t2f_c4b(float x, float y, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_GL_API_DECL void sgl_v2f_t2f_c1i(float x, float y, float u, float v, uint32_t rgba);
SOKOL_GL_API_DECL void sgl_v3f_t2f_c3f(float x, float y, float z, float u, float v, float r, float g, float b);
SOKOL_GL_API_DECL void sgl_v3f_t2f_c3b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b);
SOKOL_GL_API_DECL void sgl_v3f_t2f_c4f(float x, float y, float z, float u, float v, float r, float g, float b, float a);
SOKOL_GL_API_DECL void sgl_v3f_t2f_c4b(float x, float y, float z, float u, float v, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
SOKOL_GL_API_DECL void sgl_v3f_t2f_c1i(float x, float y, float z, float u, float v, uint32_t rgba);
SOKOL_GL_API_DECL void sgl_end(void);
/* render everything */
SOKOL_API_DECL void sgl_draw(void);
SOKOL_GL_API_DECL void sgl_draw(void);
#ifdef __cplusplus
} /* extern "C" */
@@ -2070,12 +2087,12 @@ static void _sgl_init_pool(_sgl_pool_t* pool, int num) {
pool->size = num + 1;
pool->queue_top = 0;
/* generation counters indexable by pool slot index, slot 0 is reserved */
size_t gen_ctrs_size = sizeof(uint32_t) * pool->size;
size_t gen_ctrs_size = sizeof(uint32_t) * (size_t)pool->size;
pool->gen_ctrs = (uint32_t*) SOKOL_MALLOC(gen_ctrs_size);
SOKOL_ASSERT(pool->gen_ctrs);
memset(pool->gen_ctrs, 0, gen_ctrs_size);
/* it's not a bug to only reserve 'num' here */
pool->free_queue = (int*) SOKOL_MALLOC(sizeof(int)*num);
pool->free_queue = (int*) SOKOL_MALLOC(sizeof(int) * (size_t)num);
SOKOL_ASSERT(pool->free_queue);
/* never allocate the zero-th pool item since the invalid id is 0 */
for (int i = pool->size-1; i >= 1; i--) {
@@ -2134,7 +2151,7 @@ static void _sgl_setup_pipeline_pool(const sgl_desc_t* desc) {
/* note: the pools here will have an additional item, since slot 0 is reserved */
SOKOL_ASSERT((desc->pipeline_pool_size > 0) && (desc->pipeline_pool_size < _SGL_MAX_POOL_SIZE));
_sgl_init_pool(&_sgl.pip_pool.pool, desc->pipeline_pool_size);
size_t pool_byte_size = sizeof(_sgl_pipeline_t) * _sgl.pip_pool.pool.size;
size_t pool_byte_size = sizeof(_sgl_pipeline_t) * (size_t)_sgl.pip_pool.pool.size;
_sgl.pip_pool.pips = (_sgl_pipeline_t*) SOKOL_MALLOC(pool_byte_size);
SOKOL_ASSERT(_sgl.pip_pool.pips);
memset(_sgl.pip_pool.pips, 0, pool_byte_size);
@@ -2237,14 +2254,14 @@ static void _sgl_init_pipeline(sgl_pipeline pip_id, const sg_pipeline_desc* in_d
desc.shader = _sgl.shd;
}
desc.index_type = SG_INDEXTYPE_NONE;
desc.blend.color_format = _sgl.desc.color_format;
desc.blend.depth_format = _sgl.desc.depth_format;
desc.rasterizer.sample_count = _sgl.desc.sample_count;
if (desc.rasterizer.face_winding == _SG_FACEWINDING_DEFAULT) {
desc.rasterizer.face_winding = _sgl.desc.face_winding;
desc.sample_count = _sgl.desc.sample_count;
if (desc.face_winding == _SG_FACEWINDING_DEFAULT) {
desc.face_winding = _sgl.desc.face_winding;
}
if (desc.blend.color_write_mask == _SG_COLORMASK_DEFAULT) {
desc.blend.color_write_mask = SG_COLORMASK_RGB;
desc.depth.pixel_format = _sgl.desc.depth_format;
desc.colors[0].pixel_format = _sgl.desc.color_format;
if (desc.colors[0].write_mask == _SG_COLORMASK_DEFAULT) {
desc.colors[0].write_mask = SG_COLORMASK_RGB;
}
_sgl_pipeline_t* pip = _sgl_lookup_pipeline(pip_id.id);
@@ -2639,11 +2656,11 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
_sgl.num_vertices = _sgl.desc.max_vertices;
_sgl.num_uniforms = _sgl.desc.max_commands;
_sgl.num_commands = _sgl.num_uniforms;
_sgl.vertices = (_sgl_vertex_t*) SOKOL_MALLOC(_sgl.num_vertices * sizeof(_sgl_vertex_t));
_sgl.vertices = (_sgl_vertex_t*) SOKOL_MALLOC((size_t)_sgl.num_vertices * sizeof(_sgl_vertex_t));
SOKOL_ASSERT(_sgl.vertices);
_sgl.uniforms = (_sgl_uniform_t*) SOKOL_MALLOC(_sgl.num_uniforms * sizeof(_sgl_uniform_t));
_sgl.uniforms = (_sgl_uniform_t*) SOKOL_MALLOC((size_t)_sgl.num_uniforms * sizeof(_sgl_uniform_t));
SOKOL_ASSERT(_sgl.uniforms);
_sgl.commands = (_sgl_command_t*) SOKOL_MALLOC(_sgl.num_commands * sizeof(_sgl_command_t));
_sgl.commands = (_sgl_command_t*) SOKOL_MALLOC((size_t)_sgl.num_commands * sizeof(_sgl_command_t));
SOKOL_ASSERT(_sgl.commands);
_sgl_setup_pipeline_pool(&_sgl.desc);
@@ -2652,7 +2669,7 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
sg_buffer_desc vbuf_desc;
memset(&vbuf_desc, 0, sizeof(vbuf_desc));
vbuf_desc.size = _sgl.num_vertices * sizeof(_sgl_vertex_t);
vbuf_desc.size = (size_t)_sgl.num_vertices * sizeof(_sgl_vertex_t);
vbuf_desc.type = SG_BUFFERTYPE_VERTEXBUFFER;
vbuf_desc.usage = SG_USAGE_STREAM;
vbuf_desc.label = "sgl-vertex-buffer";
@@ -2672,8 +2689,7 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
img_desc.pixel_format = SG_PIXELFORMAT_RGBA8;
img_desc.min_filter = SG_FILTER_NEAREST;
img_desc.mag_filter = SG_FILTER_NEAREST;
img_desc.content.subimage[0][0].ptr = pixels;
img_desc.content.subimage[0][0].size = sizeof(pixels);
img_desc.data.subimage[0][0] = SG_RANGE(pixels);
img_desc.label = "sgl-default-texture";
_sgl.def_img = sg_make_image(&img_desc);
SOKOL_ASSERT(SG_INVALID_ID != _sgl.def_img.id);
@@ -2696,7 +2712,7 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
ub->uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
ub->uniforms[0].array_count = 8;
shd_desc.fs.images[0].name = "tex";
shd_desc.fs.images[0].type = SG_IMAGETYPE_2D;
shd_desc.fs.images[0].image_type = SG_IMAGETYPE_2D;
shd_desc.fs.images[0].sampler_type = SG_SAMPLERTYPE_FLOAT;
shd_desc.label = "sgl-shader";
#if defined(SOKOL_GLCORE33)
@@ -2710,16 +2726,12 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
shd_desc.fs.entry = "main0";
switch (sg_query_backend()) {
case SG_BACKEND_METAL_MACOS:
shd_desc.vs.byte_code = _sgl_vs_bytecode_metal_macos;
shd_desc.vs.byte_code_size = sizeof(_sgl_vs_bytecode_metal_macos);
shd_desc.fs.byte_code = _sgl_fs_bytecode_metal_macos;
shd_desc.fs.byte_code_size = sizeof(_sgl_fs_bytecode_metal_macos);
shd_desc.vs.bytecode = SG_RANGE(_sgl_vs_bytecode_metal_macos);
shd_desc.fs.bytecode = SG_RANGE(_sgl_fs_bytecode_metal_macos);
break;
case SG_BACKEND_METAL_IOS:
shd_desc.vs.byte_code = _sgl_vs_bytecode_metal_ios;
shd_desc.vs.byte_code_size = sizeof(_sgl_vs_bytecode_metal_ios);
shd_desc.fs.byte_code = _sgl_fs_bytecode_metal_ios;
shd_desc.fs.byte_code_size = sizeof(_sgl_fs_bytecode_metal_ios);
shd_desc.vs.bytecode = SG_RANGE(_sgl_vs_bytecode_metal_ios);
shd_desc.fs.bytecode = SG_RANGE(_sgl_fs_bytecode_metal_ios);
break;
default:
shd_desc.vs.source = _sgl_vs_source_metal_sim;
@@ -2727,15 +2739,11 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
break;
}
#elif defined(SOKOL_D3D11)
shd_desc.vs.byte_code = _sgl_vs_bytecode_hlsl4;
shd_desc.vs.byte_code_size = sizeof(_sgl_vs_bytecode_hlsl4);
shd_desc.fs.byte_code = _sgl_fs_bytecode_hlsl4;
shd_desc.fs.byte_code_size = sizeof(_sgl_fs_bytecode_hlsl4);
shd_desc.vs.bytecode = SG_RANGE(_sgl_vs_bytecode_hlsl4);
shd_desc.fs.bytecode = SG_RANGE(_sgl_fs_bytecode_hlsl4);
#elif defined(SOKOL_WGPU)
shd_desc.vs.byte_code = _sgl_vs_bytecode_wgpu;
shd_desc.vs.byte_code_size = sizeof(_sgl_vs_bytecode_wgpu);
shd_desc.fs.byte_code = _sgl_fs_bytecode_wgpu;
shd_desc.fs.byte_code_size = sizeof(_sgl_fs_bytecode_wgpu);
shd_desc.vs.bytecode = SG_RANGE(_sgl_vs_bytecode_wgpu);
shd_desc.fs.bytecode = SG_RANGE(_sgl_fs_bytecode_wgpu);
#else
shd_desc.vs.source = _sgl_vs_src_dummy;
shd_desc.fs.source = _sgl_fs_src_dummy;
@@ -2746,7 +2754,7 @@ SOKOL_API_IMPL void sgl_setup(const sgl_desc_t* desc) {
/* create default pipeline object */
sg_pipeline_desc def_pip_desc;
memset(&def_pip_desc, 0, sizeof(def_pip_desc));
def_pip_desc.depth_stencil.depth_write_enabled = true;
def_pip_desc.depth.write_enabled = true;
_sgl.def_pip = _sgl_make_pipeline(&def_pip_desc);
sg_pop_debug_group();
@@ -2861,6 +2869,10 @@ SOKOL_API_IMPL void sgl_viewport(int x, int y, int w, int h, bool origin_top_lef
}
}
SOKOL_API_IMPL void sgl_viewportf(float x, float y, float w, float h, bool origin_top_left) {
sgl_viewport((int)x, (int)y, (int)w, (int)h, origin_top_left);
}
SOKOL_API_IMPL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_top_left) {
SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
SOKOL_ASSERT(!_sgl.in_begin);
@@ -2875,6 +2887,10 @@ SOKOL_API_IMPL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_top
}
}
SOKOL_API_IMPL void sgl_scissor_rectf(float x, float y, float w, float h, bool origin_top_left) {
sgl_scissor_rect((int)x, (int)y, (int)w, (int)h, origin_top_left);
}
SOKOL_API_IMPL void sgl_enable_texture(void) {
SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
SOKOL_ASSERT(!_sgl.in_begin);
@@ -3193,7 +3209,7 @@ SOKOL_API_IMPL void sgl_lookat(float eye_x, float eye_y, float eye_z, float cent
_sgl_lookat(_sgl_matrix(), eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z);
}
SOKOL_API_DECL void sgl_push_matrix(void) {
SOKOL_GL_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));
_sgl.matrix_dirty = true;
@@ -3208,7 +3224,7 @@ SOKOL_API_DECL void sgl_push_matrix(void) {
}
}
SOKOL_API_DECL void sgl_pop_matrix(void) {
SOKOL_GL_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));
_sgl.matrix_dirty = true;
@@ -3228,7 +3244,8 @@ SOKOL_API_IMPL void sgl_draw(void) {
uint32_t cur_img_id = SG_INVALID_ID;
int cur_uniform_index = -1;
sg_push_debug_group("sokol-gl");
sg_update_buffer(_sgl.vbuf, _sgl.vertices, _sgl.cur_vertex * sizeof(_sgl_vertex_t));
const sg_range range = { _sgl.vertices, (size_t)_sgl.cur_vertex * sizeof(_sgl_vertex_t) };
sg_update_buffer(_sgl.vbuf, &range);
_sgl.bind.vertex_buffers[0] = _sgl.vbuf;
for (int i = 0; i < _sgl.cur_command; i++) {
const _sgl_command_t* cmd = &_sgl.commands[i];
@@ -3261,7 +3278,8 @@ SOKOL_API_IMPL void sgl_draw(void) {
cur_img_id = args->img.id;
}
if (cur_uniform_index != args->uniform_index) {
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &_sgl.uniforms[args->uniform_index], sizeof(_sgl_uniform_t));
const sg_range ub_range = { &_sgl.uniforms[args->uniform_index], sizeof(_sgl_uniform_t) };
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, &ub_range);
cur_uniform_index = args->uniform_index;
}
/* FIXME: what if number of vertices doesn't match the primitive type? */