update sokol (views update for gfx was breaking change)

This commit is contained in:
2025-09-14 13:34:49 -04:00
parent 8ed60cca33
commit 841a23b707
66 changed files with 5534 additions and 4516 deletions

View File

@@ -57,24 +57,24 @@ jobs:
cd ..
- name: build
run: |
./odin build examples/blend -debug
./odin build examples/bufferoffsets -debug
./odin build examples/clear -debug
./odin build examples/cube -debug
./odin build examples/debugtext -debug
./odin build examples/debugtext-print -debug
./odin build examples/debugtext-userfont -debug
./odin build examples/instancing -debug
./odin build examples/mrt -debug
./odin build examples/noninterleaved -debug
./odin build examples/offscreen -debug
./odin build examples/quad -debug
./odin build examples/saudio -debug
./odin build examples/sgl -debug
./odin build examples/sgl-context -debug
./odin build examples/sgl-points -debug
./odin build examples/shapes -debug
./odin build examples/texcube -debug
./odin build examples/triangle -debug
./odin build examples/vertexpull -debug
./odin build examples/instancing-compute -debug
./odin build examples/blend -strict-style -debug
./odin build examples/bufferoffsets -strict-style -debug
./odin build examples/clear -strict-style -debug
./odin build examples/cube -strict-style -debug
./odin build examples/debugtext -strict-style -debug
./odin build examples/debugtext-print -strict-style -debug
./odin build examples/debugtext-userfont -strict-style -debug
./odin build examples/instancing -strict-style -debug
./odin build examples/mrt -strict-style -debug
./odin build examples/noninterleaved -strict-style -debug
./odin build examples/offscreen -strict-style -debug
./odin build examples/quad -strict-style -debug
./odin build examples/saudio -strict-style -debug
./odin build examples/sgl -strict-style -debug
./odin build examples/sgl-context -strict-style -debug
./odin build examples/sgl-points -strict-style -debug
./odin build examples/shapes -strict-style -debug
./odin build examples/texcube -strict-style -debug
./odin build examples/triangle -strict-style -debug
./odin build examples/vertexpull -strict-style -debug
./odin build examples/instancing-compute -strict-style -debug

View File

@@ -32,26 +32,26 @@ On Linux install the following packages: libglu1-mesa-dev, mesa-common-dev, xorg
3. Build and run the samples:
```
odin run ../examples/clear -debug
odin run ../examples/triangle -debug
odin run ../examples/quad -debug
odin run ../examples/bufferoffsets -debug
odin run ../examples/cube -debug
odin run ../examples/noninterleaved -debug
odin run ../examples/texcube -debug
odin run ../examples/shapes -debug
odin run ../examples/offscreen -debug
odin run ../examples/instancing -debug
odin run ../examples/mrt -debug
odin run ../examples/blend -debug
odin run ../examples/debugtext -debug
odin run ../examples/debugtext-print -debug
odin run ../examples/debugtext-userfont -debug
odin run ../examples/saudio -debug
odin run ../examples/sgl -debug
odin run ../examples/sgl-points -debug
odin run ../examples/sgl-context -debug
odin run ../examples/vertexpull -debug
odin run ../examples/clear -strict-style -debug
odin run ../examples/triangle -strict-style -debug
odin run ../examples/quad -strict-style -debug
odin run ../examples/bufferoffsets -strict-style -debug
odin run ../examples/cube -strict-style -debug
odin run ../examples/noninterleaved -strict-style -debug
odin run ../examples/texcube -strict-style -debug
odin run ../examples/shapes -strict-style -debug
odin run ../examples/offscreen -strict-style -debug
odin run ../examples/instancing -strict-style -debug
odin run ../examples/mrt -strict-style -debug
odin run ../examples/blend -strict-style -debug
odin run ../examples/debugtext -strict-style -debug
odin run ../examples/debugtext-print -strict-style -debug
odin run ../examples/debugtext-userfont -strict-style -debug
odin run ../examples/saudio -strict-style -debug
odin run ../examples/sgl -strict-style -debug
odin run ../examples/sgl-points -strict-style -debug
odin run ../examples/sgl-context -strict-style -debug
odin run ../examples/vertexpull -strict-style -debug
```
By default, the backend 3D API will be selected based on the target platform:

