Spinning cube. Very fragile, don't touch
This commit is contained in:
parent
b497d1b34c
commit
9ddaff5ad5
7 changed files with 853 additions and 101 deletions
29
source/basic.glsl
Normal file
29
source/basic.glsl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
@vs vs
|
||||
in vec4 pos;
|
||||
in vec4 vcolor;
|
||||
out vec4 color;
|
||||
|
||||
layout(binding = 0) uniform UBO {
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
} ubo;
|
||||
|
||||
void main() {
|
||||
color = vcolor;
|
||||
mat4 mvp = ubo.model*ubo.view*ubo.proj;
|
||||
gl_Position = ubo.model*ubo.view*ubo.proj*vec4(pos.xyz, 1.0);
|
||||
}
|
||||
@end
|
||||
|
||||
@fs fs
|
||||
in vec4 color;
|
||||
out vec4 frag_color;
|
||||
void main() {
|
||||
frag_color = color;
|
||||
}
|
||||
@end
|
||||
|
||||
@program basic vs fs
|
||||
|
||||
// thirdparty\sokol\sokol-shdc-windows.exe --input source\basic.glsl --output source\basic.glsl.h --slang glsl430:hlsl5:metal_macos
|
||||
451
source/basic.glsl.h
Normal file
451
source/basic.glsl.h
Normal file
|
|
@ -0,0 +1,451 @@
|
|||
#pragma once
|
||||
/*
|
||||
#version:1# (machine generated, don't edit!)
|
||||
|
||||
Generated by sokol-shdc (https://github.com/floooh/sokol-tools)
|
||||
|
||||
Cmdline:
|
||||
sokol-shdc --input source\basic.glsl --output source\basic.glsl.h --slang glsl430:hlsl5:metal_macos
|
||||
|
||||
Overview:
|
||||
=========
|
||||
Shader program: 'basic':
|
||||
Get shader desc: basic_shader_desc(sg_query_backend());
|
||||
Vertex Shader: vs
|
||||
Fragment Shader: fs
|
||||
Attributes:
|
||||
ATTR_basic_pos => 0
|
||||
ATTR_basic_vcolor => 1
|
||||
Bindings:
|
||||
Uniform block 'UBO':
|
||||
C struct: UBO_t
|
||||
Bind slot: UB_UBO => 0
|
||||
*/
|
||||
#if !defined(SOKOL_GFX_INCLUDED)
|
||||
#error "Please include sokol_gfx.h before basic.glsl.h"
|
||||
#endif
|
||||
#if !defined(SOKOL_SHDC_ALIGN)
|
||||
#if defined(_MSC_VER)
|
||||
#define SOKOL_SHDC_ALIGN(a) __declspec(align(a))
|
||||
#else
|
||||
#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a)))
|
||||
#endif
|
||||
#endif
|
||||
#define ATTR_basic_pos (0)
|
||||
#define ATTR_basic_vcolor (1)
|
||||
#define UB_UBO (0)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct UBO_t {
|
||||
float model[16];
|
||||
float view[16];
|
||||
float proj[16];
|
||||
} UBO_t;
|
||||
#pragma pack(pop)
|
||||
/*
|
||||
#version 430
|
||||
|
||||
uniform vec4 UBO[12];
|
||||
layout(location = 0) out vec4 color;
|
||||
layout(location = 1) in vec4 vcolor;
|
||||
layout(location = 0) in vec4 pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = vcolor;
|
||||
gl_Position = ((mat4(UBO[0], UBO[1], UBO[2], UBO[3]) * mat4(UBO[4], UBO[5], UBO[6], UBO[7])) * mat4(UBO[8], UBO[9], UBO[10], UBO[11])) * vec4(pos.xyz, 1.0);
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t vs_source_glsl430[344] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e,
|
||||
0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x55,0x42,0x4f,0x5b,0x31,
|
||||
0x32,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,
|
||||
0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,
|
||||
0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,
|
||||
0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,
|
||||
0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
|
||||
0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x6f,0x73,0x3b,0x0a,
|
||||
0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,
|
||||
0x6f,0x6e,0x20,0x3d,0x20,0x28,0x28,0x6d,0x61,0x74,0x34,0x28,0x55,0x42,0x4f,0x5b,
|
||||
0x30,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x31,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,
|
||||
0x32,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x6d,0x61,
|
||||
0x74,0x34,0x28,0x55,0x42,0x4f,0x5b,0x34,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x35,
|
||||
0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x36,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x37,
|
||||
0x5d,0x29,0x29,0x20,0x2a,0x20,0x6d,0x61,0x74,0x34,0x28,0x55,0x42,0x4f,0x5b,0x38,
|
||||
0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x39,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x31,
|
||||
0x30,0x5d,0x2c,0x20,0x55,0x42,0x4f,0x5b,0x31,0x31,0x5d,0x29,0x29,0x20,0x2a,0x20,
|
||||
0x76,0x65,0x63,0x34,0x28,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,
|
||||
0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#version 430
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
layout(location = 0) in vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_color = color;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t fs_source_glsl430[135] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61,
|
||||
0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
|
||||
0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,
|
||||
0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,
|
||||
0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,
|
||||
0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,
|
||||
0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
cbuffer UBO : register(b0)
|
||||
{
|
||||
row_major float4x4 ubo_model : packoffset(c0);
|
||||
row_major float4x4 ubo_view : packoffset(c4);
|
||||
row_major float4x4 ubo_proj : packoffset(c8);
|
||||
};
|
||||
|
||||
|
||||
static float4 gl_Position;
|
||||
static float4 color;
|
||||
static float4 vcolor;
|
||||
static float4 pos;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float4 pos : TEXCOORD0;
|
||||
float4 vcolor : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 color : TEXCOORD0;
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
void vert_main()
|
||||
{
|
||||
color = vcolor;
|
||||
gl_Position = mul(float4(pos.xyz, 1.0f), mul(ubo_proj, mul(ubo_view, ubo_model)));
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
vcolor = stage_input.vcolor;
|
||||
pos = stage_input.pos;
|
||||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.color = color;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
static const uint8_t vs_source_hlsl5[869] = {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x55,0x42,0x4f,0x20,0x3a,0x20,0x72,0x65,
|
||||
0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x78,0x34,0x20,0x75,0x62,0x6f,0x5f,0x6d,0x6f,0x64,0x65,0x6c,0x20,0x3a,0x20,
|
||||
0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x75,0x62,0x6f,0x5f,0x76,0x69,0x65,0x77,0x20,
|
||||
0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x75,0x62,0x6f,0x5f,0x70,0x72,0x6f,
|
||||
0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,
|
||||
0x38,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,
|
||||
0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,
|
||||
0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,
|
||||
0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,
|
||||
0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,
|
||||
0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x20,0x76,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,
|
||||
0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,
|
||||
0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,
|
||||
0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,
|
||||
0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,
|
||||
0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,
|
||||
0x76,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x28,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,
|
||||
0x30,0x66,0x29,0x2c,0x20,0x6d,0x75,0x6c,0x28,0x75,0x62,0x6f,0x5f,0x70,0x72,0x6f,
|
||||
0x6a,0x2c,0x20,0x6d,0x75,0x6c,0x28,0x75,0x62,0x6f,0x5f,0x76,0x69,0x65,0x77,0x2c,
|
||||
0x20,0x75,0x62,0x6f,0x5f,0x6d,0x6f,0x64,0x65,0x6c,0x29,0x29,0x29,0x3b,0x0a,0x7d,
|
||||
0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,
|
||||
0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,
|
||||
0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,
|
||||
0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x70,0x75,0x74,0x2e,0x76,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,
|
||||
0x74,0x2e,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,
|
||||
0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,
|
||||
0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,
|
||||
0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,
|
||||
0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,
|
||||
0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,
|
||||
0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,
|
||||
0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
static float4 frag_color;
|
||||
static float4 color;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float4 color : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float4 frag_color : SV_Target0;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
frag_color = color;
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
color = stage_input.color;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.frag_color = frag_color;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
static const uint8_t fs_source_hlsl5[435] = {
|
||||
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,
|
||||
0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,
|
||||
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
|
||||
0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,
|
||||
0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,
|
||||
0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,
|
||||
0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,
|
||||
0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,
|
||||
0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,
|
||||
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
|
||||
0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
|
||||
0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,
|
||||
0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,
|
||||
0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,
|
||||
0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x66,0x72,
|
||||
0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x72,0x61,0x67,0x5f,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,
|
||||
0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,
|
||||
0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 model;
|
||||
float4x4 view;
|
||||
float4x4 proj;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 color [[user(locn0)]];
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 pos [[attribute(0)]];
|
||||
float4 vcolor [[attribute(1)]];
|
||||
};
|
||||
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant UBO& ubo [[buffer(0)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.color = in.vcolor;
|
||||
out.gl_Position = ((ubo.model * ubo.view) * ubo.proj) * float4(in.pos.xyz, 1.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t vs_source_metal_macos[572] = {
|
||||
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
|
||||
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
|
||||
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
|
||||
0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
|
||||
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x55,
|
||||
0x42,0x4f,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,
|
||||
0x34,0x20,0x6d,0x6f,0x64,0x65,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,
|
||||
0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
|
||||
0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,
|
||||
0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,
|
||||
0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x6f,
|
||||
0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,
|
||||
0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,
|
||||
0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,
|
||||
0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,
|
||||
0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,
|
||||
0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,
|
||||
0x73,0x74,0x61,0x6e,0x74,0x20,0x55,0x42,0x4f,0x26,0x20,0x75,0x62,0x6f,0x20,0x5b,
|
||||
0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,
|
||||
0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,
|
||||
0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x28,0x28,0x75,0x62,0x6f,0x2e,0x6d,
|
||||
0x6f,0x64,0x65,0x6c,0x20,0x2a,0x20,0x75,0x62,0x6f,0x2e,0x76,0x69,0x65,0x77,0x29,
|
||||
0x20,0x2a,0x20,0x75,0x62,0x6f,0x2e,0x70,0x72,0x6f,0x6a,0x29,0x20,0x2a,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,
|
||||
0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,
|
||||
0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 frag_color [[color(0)]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float4 color [[user(locn0)]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(main0_in in [[stage_in]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.frag_color = in.color;
|
||||
return out;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t fs_source_metal_macos[315] = {
|
||||
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
|
||||
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
|
||||
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
|
||||
0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
|
||||
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,
|
||||
0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,
|
||||
0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
|
||||
0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
|
||||
0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,
|
||||
0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,
|
||||
0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,
|
||||
0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,
|
||||
0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,
|
||||
0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,
|
||||
0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x69,0x6e,0x2e,
|
||||
0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,
|
||||
0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
static inline const sg_shader_desc* basic_shader_desc(sg_backend backend) {
|
||||
if (backend == SG_BACKEND_GLCORE) {
|
||||
static sg_shader_desc desc;
|
||||
static bool valid;
|
||||
if (!valid) {
|
||||
valid = true;
|
||||
desc.vertex_func.source = (const char*)vs_source_glsl430;
|
||||
desc.vertex_func.entry = "main";
|
||||
desc.fragment_func.source = (const char*)fs_source_glsl430;
|
||||
desc.fragment_func.entry = "main";
|
||||
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
|
||||
desc.attrs[0].glsl_name = "pos";
|
||||
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
|
||||
desc.attrs[1].glsl_name = "vcolor";
|
||||
desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 192;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 12;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "UBO";
|
||||
desc.label = "basic_shader";
|
||||
}
|
||||
return &desc;
|
||||
}
|
||||
if (backend == SG_BACKEND_D3D11) {
|
||||
static sg_shader_desc desc;
|
||||
static bool valid;
|
||||
if (!valid) {
|
||||
valid = true;
|
||||
desc.vertex_func.source = (const char*)vs_source_hlsl5;
|
||||
desc.vertex_func.d3d11_target = "vs_5_0";
|
||||
desc.vertex_func.entry = "main";
|
||||
desc.fragment_func.source = (const char*)fs_source_hlsl5;
|
||||
desc.fragment_func.d3d11_target = "ps_5_0";
|
||||
desc.fragment_func.entry = "main";
|
||||
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
|
||||
desc.attrs[0].hlsl_sem_name = "TEXCOORD";
|
||||
desc.attrs[0].hlsl_sem_index = 0;
|
||||
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
|
||||
desc.attrs[1].hlsl_sem_name = "TEXCOORD";
|
||||
desc.attrs[1].hlsl_sem_index = 1;
|
||||
desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 192;
|
||||
desc.uniform_blocks[0].hlsl_register_b_n = 0;
|
||||
desc.label = "basic_shader";
|
||||
}
|
||||
return &desc;
|
||||
}
|
||||
if (backend == SG_BACKEND_METAL_MACOS) {
|
||||
static sg_shader_desc desc;
|
||||
static bool valid;
|
||||
if (!valid) {
|
||||
valid = true;
|
||||
desc.vertex_func.source = (const char*)vs_source_metal_macos;
|
||||
desc.vertex_func.entry = "main0";
|
||||
desc.fragment_func.source = (const char*)fs_source_metal_macos;
|
||||
desc.fragment_func.entry = "main0";
|
||||
desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT;
|
||||
desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT;
|
||||
desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 192;
|
||||
desc.uniform_blocks[0].msl_buffer_n = 0;
|
||||
desc.label = "basic_shader";
|
||||
}
|
||||
return &desc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
166
source/main.c
166
source/main.c
|
|
@ -24,9 +24,26 @@
|
|||
|
||||
#include "base.c"
|
||||
#include "arena.c"
|
||||
#include "math.c"
|
||||
|
||||
#include "basic.glsl.h"
|
||||
|
||||
typedef struct {
|
||||
Matrix model;
|
||||
Matrix view;
|
||||
Matrix proj;
|
||||
} UBO;
|
||||
|
||||
|
||||
sg_pass_action pass_action;
|
||||
sg_bindings g_bind;
|
||||
sg_pipeline g_pipeline;
|
||||
|
||||
s64 g_frame = 0;
|
||||
UBO g_ubo;
|
||||
Matrix g_proj;
|
||||
|
||||
Vec3 g_camera;
|
||||
|
||||
static void
|
||||
init(void) {
|
||||
|
|
@ -39,6 +56,56 @@ init(void) {
|
|||
.logger.func = slog_func,
|
||||
});
|
||||
|
||||
g_proj = make_proj_matrix(90, 1280, 720, 0.01, 100.0);
|
||||
g_camera = (Vec3){0, 0, -1.0};
|
||||
|
||||
float vertices[] = {
|
||||
-0.5, 0.5, -0.5, 1.0, 1.0, 1.0, 1.0,
|
||||
-0.5, -0.5, -0.5, 1.0, 0.0, 1.0, 1.0,
|
||||
0.5, 0.5, -0.5, 0.0, 0.0, 1.0, 1.0,
|
||||
0.5, -0.5, -0.5, 1.0, 0.0, 1.0, 1.0,
|
||||
|
||||
-0.5, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0,
|
||||
-0.5, -0.5, 0.5, 1.0, 1.0, 0.0, 1.0,
|
||||
0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0,
|
||||
0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0
|
||||
};
|
||||
|
||||
u32 indices[] = {
|
||||
0, 2, 1, 1, 2, 3, // back
|
||||
0, 1, 4, 4, 1, 5, // left
|
||||
3, 2, 6, 6, 7, 3, // right
|
||||
2, 0, 6, 6, 0, 4, // top
|
||||
1, 3, 7, 7, 5, 1, // bot
|
||||
4, 5, 6, 6, 5, 7, // front
|
||||
};
|
||||
|
||||
g_bind.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||
.usage = {.dynamic_update = true},
|
||||
.size = 1024,
|
||||
.label = "cube vertices",
|
||||
});
|
||||
g_bind.index_buffer = sg_make_buffer(&(sg_buffer_desc){
|
||||
.data = SG_RANGE(indices),
|
||||
.usage = {.index_buffer = true},
|
||||
.label = "cube indices",
|
||||
});
|
||||
|
||||
sg_shader shader = sg_make_shader(basic_shader_desc(sg_query_backend()));
|
||||
|
||||
g_pipeline = sg_make_pipeline(&(sg_pipeline_desc){
|
||||
.shader = shader,
|
||||
.layout = {
|
||||
.attrs = {
|
||||
[ATTR_basic_pos].format = SG_VERTEXFORMAT_FLOAT3,
|
||||
[ATTR_basic_vcolor].format = SG_VERTEXFORMAT_FLOAT4,
|
||||
},
|
||||
},
|
||||
.cull_mode = SG_CULLMODE_BACK,
|
||||
.index_type = SG_INDEXTYPE_UINT32,
|
||||
.label = "cube pipeline",
|
||||
});
|
||||
|
||||
pass_action = (sg_pass_action) {
|
||||
.colors[0] = {
|
||||
.load_action = SG_LOADACTION_CLEAR,
|
||||
|
|
@ -56,53 +123,6 @@ init(void) {
|
|||
[5] = sdtx_font_oric(),
|
||||
},
|
||||
});
|
||||
|
||||
// c23 tests
|
||||
capture auto x = 0;
|
||||
auto inc = persist(^{
|
||||
x += 1;
|
||||
});
|
||||
|
||||
printf("x = %d (before)\n", x);
|
||||
for (uword i = 0; i < 10; i += 1) {
|
||||
inc();
|
||||
}
|
||||
printf("x = %d (after)\n", x);
|
||||
|
||||
auto arena = Logger(Linear(1024 * 1024));
|
||||
scope_exit { arena_release(arena); };
|
||||
|
||||
sword* a = arena_new(arena, sword);
|
||||
sword* b = arena_new(arena, sword);
|
||||
|
||||
{
|
||||
auto region = Region(arena);
|
||||
scope_exit { arena_reset(region); };
|
||||
|
||||
arena_make(region, 10, sword);
|
||||
arena_make(region, 10, f32);
|
||||
arena_make(region, 10, bool);
|
||||
}
|
||||
|
||||
sword* c = arena_new(arena, sword);
|
||||
|
||||
*a = 1024;
|
||||
*b = 2048;
|
||||
*c = 4096;
|
||||
|
||||
printf("%d (%p)\n", cast(int, *a), a);
|
||||
printf("%d (%p)\n", cast(int, *b), b);
|
||||
printf("%d (%p)\n", cast(int, *c), c);
|
||||
|
||||
arena_reset(arena);
|
||||
|
||||
c = arena_new(arena, sword);
|
||||
b = arena_new(arena, sword);
|
||||
a = arena_new(arena, sword);
|
||||
|
||||
printf("%d (%p)\n", cast(int, *a), a);
|
||||
printf("%d (%p)\n", cast(int, *b), b);
|
||||
printf("%d (%p)\n", cast(int, *c), c);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -122,10 +142,60 @@ frame(void) {
|
|||
sdtx_pos(1, 1);
|
||||
sdtx_color3b(0, 0xFF, 0);
|
||||
sdtx_puts("press escape to quit");
|
||||
|
||||
sdtx_draw();
|
||||
|
||||
float vertices[] = {
|
||||
-0.5, 0.5, -0.5, 1.0, 1.0, 1.0, 1.0,
|
||||
-0.5, -0.5, -0.5, 1.0, 0.0, 1.0, 1.0,
|
||||
0.5, 0.5, -0.5, 0.0, 1.0, 1.0, 1.0,
|
||||
0.5, -0.5, -0.5, 0.0, 0.0, 1.0, 1.0,
|
||||
|
||||
-0.5, 0.5, 0.5, 1.0, 1.0, 0.0, 1.0,
|
||||
-0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 1.0,
|
||||
0.5, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
|
||||
0.5, -0.5, 0.5, 0.0, 0.0, 0.0, 1.0
|
||||
};
|
||||
|
||||
// get angle from frame number
|
||||
// wrap to angle
|
||||
s64 rate = 333;
|
||||
s64 wframe = g_frame;
|
||||
if(wframe >= TAU32*rate)
|
||||
wframe -= TAU32*rate;
|
||||
float angle = (f32)wframe/rate;
|
||||
|
||||
Matrix rot = make_rotation((Vec3){0.0, 1.0, 0.0}, angle);
|
||||
Vec3 p;
|
||||
for(int i = 0;
|
||||
i < 8;
|
||||
++i) {
|
||||
int vertex = i*7;
|
||||
p = (Vec3){vertices[vertex + 0], vertices[vertex + 1], vertices[vertex + 2]};
|
||||
p = m4v3_mul(rot, p);
|
||||
vertices[vertex + 0] = p.x;
|
||||
vertices[vertex + 1] = p.y;
|
||||
vertices[vertex + 2] = p.z;
|
||||
}
|
||||
|
||||
sg_update_buffer(g_bind.vertex_buffers[0], &SG_RANGE(vertices));
|
||||
|
||||
sg_apply_pipeline(g_pipeline);
|
||||
sg_apply_bindings(&g_bind);
|
||||
|
||||
Matrix model = make_translation((Vec3){0, 0, 0});
|
||||
Matrix lookat = make_lookat(g_camera, (Vec3){0, 0, 0}, (Vec3){0, 1, 0});
|
||||
|
||||
g_ubo.model = model;
|
||||
g_ubo.view = lookat;
|
||||
g_ubo.proj = g_proj;
|
||||
sg_apply_uniforms(UB_UBO, &SG_RANGE(g_ubo));
|
||||
|
||||
sg_draw(0, 36, 1);
|
||||
|
||||
sg_end_pass();
|
||||
sg_commit();
|
||||
|
||||
g_frame += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
202
source/math.c
Normal file
202
source/math.c
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
#if !defined(MATH)
|
||||
#define MATH
|
||||
|
||||
#import <math.h>
|
||||
|
||||
#define PI32 3.141592653589
|
||||
#define TAU32 6.28318530718
|
||||
|
||||
typedef struct {
|
||||
float _00, _01, _02, _03;
|
||||
float _10, _11, _12, _13;
|
||||
float _20, _21, _22, _23;
|
||||
float _30, _31, _32, _33;
|
||||
} Matrix;
|
||||
|
||||
typedef struct {
|
||||
float x,y,z;
|
||||
} Vec3;
|
||||
|
||||
typedef struct {
|
||||
float x,y,z,w;
|
||||
} Vec4;
|
||||
|
||||
Matrix mat_identity = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};
|
||||
|
||||
Matrix
|
||||
mat_scale(f32 amnt) {
|
||||
Matrix r = {0};
|
||||
r._00 = amnt;
|
||||
r._11 = amnt;
|
||||
r._22 = amnt;
|
||||
r._33 = amnt;
|
||||
return r;
|
||||
}
|
||||
|
||||
Matrix
|
||||
make_proj_matrix(f32 fov, int width, int height, f32 near_plane, f32 far_plane) {
|
||||
Matrix r = {0};
|
||||
|
||||
bool depth_01 = false;
|
||||
|
||||
f32 aspect = (f32)height/(f32)width;
|
||||
|
||||
// Y up, X right, -Z forward
|
||||
f32 fov_part = 1.0/tan(fov*0.5*PI32/180.0);
|
||||
f32 denom = far_plane - near_plane;
|
||||
r._00 = fov_part;
|
||||
r._11 = fov_part/aspect;
|
||||
r._22 = (far_plane + near_plane)/denom;
|
||||
r._23 = 2.0*far_plane*near_plane/denom;
|
||||
r._32 = 1.0;
|
||||
r._33 = 1.0;
|
||||
if(depth_01) {
|
||||
// VULKAN?
|
||||
// Makes depth range from 0 to 1
|
||||
// To map -1,1 depth range to 0,1 we transform z as follows: z' = z * 0.5 + 0.5
|
||||
r._22 = r._22 * 0.5 + r._32 * 0.5;
|
||||
r._23 = r._23 * 0.5 + r._33 * 0.5;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Matrix
|
||||
make_translation(Vec3 v) {
|
||||
Matrix r;
|
||||
r = mat_identity;
|
||||
r._03 = v.x;
|
||||
r._13 = v.y;
|
||||
r._23 = v.z;
|
||||
return r;
|
||||
}
|
||||
|
||||
Vec3
|
||||
v3_normalize(Vec3 v) {
|
||||
f32 inv_denom = 1.0/sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
v.x *= inv_denom;
|
||||
v.y *= inv_denom;
|
||||
v.z *= inv_denom;
|
||||
return v;
|
||||
}
|
||||
|
||||
Matrix
|
||||
make_rotation(Vec3 axis, f32 angle) {
|
||||
Matrix r = mat_identity;
|
||||
Vec3 a = v3_normalize(axis);
|
||||
f32 sin_theta = sin(angle);
|
||||
f32 cos_theta = cos(angle);
|
||||
f32 inv_cos = 1.0 - cos_theta;
|
||||
|
||||
// Contributors to vector's X
|
||||
r._00 = (a.x*a.x*inv_cos) + cos_theta;
|
||||
r._01 = (a.x*a.y*inv_cos) + (a.z*sin_theta);
|
||||
r._02 = (a.x*a.z*inv_cos) - (a.y*sin_theta);
|
||||
|
||||
// Contributors to vector's Y
|
||||
r._10 = (a.y*a.x*inv_cos) - (a.z*sin_theta);
|
||||
r._11 = (a.y*a.y*inv_cos) + cos_theta;
|
||||
r._12 = (a.y*a.z*inv_cos) + (a.x*sin_theta);
|
||||
|
||||
// Contributors to vector's Z
|
||||
r._20 = (a.z*a.x*inv_cos) + (a.y*sin_theta);
|
||||
r._21 = (a.z*a.y*inv_cos) - (a.x*sin_theta);
|
||||
r._22 = (a.z*a.z*inv_cos) + cos_theta;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Matrix
|
||||
translate(Matrix from, Vec3 with) {
|
||||
Matrix r;
|
||||
r = from;
|
||||
r._03 += with.x*r._00 + with.y*r._01 + with.z*r._02;
|
||||
r._13 += with.x*r._10 + with.y*r._11 + with.z*r._12;
|
||||
r._23 += with.x*r._20 + with.y*r._21 + with.z*r._22;
|
||||
return r;
|
||||
}
|
||||
|
||||
Vec3
|
||||
cross(Vec3 a, Vec3 b) {
|
||||
Vec3 r;
|
||||
r.x = a.y*b.z - a.z*b.y;
|
||||
r.y = a.z*b.x - a.x*b.z;
|
||||
r.z = a.x*b.y - a.y*b.x;
|
||||
return r;
|
||||
}
|
||||
|
||||
Matrix
|
||||
make_lookat(Vec3 camera, Vec3 at, Vec3 up_vector) {
|
||||
Vec3 forward, right, up;
|
||||
Matrix look_at;
|
||||
// Z forward, Y up, X right
|
||||
forward.x = at.x - camera.x;
|
||||
forward.y = at.y - camera.y;
|
||||
forward.z = at.z - camera.z;
|
||||
forward = v3_normalize(forward);
|
||||
right = v3_normalize(cross(up_vector, forward)); // up_vector
|
||||
up = v3_normalize(cross(forward, right));
|
||||
memset(&look_at, 0x00, sizeof(Matrix)); // Todo: zero subroutine
|
||||
look_at._00 = right.x;
|
||||
look_at._01 = right.y;
|
||||
look_at._02 = right.z;
|
||||
look_at._10 = up.x;
|
||||
look_at._11 = up.y;
|
||||
look_at._12 = up.z;
|
||||
look_at._20 = forward.x;
|
||||
look_at._21 = forward.y;
|
||||
look_at._22 = forward.z;
|
||||
look_at._33 = 1;
|
||||
|
||||
camera.x = -camera.x;
|
||||
camera.y = -camera.y;
|
||||
camera.z = -camera.z;
|
||||
look_at = translate(look_at, camera);
|
||||
|
||||
return look_at;
|
||||
}
|
||||
|
||||
Matrix
|
||||
mat_mul(Matrix a, Matrix b) {
|
||||
Matrix r;
|
||||
r._00 = a._00*b._00 + a._01*b._10 + a._02*b._20 + a._03*b._30;
|
||||
r._01 = a._00*b._01 + a._01*b._11 + a._02*b._21 + a._03*b._31;
|
||||
r._02 = a._00*b._02 + a._01*b._12 + a._02*b._22 + a._03*b._32;
|
||||
r._03 = a._00*b._03 + a._01*b._13 + a._02*b._23 + a._03*b._33;
|
||||
r._10 = a._10*b._00 + a._11*b._10 + a._12*b._20 + a._13*b._30;
|
||||
r._11 = a._10*b._01 + a._11*b._11 + a._12*b._21 + a._13*b._31;
|
||||
r._12 = a._10*b._02 + a._11*b._12 + a._12*b._22 + a._13*b._32;
|
||||
r._13 = a._10*b._03 + a._11*b._13 + a._12*b._23 + a._13*b._33;
|
||||
r._20 = a._20*b._00 + a._21*b._10 + a._22*b._20 + a._23*b._30;
|
||||
r._21 = a._20*b._01 + a._21*b._11 + a._22*b._21 + a._23*b._31;
|
||||
r._22 = a._20*b._02 + a._21*b._12 + a._22*b._22 + a._23*b._32;
|
||||
r._23 = a._20*b._03 + a._21*b._13 + a._22*b._23 + a._23*b._33;
|
||||
r._30 = a._30*b._00 + a._31*b._10 + a._32*b._20 + a._33*b._30;
|
||||
r._31 = a._30*b._01 + a._31*b._11 + a._32*b._21 + a._33*b._31;
|
||||
r._32 = a._30*b._02 + a._31*b._12 + a._32*b._22 + a._33*b._32;
|
||||
r._33 = a._30*b._03 + a._31*b._13 + a._32*b._23 + a._33*b._33;
|
||||
return r;
|
||||
}
|
||||
|
||||
Vec3
|
||||
m4v3_mul(Matrix m, Vec3 v) {
|
||||
Vec3 result;
|
||||
result.x = m._00*v.x + m._01*v.y + m._02*v.z;
|
||||
result.y = m._10*v.x + m._11*v.y + m._12*v.z;
|
||||
result.z = m._20*v.x + m._21*v.y + m._22*v.z;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
transpose(Matrix *m) {
|
||||
#define SWAP(a, b) {f32 _t = a; a = b; b = _t;}
|
||||
SWAP(m->_01, m->_10);
|
||||
SWAP(m->_02, m->_20);
|
||||
SWAP(m->_03, m->_30);
|
||||
SWAP(m->_12, m->_21);
|
||||
SWAP(m->_13, m->_31);
|
||||
SWAP(m->_23, m->_32);
|
||||
#undef SWAP
|
||||
}
|
||||
|
||||
#endif
|
||||
BIN
thirdparty/sokol/sokol-shdc-darwin
vendored
Normal file
BIN
thirdparty/sokol/sokol-shdc-darwin
vendored
Normal file
Binary file not shown.
BIN
thirdparty/sokol/sokol-shdc-linux
vendored
Normal file
BIN
thirdparty/sokol/sokol-shdc-linux
vendored
Normal file
Binary file not shown.
BIN
thirdparty/sokol/sokol-shdc-windows.exe
vendored
Normal file
BIN
thirdparty/sokol/sokol-shdc-windows.exe
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue