Procházet zdrojové kódy

Merge branch 'master' into issue904-pass-cleanup

Andre Weissflog před 1 rokem
rodič
revize
d3b17072d8
4 změnil soubory, kde provedl 59 přidání a 9 odebrání
  1. 32 0
      CHANGELOG.md
  2. 2 0
      README.md
  3. 7 2
      sokol_gfx.h
  4. 18 7
      util/sokol_imgui.h

+ 32 - 0
CHANGELOG.md

@@ -1,5 +1,37 @@
 ## Updates
 
+### 27-Feb-2024:
+
+- Merged PR https://github.com/floooh/sokol/pull/1001, this is a small fix for GLES3 to avoid
+  calling glInvalidateFramebuffer() on non-existing depth/stencil surfaces.
+
+  Many thanks to @danielchasehooper!
+
+#### 26-Feb-2024:
+
+- Minor fix in sokol_imgui.h: The drawing code now detects and skips the special
+  `ImDrawCallback_ResetRenderState` constant, not doing so would try to call a function
+  at address (-8) which then results in a crash.
+
+  See for what this is: https://github.com/ocornut/imgui/blob/277ae93c41314ba5f4c7444f37c4319cdf07e8cf/imgui.h#L2583-L2587
+
+  sokol_imgui.h doesn't have any handling for this special callback, it will just ignore it.
+
+  As a minor additional behaviour change, any user callback will now also cause `sg_reset_state_cache()`
+  to be called. This is just a precaution in case the user callback code calls any native 3D backend API
+  functions.
+
+  Related issue: https://github.com/floooh/sokol/issues/1000
+
+#### 21-Feb-2024:
+
+- PR https://github.com/floooh/sokol/pull/993 has been merged, this allows to inject
+  additional GL functions into the Win32 GL loader of sokol_gfx.h (TBH, it's a very specialized
+  feature for people who know what they're doing, but it also fixes a very specific problem
+  while at the same time resolving to 'nothing' when not used).
+
+  Many thanks for @kcbanner for the PR!
+
 #### 31-Jan-2024:
 
 - sokol_app.h macOS: merged a workaround for the application window not being focused

+ 2 - 0
README.md

@@ -16,6 +16,8 @@ cross-platform libraries for C and C++, written in C.
 
 - [sokol_gp.h](https://github.com/edubart/sokol_gp) a 2D shape drawing library on top of sokol_gfx.h
 
+- [LearnOpenGL examples ported to sokol-gfx](https://zeromake.github.io/learnopengl-examples/) ([git repo](https://github.com/zeromake/learnopengl-examples))
+
 - [Dear ImGui starterkit](https://github.com/floooh/cimgui-sokol-starterkit) a self-contained starterkit for writing Dear ImGui apps in C.
 
 - [qoiview](https://github.com/floooh/qoiview) a basic viewer for the new QOI image file format

+ 7 - 2
sokol_gfx.h

@@ -6591,8 +6591,13 @@ _SOKOL_PRIVATE void _sg_dummy_update_image(_sg_image_t* img, const sg_image_data
 // optional GL loader for win32
 #if defined(_SOKOL_USE_WIN32_GL_LOADER)
 
+#ifndef SG_GL_FUNCS_EXT
+#define SG_GL_FUNCS_EXT
+#endif
+
 // X Macro list of GL function names and signatures
 #define _SG_GL_FUNCS \
+    SG_GL_FUNCS_EXT \
     _SG_XMACRO(glBindVertexArray,                 void, (GLuint array)) \
     _SG_XMACRO(glFramebufferTextureLayer,         void, (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)) \
     _SG_XMACRO(glGenFramebuffers,                 void, (GLsizei n, GLuint * framebuffers)) \
@@ -8689,10 +8694,10 @@ _SOKOL_PRIVATE void _sg_gl_end_pass(void) {
                 invalidate_atts[att_index++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i);
             }
         }
-        if (_sg.gl.depth_store_action == SG_STOREACTION_DONTCARE) {
+        if ((_sg.gl.depth_store_action == SG_STOREACTION_DONTCARE) && (_sg.gl.cur_pass->cmn.ds_att.image_id.id != SG_INVALID_ID)) {
             invalidate_atts[att_index++] = GL_DEPTH_ATTACHMENT;
         }
-        if (_sg.gl.stencil_store_action == SG_STOREACTION_DONTCARE) {
+        if ((_sg.gl.stencil_store_action == SG_STOREACTION_DONTCARE) && (_sg.gl.cur_pass->cmn.ds_att.image_id.id != SG_INVALID_ID)) {
             invalidate_atts[att_index++] = GL_STENCIL_ATTACHMENT;
         }
         if (att_index > 0) {

+ 18 - 7
util/sokol_imgui.h

@@ -609,6 +609,12 @@ inline void simgui_new_frame(const simgui_frame_desc_t& desc) { return simgui_ne
 // helper macros and constants
 #define _simgui_def(val, def) (((val) == 0) ? (def) : (val))
 
+// workaround for missing ImDrawCallback_ResetRenderState in cimgui.h
+// see: https://github.com/cimgui/cimgui/issues/261
+#ifndef ImDrawCallback_ResetRenderState
+#define ImDrawCallback_ResetRenderState (ImDrawCallback)(-8)
+#endif
+
 typedef struct {
     ImVec2 disp_size;
     uint8_t _pad_8[8];
@@ -2644,13 +2650,18 @@ SOKOL_API_IMPL void simgui_render(void) {
         uint32_t vtx_offset = 0;
         for (int cmd_index = 0; cmd_index < num_cmds; cmd_index++) {
             ImDrawCmd* pcmd = &cl->CmdBuffer.Data[cmd_index];
-            if (pcmd->UserCallback) {
-                pcmd->UserCallback(cl, pcmd);
-                // need to re-apply all state after calling a user callback
-                sg_apply_viewport(0, 0, fb_width, fb_height, true);
-                sg_apply_pipeline(_simgui.def_pip);
-                sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(vs_params));
-                sg_apply_bindings(&bind);
+            if (pcmd->UserCallback != 0) {
+                // User callback, registered via ImDrawList::AddCallback()
+                // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+                if (pcmd->UserCallback != ImDrawCallback_ResetRenderState) {
+                    pcmd->UserCallback(cl, pcmd);
+                    // need to re-apply all state after calling a user callback
+                    sg_reset_state_cache();
+                    sg_apply_viewport(0, 0, fb_width, fb_height, true);
+                    sg_apply_pipeline(_simgui.def_pip);
+                    sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(vs_params));
+                    sg_apply_bindings(&bind);
+                }
             } else {
                 if ((tex_id != pcmd->TextureId) || (vtx_offset != pcmd->VtxOffset)) {
                     tex_id = pcmd->TextureId;