View File

@@ -66,18 +66,30 @@ package sokol_app
Link with the following system libraries:
- on macOS with Metal: Cocoa, QuartzCore, Metal, MetalKit
- on macOS with GL: Cocoa, QuartzCore, OpenGL
- on iOS with Metal: Foundation, UIKit, Metal, MetalKit
- on iOS with GL: Foundation, UIKit, OpenGLES, GLKit
- on Linux with EGL: X11, Xi, Xcursor, EGL, GL (or GLESv2), dl, pthread, m(?)
- on Linux with GLX: X11, Xi, Xcursor, GL, dl, pthread, m(?)
- on macOS:
- all backends: Foundation, Cocoa, QuartzCore
- with SOKOL_METAL: Metal, MetalKit
- with SOKOL_GLCORE: OpenGL
- with SOKOL_WGPU: a WebGPU implementation library (tested with webgpu_dawn)
- on iOS:
- all backends: Foundation, UIKit
- with SOKOL_METAL: Metal, MetalKit
- with SOKOL_GLES3: OpenGLES, GLKit
- on Linux:
- all backends: X11, Xi, Xcursor, dl, pthread, m
- with SOKOL_GLCORE: GL
- with SOKOL_GLES3: GLESv2
- with SOKOL_WGPU: a WebGPU implementation library (tested with webgpu_dawn)
- with EGL: EGL
- on Android: GLESv3, EGL, log, android
- on Windows with the MSVC or Clang toolchains: no action needed, libs are defined in-source via pragma-comment-lib
- on Windows with MINGW/MSYS2 gcc: compile with '-mwin32' so that _WIN32 is defined
- link with the following libs: -lkernel32 -luser32 -lshell32
- additionally with the GL backend: -lgdi32
- additionally with the D3D11 backend: -ld3d11 -ldxgi
- on Windows:
- with MSVC or Clang: library dependencies are defined via `#pragma comment`
- with SOKOL_WGPU: a WebGPU implementation library (tested with webgpu_dawn)
- with MINGW/MSYS2 gcc:
- compile with '-mwin32' so that _WIN32 is defined
- link with the following libs: -lkernel32 -luser32 -lshell32
- additionally with the GL backend: -lgdi32
- additionally with the D3D11 backend: -ld3d11 -ldxgi
On Linux, you also need to use the -pthread compiler and linker option, otherwise weird
things will happen, see here for details: https://github.com/floooh/sokol/issues/376
@@ -87,7 +99,7 @@ package sokol_app
On Emscripten:
- for WebGL2: add the linker option `-s USE_WEBGL2=1`
- for WebGPU: compile and link with `--use-port=emdawnwebgpu`
(for more exotic situations, read: https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md)
(for more exotic situations read: https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md)
FEATURE OVERVIEW
================
@@ -95,11 +107,12 @@ package sokol_app
implements the 'application-wrapper' parts of a 3D application:
- a common application entry function
- creates a window and 3D-API context/device with a 'default framebuffer'
- creates a window and 3D-API context/device with a swapchain
surface, depth-stencil-buffer surface and optionally MSAA surface
- makes the rendered frame visible
- provides keyboard-, mouse- and low-level touch-events
- platforms: MacOS, iOS, HTML5, Win32, Linux/RaspberryPi, Android
- 3D-APIs: Metal, D3D11, GL4.1, GL4.3, GLES3, WebGL, WebGL2, NOAPI
- 3D-APIs: Metal, D3D11, GL4.1, GL4.3, GLES3, WebGL2, WebGPU, NOAPI
FEATURE/PLATFORM MATRIX
=======================
@@ -109,6 +122,7 @@ package sokol_app
gles3/webgl2 | --- | --- | YES(2)| YES | YES | YES
metal | --- | YES | --- | YES | --- | ---
d3d11 | YES | --- | --- | --- | --- | ---
webgpu | YES(4) | YES(4)| YES(4)| NO | NO | YES
noapi | YES | TODO | TODO | --- | TODO | ---
KEY_DOWN | YES | YES | YES | SOME | TODO | YES
KEY_UP | YES | YES | YES | SOME | TODO | YES
@@ -134,7 +148,7 @@ package sokol_app
IME | TODO | TODO? | TODO | ??? | TODO | ???
key repeat flag | YES | YES | YES | --- | --- | YES
windowed | YES | YES | YES | --- | --- | YES
fullscreen | YES | YES | YES | YES | YES | ---
fullscreen | YES | YES | YES | YES | YES | YES(3)
mouse hide | YES | YES | YES | --- | --- | YES
mouse lock | YES | YES | YES | --- | --- | YES
set cursor type | YES | YES | YES | --- | --- | YES
@@ -148,6 +162,9 @@ package sokol_app
(1) macOS has no regular window icons, instead the dock icon is changed
(2) supported with EGL only (not GLX)
(3) fullscreen in the browser not supported on iphones
(4) WebGPU on native desktop platforms should be considered experimental
and mainly useful for debugging and benchmarking
STEP BY STEP
============
@@ -687,8 +704,7 @@ package sokol_app
const size_t num_bytes = response->data.size;
// and the pointer to the data (same as 'buf' in the fetch-call):
const void* ptr = response->data.ptr;
}
else {
} else {
// on error check the error code:
switch (response->error_code) {
case SAPP_HTML5_FETCH_ERROR_BUFFER_TOO_SMALL:
@@ -865,6 +881,15 @@ package sokol_app
To check if the application window is currently in fullscreen mode,
call sapp_is_fullscreen().
On the web, sapp_desc.fullscreen will have no effect, and the application
will always start in non-fullscreen mode. Call sapp_toggle_fullscreen()
from within or 'near' an input event to switch to fullscreen programatically.
Note that on the web, the fullscreen state may change back to windowed at
any time (either because the browser had rejected switching into fullscreen,
or the user leaves fullscreen via Esc), this means that the result
of sapp_is_fullscreen() may change also without calling sapp_toggle_fullscreen()!
WINDOW ICON SUPPORT
===================
Some sokol_app.h backends allow to change the window icon programmatically:
@@ -1408,6 +1433,10 @@ foreign sokol_app_clib {
set_mouse_cursor :: proc(cursor: Mouse_Cursor) ---
// get current mouse cursor type
get_mouse_cursor :: proc() -> Mouse_Cursor ---
// associate a custom mouse cursor image to a sapp_mouse_cursor enum entry
bind_mouse_cursor_image :: proc(cursor: Mouse_Cursor, #by_ptr desc: Image_Desc) -> Mouse_Cursor ---
// restore the sapp_mouse_cursor enum entry to it's default system appearance
unbind_mouse_cursor_image :: proc(cursor: Mouse_Cursor) ---
// return the userdata pointer optionally provided in sapp_desc
userdata :: proc() -> rawptr ---
// return a copy of the sapp_desc structure
@@ -1775,16 +1804,18 @@ Range :: struct {
/*
sapp_image_desc
This is used to describe image data to sokol_app.h (at first, window
icons, later maybe cursor images).
This is used to describe image data to sokol_app.h (window icons and cursor images).
Note that the actual image pixel format depends on the use case:
The pixel format is RGBA8.
- window icon pixels are RGBA8
cursor_hotspot_x and _y are used only for cursors, to define which pixel
of the image should be aligned with the mouse position.
*/
Image_Desc :: struct {
width : c.int,
height : c.int,
cursor_hotspot_x : c.int,
cursor_hotspot_y : c.int,
pixels : Range,
}
@@ -1852,6 +1883,7 @@ Log_Item :: enum i32 {
WIN32_REGISTER_RAW_INPUT_DEVICES_FAILED_MOUSE_LOCK,
WIN32_REGISTER_RAW_INPUT_DEVICES_FAILED_MOUSE_UNLOCK,
WIN32_GET_RAW_INPUT_DATA_FAILED,
WIN32_DESTROYICON_FOR_CURSOR_FAILED,
LINUX_GLX_LOAD_LIBGL_FAILED,
LINUX_GLX_LOAD_ENTRY_POINTS_FAILED,
LINUX_GLX_EXTENSION_NOT_FOUND,
@@ -1910,6 +1942,9 @@ Log_Item :: enum i32 {
ANDROID_NATIVE_ACTIVITY_ONCREATE,
ANDROID_CREATE_THREAD_PIPE_FAILED,
ANDROID_NATIVE_ACTIVITY_CREATE_SUCCESS,
WGPU_DEVICE_LOST,
WGPU_DEVICE_LOG,
WGPU_DEVICE_UNCAPTURED_ERROR,
WGPU_SWAPCHAIN_CREATE_SURFACE_FAILED,
WGPU_SWAPCHAIN_SURFACE_GET_CAPABILITIES_FAILED,
WGPU_SWAPCHAIN_CREATE_DEPTH_STENCIL_TEXTURE_FAILED,
@@ -2036,5 +2071,21 @@ Mouse_Cursor :: enum i32 {
RESIZE_NESW,
RESIZE_ALL,
NOT_ALLOWED,
CUSTOM_0,
CUSTOM_1,
CUSTOM_2,
CUSTOM_3,
CUSTOM_4,
CUSTOM_5,
CUSTOM_6,
CUSTOM_7,
CUSTOM_8,
CUSTOM_9,
CUSTOM_10,
CUSTOM_11,
CUSTOM_12,
CUSTOM_13,
CUSTOM_14,
CUSTOM_15,
}

View File

@@ -1,16 +1,17 @@
#!/usr/bin/env bash
set -e
sokol_tools_root=../sokol-tools-bin
if [ -z "$1" ]
then
echo "usage: ./build_shaders.sh [path-to-sokol-shdc]"
exit 1
fi
shdc="$1"
build_shader() {
name=$1
dir=examples/$name
if [[ $(arch) =~ "arm64" ]]
then
shdc=$sokol_tools_root/bin/osx_arm64/sokol-shdc
else
shdc=$sokol_tools_root/bin/osx/sokol-shdc
fi
echo $dir
$shdc -i $dir/shader.glsl -o $dir/shader.odin -l glsl430:metal_macos:hlsl5 -f sokol_odin
}

File diff suppressed because it is too large Load Diff

View File

@@ -695,6 +695,10 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
#if defined(SOKOL_DUMMY_BACKEND)
#define _SAUDIO_NOTHREADS (1)
#elif defined(_SAUDIO_WINDOWS)
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#endif
#define _SAUDIO_WINTHREADS (1)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
@@ -740,6 +744,9 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
#pragma warning(push)
#pragma warning(disable:4505) /* unreferenced local function has been removed */
#endif
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
#elif defined(_SAUDIO_APPLE)
#define _SAUDIO_PTHREADS (1)
#include <pthread.h>

View File

@@ -3958,6 +3958,7 @@ typedef struct {
uint32_t init_cookie;
sdtx_desc_t desc;
sg_image font_img;
sg_view font_view;
sg_sampler font_smp;
sg_shader shader;
uint32_t fmt_buf_size;
@@ -4368,21 +4369,21 @@ static void _sdtx_setup_common(void) {
shd_desc.attrs[1].hlsl_sem_index = 1;
shd_desc.attrs[2].hlsl_sem_name = "TEXCOORD";
shd_desc.attrs[2].hlsl_sem_index = 2;
shd_desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.images[0].image_type = SG_IMAGETYPE_2D;
shd_desc.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT;
shd_desc.images[0].hlsl_register_t_n = 0;
shd_desc.images[0].msl_texture_n = 0;
shd_desc.images[0].wgsl_group1_binding_n = 64;
shd_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.views[0].texture.image_type = SG_IMAGETYPE_2D;
shd_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT;
shd_desc.views[0].texture.hlsl_register_t_n = 0;
shd_desc.views[0].texture.msl_texture_n = 0;
shd_desc.views[0].texture.wgsl_group1_binding_n = 64;
shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING;
shd_desc.samplers[0].hlsl_register_s_n = 0;
shd_desc.samplers[0].msl_sampler_n = 0;
shd_desc.samplers[0].wgsl_group1_binding_n = 80;
shd_desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.image_sampler_pairs[0].image_slot = 0;
shd_desc.image_sampler_pairs[0].sampler_slot = 0;
shd_desc.image_sampler_pairs[0].glsl_name = "tex_smp";
shd_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.texture_sampler_pairs[0].view_slot = 0;
shd_desc.texture_sampler_pairs[0].sampler_slot = 0;
shd_desc.texture_sampler_pairs[0].glsl_name = "tex_smp";
#if defined(SOKOL_GLCORE)
shd_desc.vertex_func.source = (const char*)_sdtx_vs_source_glsl410;
shd_desc.fragment_func.source = (const char*)_sdtx_fs_source_glsl410;
@@ -4428,7 +4429,7 @@ static void _sdtx_setup_common(void) {
}
}
// create font texture and sampler
// create font image, texture view and sampler
sg_image_desc img_desc;
_sdtx_clear(&img_desc, sizeof(img_desc));
img_desc.width = 256 * 8;
@@ -4439,6 +4440,13 @@ static void _sdtx_setup_common(void) {
_sdtx.font_img = sg_make_image(&img_desc);
SOKOL_ASSERT(SG_INVALID_ID != _sdtx.font_img.id);
sg_view_desc view_desc;
_sdtx_clear(&view_desc, sizeof(view_desc));
view_desc.texture.image = _sdtx.font_img;
view_desc.label = "sdtx-font-texture-view";
_sdtx.font_view = sg_make_view(&view_desc);
SOKOL_ASSERT(SG_INVALID_ID != _sdtx.font_view.id);
sg_sampler_desc smp_desc;
_sdtx_clear(&smp_desc, sizeof(smp_desc));
smp_desc.min_filter = SG_FILTER_NEAREST;
@@ -4455,6 +4463,7 @@ static void _sdtx_setup_common(void) {
static void _sdtx_discard_common(void) {
sg_push_debug_group("sokol-debugtext");
sg_destroy_sampler(_sdtx.font_smp);
sg_destroy_view(_sdtx.font_view);
sg_destroy_image(_sdtx.font_img);
sg_destroy_shader(_sdtx.shader);
if (_sdtx.fmt_buf) {
@@ -4613,7 +4622,7 @@ SOKOL_API_IMPL void _sdtx_draw_layer(_sdtx_context_t* ctx, int layer_id) {
sg_bindings bindings;
_sdtx_clear(&bindings, sizeof(bindings));
bindings.vertex_buffers[0] = ctx->vbuf;
bindings.images[0] = _sdtx.font_img;
bindings.views[0] = _sdtx.font_view;
bindings.samplers[0] = _sdtx.font_smp;
sg_apply_bindings(&bindings);
for (int cmd_index = 0; cmd_index < ctx->commands.next; cmd_index++) {

File diff suppressed because it is too large Load Diff

View File

@@ -233,9 +233,9 @@
sgl_enable_texture()
sgl_disable_texture()
sgl_texture(sg_image img, sg_sampler smp)
sgl_texture(sg_view tex_view, sg_sampler smp)
NOTE: the img and smp handles can be invalid (SG_INVALID_ID), in this
NOTE: the tex_view and smp handles can be invalid (SG_INVALID_ID), in this
case, sokol-gl will fall back to the internal default (white) texture
and sampler.
@@ -865,7 +865,7 @@ SOKOL_GL_API_DECL void sgl_scissor_rect(int x, int y, int w, int h, bool origin_
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, sg_sampler smp);
SOKOL_GL_API_DECL void sgl_texture(sg_view tex_view, sg_sampler smp);
SOKOL_GL_API_DECL void sgl_layer(int layer_id);
/* pipeline stack functions */
@@ -2767,7 +2767,7 @@ typedef enum {
typedef struct {
sg_pipeline pip;
sg_image img;
sg_view view;
sg_sampler smp;
int base_vertex;
int num_vertices;
@@ -2837,7 +2837,7 @@ typedef struct {
uint32_t rgba;
float point_size;
_sgl_primitive_type_t cur_prim_type;
sg_image cur_img;
sg_view cur_view;
sg_sampler cur_smp;
bool texturing_enabled;
bool matrix_dirty; /* reset in sgl_end(), set in any of the matrix stack functions */
@@ -2866,6 +2866,7 @@ typedef struct {
uint32_t init_cookie;
sgl_desc_t desc;
sg_image def_img; // a default white texture
sg_view def_view; // ...and the texture view for the default image
sg_sampler def_smp; // a default sampler
sg_shader shd; // same shader for all contexts
sgl_context def_ctx_id;
@@ -3305,7 +3306,7 @@ static void _sgl_init_context(sgl_context ctx_id, const sgl_context_desc_t* in_d
ctx->desc = _sgl_context_desc_defaults(in_desc);
// NOTE: frame_id must be non-zero, so that updates trigger in first frame
ctx->frame_id = 1;
ctx->cur_img = _sgl.def_img;
ctx->cur_view = _sgl.def_view;
ctx->cur_smp = _sgl.def_smp;
// allocate buffers and pools
@@ -3756,10 +3757,18 @@ static void _sgl_setup_common(void) {
_sgl.def_img = sg_make_image(&img_desc);
SOKOL_ASSERT(SG_INVALID_ID != _sgl.def_img.id);
sg_view_desc view_desc;
_sgl_clear(&view_desc, sizeof(view_desc));
view_desc.texture.image = _sgl.def_img;
view_desc.label = "sgl-default-texture-view";
_sgl.def_view = sg_make_view(&view_desc);
SOKOL_ASSERT(SG_INVALID_ID != _sgl.def_view.id);
sg_sampler_desc smp_desc;
_sgl_clear(&smp_desc, sizeof(smp_desc));
smp_desc.min_filter = SG_FILTER_NEAREST;
smp_desc.mag_filter = SG_FILTER_NEAREST;
smp_desc.label = "sgl-default-sampler";
_sgl.def_smp = sg_make_sampler(&smp_desc);
SOKOL_ASSERT(SG_INVALID_ID != _sgl.def_smp.id);
@@ -3786,21 +3795,21 @@ static void _sgl_setup_common(void) {
shd_desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params";
shd_desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
shd_desc.uniform_blocks[0].glsl_uniforms[0].array_count = 8;
shd_desc.images[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.images[0].image_type = SG_IMAGETYPE_2D;
shd_desc.images[0].sample_type = SG_IMAGESAMPLETYPE_FLOAT;
shd_desc.images[0].hlsl_register_t_n = 0;
shd_desc.images[0].msl_texture_n = 0;
shd_desc.images[0].wgsl_group1_binding_n = 64;
shd_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.views[0].texture.image_type = SG_IMAGETYPE_2D;
shd_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT;
shd_desc.views[0].texture.hlsl_register_t_n = 0;
shd_desc.views[0].texture.msl_texture_n = 0;
shd_desc.views[0].texture.wgsl_group1_binding_n = 64;
shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING;
shd_desc.samplers[0].hlsl_register_s_n = 0;
shd_desc.samplers[0].msl_sampler_n = 0;
shd_desc.samplers[0].wgsl_group1_binding_n = 80;
shd_desc.image_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.image_sampler_pairs[0].image_slot = 0;
shd_desc.image_sampler_pairs[0].sampler_slot = 0;
shd_desc.image_sampler_pairs[0].glsl_name = "tex_smp";
shd_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT;
shd_desc.texture_sampler_pairs[0].view_slot = 0;
shd_desc.texture_sampler_pairs[0].sampler_slot = 0;
shd_desc.texture_sampler_pairs[0].glsl_name = "tex_smp";
shd_desc.label = "sgl-shader";
#if defined(SOKOL_GLCORE)
shd_desc.vertex_func.source = (const char*)_sgl_vs_source_glsl410;
@@ -3843,6 +3852,7 @@ static void _sgl_setup_common(void) {
// discard resources which are shared between all contexts
static void _sgl_discard_common(void) {
sg_push_debug_group("sokol-gl");
sg_destroy_view(_sgl.def_view);
sg_destroy_image(_sgl.def_img);
sg_destroy_sampler(_sgl.def_smp);
sg_destroy_shader(_sgl.shd);
@@ -3859,7 +3869,7 @@ static void _sgl_draw(_sgl_context_t* ctx, int layer_id) {
sg_push_debug_group("sokol-gl");
uint32_t cur_pip_id = SG_INVALID_ID;
uint32_t cur_img_id = SG_INVALID_ID;
uint32_t cur_tex_id = SG_INVALID_ID;
uint32_t cur_smp_id = SG_INVALID_ID;
int cur_uniform_index = -1;
@@ -3895,16 +3905,16 @@ static void _sgl_draw(_sgl_context_t* ctx, int layer_id) {
if (args->pip.id != cur_pip_id) {
sg_apply_pipeline(args->pip);
cur_pip_id = args->pip.id;
/* when pipeline changes, also need to re-apply uniforms and bindings */
cur_img_id = SG_INVALID_ID;
// when pipeline changes, also need to re-apply uniforms and bindings
cur_tex_id = SG_INVALID_ID;
cur_smp_id = SG_INVALID_ID;
cur_uniform_index = -1;
}
if ((cur_img_id != args->img.id) || (cur_smp_id != args->smp.id)) {
ctx->bind.images[0] = args->img;
if ((cur_tex_id != args->view.id) || (cur_smp_id != args->smp.id)) {
ctx->bind.views[0] = args->view;
ctx->bind.samplers[0] = args->smp;
sg_apply_bindings(&ctx->bind);
cur_img_id = args->img.id;
cur_tex_id = args->view.id;
cur_smp_id = args->smp.id;
}
if (cur_uniform_index != args->uniform_index) {
@@ -3912,7 +3922,7 @@ static void _sgl_draw(_sgl_context_t* ctx, int layer_id) {
sg_apply_uniforms(0, &ub_range);
cur_uniform_index = args->uniform_index;
}
/* FIXME: what if number of vertices doesn't match the primitive type? */
// FIXME: what if number of vertices doesn't match the primitive type?
if (args->num_vertices > 0) {
sg_draw(args->base_vertex, args->num_vertices, 1);
}
@@ -4147,7 +4157,7 @@ SOKOL_API_IMPL void sgl_defaults(void) {
ctx->rgba = 0xFFFFFFFF;
ctx->point_size = 1.0f;
ctx->texturing_enabled = false;
ctx->cur_img = _sgl.def_img;
ctx->cur_view = _sgl.def_view;
ctx->cur_smp = _sgl.def_smp;
sgl_load_default_pipeline();
_sgl_identity(_sgl_matrix_texture(ctx));
@@ -4233,17 +4243,17 @@ SOKOL_API_IMPL void sgl_disable_texture(void) {
ctx->texturing_enabled = false;
}
SOKOL_API_IMPL void sgl_texture(sg_image img, sg_sampler smp) {
SOKOL_API_IMPL void sgl_texture(sg_view tex_view, sg_sampler smp) {
SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
_sgl_context_t* ctx = _sgl.cur_ctx;
if (!ctx) {
return;
}
SOKOL_ASSERT(!ctx->in_begin);
if (SG_INVALID_ID != img.id) {
ctx->cur_img = img;
if (SG_INVALID_ID != tex_view.id) {
ctx->cur_view = tex_view;
} else {
ctx->cur_img = _sgl.def_img;
ctx->cur_view = _sgl.def_view;
}
if (SG_INVALID_ID != smp.id) {
ctx->cur_smp = smp;
@@ -4339,7 +4349,7 @@ SOKOL_API_IMPL void sgl_end(void) {
// check if command can be merged with current command
sg_pipeline pip = _sgl_get_pipeline(ctx->pip_stack[ctx->pip_tos], ctx->cur_prim_type);
sg_image img = ctx->texturing_enabled ? ctx->cur_img : _sgl.def_img;
sg_view view = ctx->texturing_enabled ? ctx->cur_view : _sgl.def_view;
sg_sampler smp = ctx->texturing_enabled ? ctx->cur_smp : _sgl.def_smp;
_sgl_command_t* cur_cmd = _sgl_cur_command(ctx);
bool merge_cmd = false;
@@ -4349,7 +4359,7 @@ SOKOL_API_IMPL void sgl_end(void) {
(ctx->cur_prim_type != SGL_PRIMITIVETYPE_LINE_STRIP) &&
(ctx->cur_prim_type != SGL_PRIMITIVETYPE_TRIANGLE_STRIP) &&
!matrix_dirty &&
(cur_cmd->args.draw.img.id == img.id) &&
(cur_cmd->args.draw.view.id == view.id) &&
(cur_cmd->args.draw.smp.id == smp.id) &&
(cur_cmd->args.draw.pip.id == pip.id))
{
@@ -4366,7 +4376,7 @@ SOKOL_API_IMPL void sgl_end(void) {
SOKOL_ASSERT(ctx->uniforms.next > 0);
cmd->cmd = SGL_COMMAND_DRAW;
cmd->layer_id = ctx->layer_id;
cmd->args.draw.img = img;
cmd->args.draw.view = view;
cmd->args.draw.smp = smp;
cmd->args.draw.pip = _sgl_get_pipeline(ctx->pip_stack[ctx->pip_tos], ctx->cur_prim_type);
cmd->args.draw.base_vertex = ctx->base_vertex;

File diff suppressed because it is too large Load Diff

View File

@@ -234,9 +234,9 @@ package sokol_gl
sgl_enable_texture()
sgl_disable_texture()
sgl_texture(sg_image img, sg_sampler smp)
sgl_texture(sg_view tex_view, sg_sampler smp)
NOTE: the img and smp handles can be invalid (SG_INVALID_ID), in this
NOTE: the tex_view and smp handles can be invalid (SG_INVALID_ID), in this
case, sokol-gl will fall back to the internal default (white) texture
and sampler.
@@ -804,7 +804,7 @@ foreign sokol_gl_clib {
scissor_rectf :: proc(x: f32, y: f32, w: f32, h: f32, origin_top_left: bool) ---
enable_texture :: proc() ---
disable_texture :: proc() ---
texture :: proc(img: sg.Image, smp: sg.Sampler) ---
texture :: proc(tex_view: sg.View, smp: sg.Sampler) ---
layer :: proc(#any_int layer_id: c.int) ---
// pipeline stack functions
load_default_pipeline :: proc() ---

Binary file not shown.