Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to the flat pipeline #22

Merged
merged 6 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
200 changes: 97 additions & 103 deletions .idea/editor.xml

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions assets/shaders/dst/gl33/flat.glsl_flat_glsl410_fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 410

layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec4 color;

void main()
{
fragColor = color;
}

15 changes: 15 additions & 0 deletions assets/shaders/dst/gl33/flat.glsl_flat_glsl410_vs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 410

uniform vec4 vs_params[12];
layout(location = 0) in vec3 vertexPosition;
layout(location = 0) out vec4 color;
layout(location = 1) in vec4 vertexColor;
layout(location = 2) in vec2 vertexTexture;

void main()
{
gl_Position = ((mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7])) * mat4(vs_params[8], vs_params[9], vs_params[10], vs_params[11])) * vec4(vertexPosition, 1.0);
gl_PointSize = 1.0;
color = vertexColor;
}

12 changes: 12 additions & 0 deletions assets/shaders/dst/gles/flat.glsl_flat_glsl300es_fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 300 es
precision mediump float;
precision highp int;

layout(location = 0) out highp vec4 fragColor;
in highp vec4 color;

void main()
{
fragColor = color;
}

15 changes: 15 additions & 0 deletions assets/shaders/dst/gles/flat.glsl_flat_glsl300es_vs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 300 es

uniform vec4 vs_params[12];
layout(location = 0) in vec3 vertexPosition;
out vec4 color;
layout(location = 1) in vec4 vertexColor;
layout(location = 2) in vec2 vertexTexture;

void main()
{
gl_Position = ((mat4(vs_params[0], vs_params[1], vs_params[2], vs_params[3]) * mat4(vs_params[4], vs_params[5], vs_params[6], vs_params[7])) * mat4(vs_params[8], vs_params[9], vs_params[10], vs_params[11])) * vec4(vertexPosition, 1.0);
gl_PointSize = 1.0;
color = vertexColor;
}

26 changes: 26 additions & 0 deletions assets/shaders/dst/hlsl/flat.glsl_flat_hlsl4_fs.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
static float4 fragColor;
static float4 color;

struct SPIRV_Cross_Input
{
float4 color : TEXCOORD0;
};

struct SPIRV_Cross_Output
{
float4 fragColor : SV_Target0;
};

void frag_main()
{
fragColor = color;
}

SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
color = stage_input.color;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.fragColor = fragColor;
return stage_output;
}
46 changes: 46 additions & 0 deletions assets/shaders/dst/hlsl/flat.glsl_flat_hlsl4_vs.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cbuffer vs_params : register(b0)
{
row_major float4x4 _19_projectionMatrix : packoffset(c0);
row_major float4x4 _19_viewMatrix : packoffset(c4);
row_major float4x4 _19_modelMatrix : packoffset(c8);
};


static float4 gl_Position;
static float gl_PointSize;
static float3 vertexPosition;
static float4 color;
static float4 vertexColor;
static float2 vertexTexture;

struct SPIRV_Cross_Input
{
float3 vertexPosition : TEXCOORD0;
float4 vertexColor : TEXCOORD1;
float2 vertexTexture : TEXCOORD2;
};

struct SPIRV_Cross_Output
{
float4 color : TEXCOORD0;
float4 gl_Position : SV_Position;
};

void vert_main()
{
gl_Position = mul(float4(vertexPosition, 1.0f), mul(_19_modelMatrix, mul(_19_viewMatrix, _19_projectionMatrix)));
gl_PointSize = 1.0f;
color = vertexColor;
}

SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
vertexPosition = stage_input.vertexPosition;
vertexColor = stage_input.vertexColor;
vertexTexture = stage_input.vertexTexture;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output.color = color;
return stage_output;
}
22 changes: 22 additions & 0 deletions assets/shaders/dst/metal-ios/flat.glsl_flat_metal_ios_fs.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct main0_out
{
float4 fragColor [[color(0)]];
};

struct main0_in
{
float4 color [[user(locn0)]];
};

fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.fragColor = in.color;
return out;
}

34 changes: 34 additions & 0 deletions assets/shaders/dst/metal-ios/flat.glsl_flat_metal_ios_vs.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct vs_params
{
float4x4 projectionMatrix;
float4x4 viewMatrix;
float4x4 modelMatrix;
};

struct main0_out
{
float4 color [[user(locn0)]];
float4 gl_Position [[position]];
float gl_PointSize [[point_size]];
};

struct main0_in
{
float3 vertexPosition [[attribute(0)]];
float4 vertexColor [[attribute(1)]];
};

vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]])
{
main0_out out = {};
out.gl_Position = ((_19.projectionMatrix * _19.viewMatrix) * _19.modelMatrix) * float4(in.vertexPosition, 1.0);
out.gl_PointSize = 1.0;
out.color = in.vertexColor;
return out;
}

22 changes: 22 additions & 0 deletions assets/shaders/dst/metal-macos/flat.glsl_flat_metal_macos_fs.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct main0_out
{
float4 fragColor [[color(0)]];
};

struct main0_in
{
float4 color [[user(locn0)]];
};

fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
out.fragColor = in.color;
return out;
}

