فهرست منبع

Merge branch 'danielchasehooper-master'

Andre Weissflog 2 سال پیش
والد
کامیت
48987bca0c
4فایلهای تغییر یافته به همراه28 افزوده شده و 0 حذف شده
  1. 9 0
      CHANGELOG.md
  2. 2 0
      bindgen/gen_rust.py
  3. 2 0
      bindgen/gen_zig.py
  4. 15 0
      sokol_gfx.h

+ 9 - 0
CHANGELOG.md

@@ -1,5 +1,14 @@
 ## Updates
 ## Updates
 
 
+#### 23-Sep-2023
+
+- sokol_gfx.h gl: Allow to inject an external GL framebuffer id into the sokol-gfx default
+  pass. See PR https://github.com/floooh/sokol/pull/899 and issue https://github.com/floooh/sokol/issues/892
+  for details. Many thanks to @danielchasehooper for the discussion and PR!
+
+  Further down the road I want to make the whole topic more flexible while at the same time
+  simplifying the sokol-gfx API, see here: https://github.com/floooh/sokol/issues/904
+
 #### 22-Sep-2023
 #### 22-Sep-2023
 
 
 - sokol_gfx.h: Fixed a Metal validation error on Intel Macs when creating textures (Intel Macs
 - sokol_gfx.h: Fixed a Metal validation error on Intel Macs when creating textures (Intel Macs

+ 2 - 0
bindgen/gen_rust.py

@@ -355,6 +355,8 @@ def funcptr_result_c(field_type):
     res_type = field_type[: field_type.index("(*)")].strip()
     res_type = field_type[: field_type.index("(*)")].strip()
     if res_type == "void":
     if res_type == "void":
         return ""
         return ""
+    elif is_prim_type(res_type):
+        return as_rust_prim_type(res_type)
     elif util.is_const_void_ptr(res_type):
     elif util.is_const_void_ptr(res_type):
         return " -> *const core::ffi::c_void"
         return " -> *const core::ffi::c_void"
     elif util.is_void_ptr(res_type):
     elif util.is_void_ptr(res_type):

+ 2 - 0
bindgen/gen_zig.py

@@ -271,6 +271,8 @@ def funcptr_result_c(field_type):
     res_type = field_type[:field_type.index('(*)')].strip()
     res_type = field_type[:field_type.index('(*)')].strip()
     if res_type == 'void':
     if res_type == 'void':
         return 'void'
         return 'void'
+    elif is_prim_type(res_type):
+        return as_zig_prim_type(res_type)
     elif util.is_const_void_ptr(res_type):
     elif util.is_const_void_ptr(res_type):
         return '?*const anyopaque'
         return '?*const anyopaque'
     elif util.is_void_ptr(res_type):
     elif util.is_void_ptr(res_type):

+ 15 - 0
sokol_gfx.h

@@ -3245,6 +3245,12 @@ typedef struct sg_wgpu_context_desc {
     void* user_data;
     void* user_data;
 } sg_wgpu_context_desc;
 } sg_wgpu_context_desc;
 
 
+typedef struct sg_gl_context_desc {
+    uint32_t (*default_framebuffer_cb)(void);
+    uint32_t (*default_framebuffer_userdata_cb)(void*);
+    void* user_data;
+} sg_gl_context_desc;
+
 typedef struct sg_context_desc {
 typedef struct sg_context_desc {
     sg_pixel_format color_format;
     sg_pixel_format color_format;
     sg_pixel_format depth_format;
     sg_pixel_format depth_format;
@@ -3252,6 +3258,7 @@ typedef struct sg_context_desc {
     sg_metal_context_desc metal;
     sg_metal_context_desc metal;
     sg_d3d11_context_desc d3d11;
     sg_d3d11_context_desc d3d11;
     sg_wgpu_context_desc wgpu;
     sg_wgpu_context_desc wgpu;
+    sg_gl_context_desc gl;
 } sg_context_desc;
 } sg_context_desc;
 
 
 /*
 /*
@@ -7036,6 +7043,8 @@ _SOKOL_PRIVATE void _sg_gl_reset_state_cache(void) {
 
 
 _SOKOL_PRIVATE void _sg_gl_setup_backend(const sg_desc* desc) {
 _SOKOL_PRIVATE void _sg_gl_setup_backend(const sg_desc* desc) {
     _SOKOL_UNUSED(desc);
     _SOKOL_UNUSED(desc);
+    SOKOL_ASSERT(desc->context.gl.default_framebuffer_cb == 0 || desc->context.gl.default_framebuffer_userdata_cb == 0);
+    
     // assumes that _sg.gl is already zero-initialized
     // assumes that _sg.gl is already zero-initialized
     _sg.gl.valid = true;
     _sg.gl.valid = true;
 
 
@@ -7724,6 +7733,12 @@ _SOKOL_PRIVATE void _sg_gl_begin_pass(_sg_pass_t* pass, const sg_pass_action* ac
         #if defined(SOKOL_GLCORE33)
         #if defined(SOKOL_GLCORE33)
         glDisable(GL_FRAMEBUFFER_SRGB);
         glDisable(GL_FRAMEBUFFER_SRGB);
         #endif
         #endif
+        if (_sg.desc.context.gl.default_framebuffer_userdata_cb) {
+            _sg.gl.cur_context->default_framebuffer = _sg.desc.context.gl.default_framebuffer_userdata_cb(_sg.desc.context.gl.user_data);
+        } else if (_sg.desc.context.gl.default_framebuffer_cb) {
+            _sg.gl.cur_context->default_framebuffer = _sg.desc.context.gl.default_framebuffer_cb();
+        }
+
         glBindFramebuffer(GL_FRAMEBUFFER, _sg.gl.cur_context->default_framebuffer);
         glBindFramebuffer(GL_FRAMEBUFFER, _sg.gl.cur_context->default_framebuffer);
     }
     }
     glViewport(0, 0, w, h);
     glViewport(0, 0, w, h);