From 495f9972e5c5a4ab5b8150121e98c25e4b5b4da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sun, 10 Sep 2023 18:16:25 +0200 Subject: [PATCH] render: api adjustments --- MAKE.bat | 7 +++++++ demos/99-compute.c | 2 +- engine/art/shaders/header_shadertoy.glsl | 2 +- engine/bind/v4k.lua | 15 ++++++++++----- engine/joint/v4k.h | 23 +++++++++++++++-------- engine/split/v4k_render.h | 19 +++++++++++++------ engine/split/v4k_window.c | 4 ++-- engine/v4k.c | 4 ++-- engine/v4k.h | 19 +++++++++++++------ 9 files changed, 64 insertions(+), 31 deletions(-) diff --git a/MAKE.bat b/MAKE.bat index 8a05b85..ceb43b9 100644 --- a/MAKE.bat +++ b/MAKE.bat @@ -43,6 +43,7 @@ if "%1"=="help" ( echo nov4k \ do not compile framework echo demos ^| do compile demos echo editor / do compile editor + echo run ^| run compiled .exe echo vis ^> visualize invokation cmdline. echo args ^> after `--` separator is found, pass all remaining arguments to compiler as-is echo. @@ -359,6 +360,7 @@ set editor=no set vis=no set proj=no set rc=0 +set run=no :parse_args if "%1"=="--" shift && goto parse_compiler_args @@ -386,6 +388,7 @@ set rc=0 if "%1"=="noeditor" set "editor=no" && goto loop if "%1"=="hello" set "hello=yes" && goto loop if "%1"=="editor" set "editor=yes" && set "hello=no"&& goto loop + if "%1"=="run" set "run=yes" && goto loop if "%1"=="all" set "v4k=yes" && set "demos=yes" && set "extras=yes" && set "editor=yes" && set "hello=yes" && goto loop if "%1"=="tcc" set "cc=%1" && goto loop @@ -623,6 +626,10 @@ if "!vis!"=="yes" echo !cc! !other! !import! !args! !echo! !other! && !cc! !other! !import! !args! || set rc=1 ) +rem if "!run!"=="yes" ( +rem ! +rem ) + rem PAUSE only if double-clicked from Windows explorer rem (((echo.%cmdcmdline%)|%WINDIR%\system32\find.exe /I "%~0")>nul)&&pause diff --git a/demos/99-compute.c b/demos/99-compute.c index 0cc1331..a352497 100644 --- a/demos/99-compute.c +++ b/demos/99-compute.c @@ -10,7 +10,7 @@ int main() { unsigned comp = compute(vfs_read("shaders/compute-test.glsl")); texture_t tex = texture_create(TEX_WIDTH, TEX_WIDTH, 4, 0, TEXTURE_LINEAR|TEXTURE_FLOAT); shader_bind(comp); - shader_image(tex, 0, 0, 0, READ); + shader_image(tex, 0, 0, 0, BUFFER_READ); struct { float f; diff --git a/engine/art/shaders/header_shadertoy.glsl b/engine/art/shaders/header_shadertoy.glsl index 8ac26a2..886064c 100644 --- a/engine/art/shaders/header_shadertoy.glsl +++ b/engine/art/shaders/header_shadertoy.glsl @@ -21,4 +21,4 @@ out vec4 fragColor; void mainImage( out vec4 fragColor, in vec2 fragCoord ); void main() { mainImage(fragColor, texCoord.xy); -} \ No newline at end of file +} diff --git a/engine/bind/v4k.lua b/engine/bind/v4k.lua index 1b97e52..16028b1 100644 --- a/engine/bind/v4k.lua +++ b/engine/bind/v4k.lua @@ -2360,10 +2360,10 @@ int texture_width; void shader_colormap(const char *name, colormap_t cm); unsigned shader_get_active(); void shader_destroy(unsigned shader); -enum ACCESS_MODE { -READ, -WRITE, -READ_WRITE +enum BUFFER_ACCESS_MODE { +BUFFER_READ, +BUFFER_WRITE, +BUFFER_READ_WRITE }; unsigned compute(const char *cs); void compute_dispatch(unsigned wx, unsigned wy, unsigned wz); @@ -2371,7 +2371,7 @@ READ_WRITE void shader_image_unit(unsigned texture, unsigned unit, unsigned level, int layer, unsigned texel_type, unsigned access); void image_write_barrier(); void write_barrier(); -enum USAGE_MODE { +enum SSBO_USAGE_MODE { STATIC_DRAW, STATIC_READ, STATIC_COPY, @@ -2381,6 +2381,11 @@ DYNAMIC_COPY, STREAM_DRAW, STREAM_READ, STREAM_COPY +}; +enum SSBO_ACCESS { +SSBO_READ = BUFFER_READ, +SSBO_WRITE = BUFFER_WRITE, +SSBO_READ_WRITE = BUFFER_READ_WRITE }; unsigned ssbo_create(const void *data, int len, unsigned usage); void ssbo_destroy(unsigned ssbo); diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 5a68adf..d14d95d 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -16490,13 +16490,14 @@ API void shader_colormap(const char *name, colormap_t cm); API unsigned shader_get_active(); API void shader_destroy(unsigned shader); -// compute shaders -enum ACCESS_MODE { - READ, - WRITE, - READ_WRITE +enum BUFFER_ACCESS_MODE { + BUFFER_READ, + BUFFER_WRITE, + BUFFER_READ_WRITE }; +// compute shaders + /// Loads the compute shader and compiles a GL program. /// return: GL program, 0 if failed. /// cs: shader source code @@ -16542,7 +16543,7 @@ API void write_barrier(); /// `DRAW` favors CPU->GPU operations. /// `READ` favors GPU->CPU operations. /// `COPY` favors CPU->GPU->CPU operations. -enum USAGE_MODE { +enum SSBO_USAGE_MODE { STATIC_DRAW, STATIC_READ, STATIC_COPY, @@ -16556,6 +16557,12 @@ enum USAGE_MODE { STREAM_COPY }; +enum SSBO_ACCESS { + SSBO_READ = BUFFER_READ, + SSBO_WRITE = BUFFER_WRITE, + SSBO_READ_WRITE = BUFFER_READ_WRITE +}; + /// Create Shader Storage Buffer Object /// !!! `data` can be NULL /// data: optional pointer to data to upload @@ -349016,8 +349023,8 @@ void window_hints(unsigned flags) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // osx glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // osx, 2:#version150,3:330 #else - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); #endif #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //osx diff --git a/engine/split/v4k_render.h b/engine/split/v4k_render.h index ef77fcf..5cccc91 100644 --- a/engine/split/v4k_render.h +++ b/engine/split/v4k_render.h @@ -335,13 +335,14 @@ API void shader_colormap(const char *name, colormap_t cm); API unsigned shader_get_active(); API void shader_destroy(unsigned shader); -// compute shaders -enum ACCESS_MODE { - READ, - WRITE, - READ_WRITE +enum BUFFER_ACCESS_MODE { + BUFFER_READ, + BUFFER_WRITE, + BUFFER_READ_WRITE }; +// compute shaders + /// Loads the compute shader and compiles a GL program. /// return: GL program, 0 if failed. /// cs: shader source code @@ -387,7 +388,7 @@ API void write_barrier(); /// `DRAW` favors CPU->GPU operations. /// `READ` favors GPU->CPU operations. /// `COPY` favors CPU->GPU->CPU operations. -enum USAGE_MODE { +enum SSBO_USAGE_MODE { STATIC_DRAW, STATIC_READ, STATIC_COPY, @@ -401,6 +402,12 @@ enum USAGE_MODE { STREAM_COPY }; +enum SSBO_ACCESS { + SSBO_READ = BUFFER_READ, + SSBO_WRITE = BUFFER_WRITE, + SSBO_READ_WRITE = BUFFER_READ_WRITE +}; + /// Create Shader Storage Buffer Object /// !!! `data` can be NULL /// data: optional pointer to data to upload diff --git a/engine/split/v4k_window.c b/engine/split/v4k_window.c index 98ced40..03d0b64 100644 --- a/engine/split/v4k_window.c +++ b/engine/split/v4k_window.c @@ -174,8 +174,8 @@ void window_hints(unsigned flags) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // osx glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // osx, 2:#version150,3:330 #else - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); #endif #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //osx diff --git a/engine/v4k.c b/engine/v4k.c index 359f870..f6ec920 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -19932,8 +19932,8 @@ void window_hints(unsigned flags) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // osx glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // osx, 2:#version150,3:330 #else - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); #endif #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //osx diff --git a/engine/v4k.h b/engine/v4k.h index 0b7df70..730f812 100644 --- a/engine/v4k.h +++ b/engine/v4k.h @@ -2573,13 +2573,14 @@ API void shader_colormap(const char *name, colormap_t cm); API unsigned shader_get_active(); API void shader_destroy(unsigned shader); -// compute shaders -enum ACCESS_MODE { - READ, - WRITE, - READ_WRITE +enum BUFFER_ACCESS_MODE { + BUFFER_READ, + BUFFER_WRITE, + BUFFER_READ_WRITE }; +// compute shaders + /// Loads the compute shader and compiles a GL program. /// return: GL program, 0 if failed. /// cs: shader source code @@ -2625,7 +2626,7 @@ API void write_barrier(); /// `DRAW` favors CPU->GPU operations. /// `READ` favors GPU->CPU operations. /// `COPY` favors CPU->GPU->CPU operations. -enum USAGE_MODE { +enum SSBO_USAGE_MODE { STATIC_DRAW, STATIC_READ, STATIC_COPY, @@ -2639,6 +2640,12 @@ enum USAGE_MODE { STREAM_COPY }; +enum SSBO_ACCESS { + SSBO_READ = BUFFER_READ, + SSBO_WRITE = BUFFER_WRITE, + SSBO_READ_WRITE = BUFFER_READ_WRITE +}; + /// Create Shader Storage Buffer Object /// !!! `data` can be NULL /// data: optional pointer to data to upload