34 changes: 34 additions & 0 deletions assets/shaders/dst/metal-macos/flat.glsl_flat_metal_macos_vs.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct vs_params
{
float4x4 projectionMatrix;
float4x4 viewMatrix;
float4x4 modelMatrix;
};

struct main0_out
{
float4 color [[user(locn0)]];
float4 gl_Position [[position]];
float gl_PointSize [[point_size]];
};

struct main0_in
{
float3 vertexPosition [[attribute(0)]];
float4 vertexColor [[attribute(1)]];
};

vertex main0_out main0(main0_in in [[stage_in]], constant vs_params& _19 [[buffer(0)]])
{
main0_out out = {};
out.gl_Position = ((_19.projectionMatrix * _19.viewMatrix) * _19.modelMatrix) * float4(in.vertexPosition, 1.0);
out.gl_PointSize = 1.0;
out.color = in.vertexColor;
return out;
}

36 changes: 36 additions & 0 deletions assets/shaders/src/flat.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma sokol @vs vs

in vec3 vertexPosition;
in vec4 vertexColor;
in vec2 vertexTexture;

uniform vs_params {
mat4 projectionMatrix;
mat4 viewMatrix;
mat4 modelMatrix;
};

out vec4 color;

void main(void) {
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
//gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_PointSize = 1.0;
color = vertexColor;
}

#pragma sokol @end

#pragma sokol @fs fs

in vec4 color;
out vec4 fragColor;
void main(void)
{
fragColor = color;
//fragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

#pragma sokol @end

#pragma sokol @program flat vs fs
6 changes: 6 additions & 0 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,24 @@
#define DEFAULT_FS_FILENAME "default.glsl_default_metal_macos_fs.metal"
#define SCREEN_VS_FILENAME "screen.glsl_default_metal_macos_vs.metal"
#define SCREEN_FS_FILENAME "screen.glsl_default_metal_macos_fs.metal"
#define FLAT_VS_FILENAME "flat_flat_metal_macos_vs.metal"
#define FLAT_FS_FILENAME "flat_flat_metal_macos_fs.metal"
#elif defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
#define SHADER_PATH "dst/gles"
#define DEFAULT_VS_FILENAME "default.glsl_default_glsl300es_vs.glsl"
#define DEFAULT_FS_FILENAME "default.glsl_default_glsl300es_fs.glsl"
#define SCREEN_VS_FILENAME "screen.glsl_default_glsl300es_vs.glsl"
#define SCREEN_FS_FILENAME "screen.glsl_default_glsl300es_fs.glsl"
#define FLAT_VS_FILENAME "flat_flat_glsl300es_vs.glsl"
#define FLAT_FS_FILENAME "flat_flat_glsl300es_fs.glsl"
#else
#define SHADER_PATH "dst/gl33"
#define DEFAULT_VS_FILENAME "default.glsl_default_glsl410_vs.glsl"
#define DEFAULT_FS_FILENAME "default.glsl_default_glsl410_fs.glsl"
#define SCREEN_VS_FILENAME "screen.glsl_default_glsl410_vs.glsl"
#define SCREEN_FS_FILENAME "screen.glsl_default_glsl410_fs.glsl"
#define FLAT_VS_FILENAME "flat_flat_glsl410_vs.glsl"
#define FLAT_FS_FILENAME "flat_flat_glsl410_fs.glsl"
#endif

typedef struct default_shader_params_t {
Expand Down
34 changes: 31 additions & 3 deletions src/binocle/core/binocle_app_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,36 @@ int l_binocle_app_assets_dir(lua_State *L) {
}

int l_binocle_app_shader_prefix(lua_State *L) {
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
char *s = "gles";
#if defined(BINOCLE_MACOS) && defined(BINOCLE_METAL)
char *s = "dst/metal-macos";
#elif defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
char *s = "dst/gles";
#else
char *s = "gl33";
char *s = "dst/gl33";
#endif
lua_pushstring(L, s);
return 1;
}

int l_binocle_app_shader_vs_suffix(lua_State *L) {
#if defined(BINOCLE_MACOS) && defined(BINOCLE_METAL)
char *s = "_metal_macos_vs.metal";
#elif defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
char *s = "_glsl300es_vs.glsl";
#else
char *s = "_glsl410_vs.glsl";
#endif
lua_pushstring(L, s);
return 1;
}

int l_binocle_app_shader_fs_suffix(lua_State *L) {
#if defined(BINOCLE_MACOS) && defined(BINOCLE_METAL)
char *s = "_metal_macos_fs.metal";
#elif defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
char *s = "_glsl300es_fs.glsl";
#else
char *s = "_glsl410_fs.glsl";
#endif
lua_pushstring(L, s);
return 1;
Expand All @@ -24,6 +50,8 @@ int l_binocle_app_shader_prefix(lua_State *L) {
static const struct luaL_Reg app [] = {
{"assets_dir", l_binocle_app_assets_dir},
{"shader_prefix", l_binocle_app_shader_prefix},
{"shader_vs_suffix", l_binocle_app_shader_vs_suffix},
{"shader_fs_suffix", l_binocle_app_shader_fs_suffix},
{NULL, NULL}
};

Expand Down
Loading
Loading