Răsfoiți Sursa

sokol_app.h: remove sapp_pixel_format enum

The functions sapp_color_format() and sapp_depth_format() instead
return an integer value that's compatible with sg_pixel_format
now. This allows to plug the return value directly into
places where sg_pixel_format is expected without casting
(recent clang versions started to warn about the conversion
from sapp_pixel_format to sg_pixel_format).
Andre Weissflog 5 ani în urmă
părinte
comite
507befe2d1
2 a modificat fișierele cu 24 adăugiri și 32 ștergeri
  1. 24 28
      sokol_app.h
  2. 0 4
      sokol_glue.h

+ 24 - 28
sokol_app.h

@@ -218,16 +218,17 @@
         int sapp_height(void)
             Likewise, returns the current height of the default framebuffer.
 
-        sapp_pixel_format sapp_color_format(void)
-        sapp_pixel_format sapp_depth_format(void)
+        int sapp_color_format(void)
+        int sapp_depth_format(void)
             The color and depth-stencil pixelformats of the default framebuffer,
-            as enum values which are compatible with sokol-gfx's
-            sg_pixel_format enum:
+            as int values which are compatible with sokol-gfx's
+            sg_pixel_format enum, so they can be plugged directly in places
+            where sg_pixel_format is expected:
 
-                SAPP_PIXELFORMAT_RGBA8 == 23 == SG_PIXELFORMAT_RGBA8
-                SAPP_PIXELFORMAT_BGRA8 == 27 == SG_PIXELFORMAT_BGRA8
-                SAPP_PIXELFORMAT_DEPTH == 41 == SG_PIXELFORMAT_DEPTH
-                SAPP_PIXELFORMAT_DEPTH_STENCIL == 42 == SG_PIXELFORMAT_DEPTH_STENCIL
+                23 == SG_PIXELFORMAT_RGBA8
+                27 == SG_PIXELFORMAT_BGRA8
+                41 == SG_PIXELFORMAT_DEPTH
+                42 == SG_PIXELFORMAT_DEPTH_STENCIL
 
         int sapp_sample_count(void)
             Return the MSAA sample count of the default framebuffer.
@@ -621,14 +622,6 @@ enum {
     SAPP_MAX_KEYCODES = 512,
 };
 
-/* NOTE: the pixel format values *must* be compatible with sg_pixel_format */
-typedef enum sapp_pixel_format {
-    SAPP_PIXELFORMAT_RGBA8 = 23,
-    SAPP_PIXELFORMAT_BGRA8 = 27,
-    SAPP_PIXELFORMAT_DEPTH = 41,
-    SAPP_PIXELFORMAT_DEPTH_STENCIL = 42
-} sapp_pixel_format;
-
 typedef enum sapp_event_type {
     SAPP_EVENTTYPE_INVALID,
     SAPP_EVENTTYPE_KEY_DOWN,
@@ -867,9 +860,9 @@ SOKOL_API_DECL int sapp_width(void);
 /* returns the current framebuffer height in pixels */
 SOKOL_API_DECL int sapp_height(void);
 /* get default framebuffer color pixel format */
-SOKOL_API_DECL sapp_pixel_format sapp_color_format(void);
+SOKOL_API_DECL int sapp_color_format(void);
 /* get default framebuffer depth pixel format */
-SOKOL_API_DECL sapp_pixel_format sapp_depth_format(void);
+SOKOL_API_DECL int sapp_depth_format(void);
 /* get default framebuffer sample count */
 SOKOL_API_DECL int sapp_sample_count(void);
 /* returns true when high_dpi was requested and actually running in a high-dpi scenario */
@@ -1067,9 +1060,12 @@ SOKOL_API_DECL const void* sapp_android_get_native_activity(void);
 #define _sapp_def(val, def) (((val) == 0) ? (def) : (val))
 #define _sapp_absf(a) (((a)<0.0f)?-(a):(a))
 
-enum {
-    _SAPP_MAX_TITLE_LENGTH = 128,
-};
+#define _SAPP_MAX_TITLE_LENGTH (128)
+/* NOTE: the pixel format values *must* be compatible with sg_pixel_format */
+#define _SAPP_PIXELFORMAT_RGBA8 (23)
+#define _SAPP_PIXELFORMAT_BGRA8 (27)
+#define _SAPP_PIXELFORMAT_DEPTH (41)
+#define _SAPP_PIXELFORMAT_DEPTH_STENCIL (42)
 
 typedef struct {
     bool valid;
@@ -7678,26 +7674,26 @@ SOKOL_API_IMPL int sapp_width(void) {
     return (_sapp.framebuffer_width > 0) ? _sapp.framebuffer_width : 1;
 }
 
-SOKOL_API_IMPL sapp_pixel_format sapp_color_format(void) {
+SOKOL_API_IMPL int sapp_color_format(void) {
     #if defined(SOKOL_WGPU)
         switch (_sapp_emsc.wgpu.render_format) {
             case WGPUTextureFormat_RGBA8Unorm:
-                return SAPP_PIXELFORMAT_RGBA8;
+                return _SAPP_PIXELFORMAT_RGBA8;
             case WGPUTextureFormat_BGRA8Unorm:
-                return SAPP_PIXELFORMAT_BGRA8;
+                return _SAPP_PIXELFORMAT_BGRA8;
             default:
                 SOKOL_UNREACHABLE;
                 return 0;
         }
     #elif defined(SOKOL_METAL) || defined(SOKOL_D3D11)
-        return SAPP_PIXELFORMAT_BGRA8;
+        return _SAPP_PIXELFORMAT_BGRA8;
     #else
-        return SAPP_PIXELFORMAT_RGBA8;
+        return _SAPP_PIXELFORMAT_RGBA8;
     #endif
 }
 
-SOKOL_API_IMPL sapp_pixel_format sapp_depth_format(void) {
-    return SAPP_PIXELFORMAT_DEPTH_STENCIL;
+SOKOL_API_IMPL int sapp_depth_format(void) {
+    return _SAPP_PIXELFORMAT_DEPTH_STENCIL;
 }
 
 SOKOL_API_IMPL int sapp_sample_count(void) {

+ 0 - 4
sokol_glue.h

@@ -105,10 +105,6 @@ SOKOL_API_DECL sg_context_desc sapp_sgcontext(void);
 
 #if defined(SOKOL_GFX_INCLUDED) && defined(SOKOL_APP_INCLUDED)
 SOKOL_API_IMPL sg_context_desc sapp_sgcontext(void) {
-    SOKOL_ASSERT(SAPP_PIXELFORMAT_RGBA8 == (sapp_pixel_format) SG_PIXELFORMAT_RGBA8);
-    SOKOL_ASSERT(SAPP_PIXELFORMAT_BGRA8 == (sapp_pixel_format) SG_PIXELFORMAT_BGRA8);
-    SOKOL_ASSERT(SAPP_PIXELFORMAT_DEPTH == (sapp_pixel_format) SG_PIXELFORMAT_DEPTH);
-    SOKOL_ASSERT(SAPP_PIXELFORMAT_DEPTH_STENCIL == (sapp_pixel_format) SG_PIXELFORMAT_DEPTH_STENCIL);
     sg_context_desc desc;
     memset(&desc, 0, sizeof(desc));
     desc.color_format = (sg_pixel_format) sapp_color_format();