mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Strip unneeded semicolons from vendor library
This commit is contained in:
Vendored
+1387
-1387
File diff suppressed because it is too large
Load Diff
Vendored
+105
-105
@@ -19,27 +19,27 @@ Shader_Type :: enum i32 {
|
||||
|
||||
|
||||
@(private, thread_local)
|
||||
last_compile_error_message: []byte;
|
||||
last_compile_error_message: []byte
|
||||
@(private, thread_local)
|
||||
last_link_error_message: []byte;
|
||||
last_link_error_message: []byte
|
||||
|
||||
@(private, thread_local)
|
||||
last_compile_error_type: Shader_Type;
|
||||
last_compile_error_type: Shader_Type
|
||||
@(private, thread_local)
|
||||
last_link_error_type: Shader_Type;
|
||||
last_link_error_type: Shader_Type
|
||||
|
||||
get_last_error_messages :: proc() -> (compile_message: string, compile_type: Shader_Type, link_message: string, link_type: Shader_Type) {
|
||||
compile_message = string(last_compile_error_message[:max(0, len(last_compile_error_message)-1)]);
|
||||
compile_type = last_compile_error_type;
|
||||
link_message = string(last_link_error_message[:max(0, len(last_link_error_message)-1)]);
|
||||
link_type = last_link_error_type;
|
||||
return;
|
||||
compile_message = string(last_compile_error_message[:max(0, len(last_compile_error_message)-1)])
|
||||
compile_type = last_compile_error_type
|
||||
link_message = string(last_link_error_message[:max(0, len(last_link_error_message)-1)])
|
||||
link_type = last_link_error_type
|
||||
return
|
||||
}
|
||||
|
||||
get_last_error_message :: proc() -> (compile_message: string, compile_type: Shader_Type) {
|
||||
compile_message = string(last_compile_error_message[:max(0, len(last_compile_error_message)-1)]);
|
||||
compile_type = last_compile_error_type;
|
||||
return;
|
||||
compile_message = string(last_compile_error_message[:max(0, len(last_compile_error_message)-1)])
|
||||
compile_type = last_compile_error_type
|
||||
return
|
||||
}
|
||||
|
||||
// Shader checking and linking checking are identical
|
||||
@@ -55,32 +55,32 @@ when ODIN_DEBUG {
|
||||
log_func: proc "c" (u32, i32, ^i32, [^]u8, runtime.Source_Code_Location),
|
||||
loc := #caller_location,
|
||||
) -> (success: bool) {
|
||||
result, info_log_length: i32;
|
||||
iv_func(id, status, &result, loc);
|
||||
iv_func(id, INFO_LOG_LENGTH, &info_log_length, loc);
|
||||
result, info_log_length: i32
|
||||
iv_func(id, status, &result, loc)
|
||||
iv_func(id, INFO_LOG_LENGTH, &info_log_length, loc)
|
||||
|
||||
if result == 0 {
|
||||
if log_func == GetShaderInfoLog {
|
||||
delete(last_compile_error_message);
|
||||
last_compile_error_message = make([]byte, info_log_length);
|
||||
last_compile_error_type = type;
|
||||
delete(last_compile_error_message)
|
||||
last_compile_error_message = make([]byte, info_log_length)
|
||||
last_compile_error_type = type
|
||||
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_compile_error_message), loc);
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_compile_error_message), loc)
|
||||
//fmt.printf_err("Error in %v:\n%s", type, string(last_compile_error_message[0:len(last_compile_error_message)-1]));
|
||||
} else {
|
||||
|
||||
delete(last_link_error_message);
|
||||
last_link_error_message = make([]byte, info_log_length);
|
||||
last_compile_error_type = type;
|
||||
delete(last_link_error_message)
|
||||
last_link_error_message = make([]byte, info_log_length)
|
||||
last_compile_error_type = type
|
||||
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_link_error_message), loc);
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_link_error_message), loc)
|
||||
//fmt.printf_err("Error in %v:\n%s", type, string(last_link_error_message[0:len(last_link_error_message)-1]));
|
||||
}
|
||||
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
@private
|
||||
@@ -89,103 +89,103 @@ when ODIN_DEBUG {
|
||||
iv_func: proc "c" (u32, u32, [^]i32),
|
||||
log_func: proc "c" (u32, i32, ^i32, [^]u8),
|
||||
) -> (success: bool) {
|
||||
result, info_log_length: i32;
|
||||
iv_func(id, status, &result);
|
||||
iv_func(id, INFO_LOG_LENGTH, &info_log_length);
|
||||
result, info_log_length: i32
|
||||
iv_func(id, status, &result)
|
||||
iv_func(id, INFO_LOG_LENGTH, &info_log_length)
|
||||
|
||||
if result == 0 {
|
||||
if log_func == GetShaderInfoLog {
|
||||
delete(last_compile_error_message);
|
||||
last_compile_error_message = make([]u8, info_log_length);
|
||||
last_link_error_type = type;
|
||||
delete(last_compile_error_message)
|
||||
last_compile_error_message = make([]u8, info_log_length)
|
||||
last_link_error_type = type
|
||||
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_compile_error_message));
|
||||
fmt.eprintf("Error in %v:\n%s", type, string(last_compile_error_message[0:len(last_compile_error_message)-1]));
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_compile_error_message))
|
||||
fmt.eprintf("Error in %v:\n%s", type, string(last_compile_error_message[0:len(last_compile_error_message)-1]))
|
||||
} else {
|
||||
delete(last_link_error_message);
|
||||
last_link_error_message = make([]u8, info_log_length);
|
||||
last_link_error_type = type;
|
||||
delete(last_link_error_message)
|
||||
last_link_error_message = make([]u8, info_log_length)
|
||||
last_link_error_type = type
|
||||
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_link_error_message));
|
||||
fmt.eprintf("Error in %v:\n%s", type, string(last_link_error_message[0:len(last_link_error_message)-1]));
|
||||
log_func(id, i32(info_log_length), nil, raw_data(last_link_error_message))
|
||||
fmt.eprintf("Error in %v:\n%s", type, string(last_link_error_message[0:len(last_link_error_message)-1]))
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Compiling shaders are identical for any shader (vertex, geometry, fragment, tesselation, (maybe compute too))
|
||||
@private
|
||||
compile_shader_from_source :: proc(shader_data: string, shader_type: Shader_Type) -> (shader_id: u32, ok: bool) {
|
||||
shader_id = CreateShader(cast(u32)shader_type);
|
||||
length := i32(len(shader_data));
|
||||
shader_data_copy := cstring(raw_data(shader_data));
|
||||
ShaderSource(shader_id, 1, &shader_data_copy, &length);
|
||||
CompileShader(shader_id);
|
||||
shader_id = CreateShader(cast(u32)shader_type)
|
||||
length := i32(len(shader_data))
|
||||
shader_data_copy := cstring(raw_data(shader_data))
|
||||
ShaderSource(shader_id, 1, &shader_data_copy, &length)
|
||||
CompileShader(shader_id)
|
||||
|
||||
check_error(shader_id, shader_type, COMPILE_STATUS, GetShaderiv, GetShaderInfoLog) or_return;
|
||||
ok = true;
|
||||
return;
|
||||
check_error(shader_id, shader_type, COMPILE_STATUS, GetShaderiv, GetShaderInfoLog) or_return
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
// only used once, but I'd just make a subprocedure(?) for consistency
|
||||
@private
|
||||
create_and_link_program :: proc(shader_ids: []u32, binary_retrievable := false) -> (program_id: u32, ok: bool) {
|
||||
program_id = CreateProgram();
|
||||
program_id = CreateProgram()
|
||||
for id in shader_ids {
|
||||
AttachShader(program_id, id);
|
||||
AttachShader(program_id, id)
|
||||
}
|
||||
if binary_retrievable {
|
||||
ProgramParameteri(program_id, PROGRAM_BINARY_RETRIEVABLE_HINT, 1/*true*/);
|
||||
ProgramParameteri(program_id, PROGRAM_BINARY_RETRIEVABLE_HINT, 1/*true*/)
|
||||
}
|
||||
LinkProgram(program_id);
|
||||
LinkProgram(program_id)
|
||||
|
||||
check_error(program_id, Shader_Type.SHADER_LINK, LINK_STATUS, GetProgramiv, GetProgramInfoLog) or_return;
|
||||
ok = true;
|
||||
return;
|
||||
check_error(program_id, Shader_Type.SHADER_LINK, LINK_STATUS, GetProgramiv, GetProgramInfoLog) or_return
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
|
||||
load_compute_file :: proc(filename: string, binary_retrievable := false) -> (program_id: u32, ok: bool) {
|
||||
cs_data := os.read_entire_file(filename) or_return;
|
||||
defer delete(cs_data);
|
||||
cs_data := os.read_entire_file(filename) or_return
|
||||
defer delete(cs_data)
|
||||
|
||||
// Create the shaders
|
||||
compute_shader_id := compile_shader_from_source(string(cs_data), Shader_Type(COMPUTE_SHADER)) or_return;
|
||||
return create_and_link_program([]u32{compute_shader_id}, binary_retrievable);
|
||||
compute_shader_id := compile_shader_from_source(string(cs_data), Shader_Type(COMPUTE_SHADER)) or_return
|
||||
return create_and_link_program([]u32{compute_shader_id}, binary_retrievable)
|
||||
}
|
||||
|
||||
load_compute_source :: proc(cs_data: string, binary_retrievable := false) -> (program_id: u32, ok: bool) {
|
||||
// Create the shaders
|
||||
compute_shader_id := compile_shader_from_source(cs_data, Shader_Type(COMPUTE_SHADER)) or_return;
|
||||
return create_and_link_program([]u32{compute_shader_id}, binary_retrievable);
|
||||
compute_shader_id := compile_shader_from_source(cs_data, Shader_Type(COMPUTE_SHADER)) or_return
|
||||
return create_and_link_program([]u32{compute_shader_id}, binary_retrievable)
|
||||
}
|
||||
|
||||
load_shaders_file :: proc(vs_filename, fs_filename: string, binary_retrievable := false) -> (program_id: u32, ok: bool) {
|
||||
vs_data := os.read_entire_file(vs_filename) or_return;
|
||||
defer delete(vs_data);
|
||||
vs_data := os.read_entire_file(vs_filename) or_return
|
||||
defer delete(vs_data)
|
||||
|
||||
fs_data := os.read_entire_file(fs_filename) or_return;
|
||||
defer delete(fs_data);
|
||||
fs_data := os.read_entire_file(fs_filename) or_return
|
||||
defer delete(fs_data)
|
||||
|
||||
return load_shaders_source(string(vs_data), string(fs_data), binary_retrievable);
|
||||
return load_shaders_source(string(vs_data), string(fs_data), binary_retrievable)
|
||||
}
|
||||
|
||||
load_shaders_source :: proc(vs_source, fs_source: string, binary_retrievable := false) -> (program_id: u32, ok: bool) {
|
||||
// actual function from here
|
||||
vertex_shader_id := compile_shader_from_source(vs_source, Shader_Type.VERTEX_SHADER) or_return;
|
||||
defer DeleteShader(vertex_shader_id);
|
||||
vertex_shader_id := compile_shader_from_source(vs_source, Shader_Type.VERTEX_SHADER) or_return
|
||||
defer DeleteShader(vertex_shader_id)
|
||||
|
||||
fragment_shader_id := compile_shader_from_source(fs_source, Shader_Type.FRAGMENT_SHADER) or_return;
|
||||
defer DeleteShader(fragment_shader_id);
|
||||
fragment_shader_id := compile_shader_from_source(fs_source, Shader_Type.FRAGMENT_SHADER) or_return
|
||||
defer DeleteShader(fragment_shader_id)
|
||||
|
||||
return create_and_link_program([]u32{vertex_shader_id, fragment_shader_id}, binary_retrievable);
|
||||
return create_and_link_program([]u32{vertex_shader_id, fragment_shader_id}, binary_retrievable)
|
||||
}
|
||||
|
||||
load_shaders :: proc{load_shaders_file};
|
||||
load_shaders :: proc{load_shaders_file}
|
||||
|
||||
|
||||
when ODIN_OS == "windows" {
|
||||
@@ -198,23 +198,23 @@ when ODIN_OS == "windows" {
|
||||
current_vertex_time, current_fragment_time: os.File_Time,
|
||||
updated: bool,
|
||||
) {
|
||||
current_vertex_time, _ = os.last_write_time_by_name(vertex_name);
|
||||
current_fragment_time, _ = os.last_write_time_by_name(fragment_name);
|
||||
old_program = program;
|
||||
current_vertex_time, _ = os.last_write_time_by_name(vertex_name)
|
||||
current_fragment_time, _ = os.last_write_time_by_name(fragment_name)
|
||||
old_program = program
|
||||
|
||||
if current_vertex_time != last_vertex_time || current_fragment_time != last_fragment_time {
|
||||
new_program, success := load_shaders(vertex_name, fragment_name);
|
||||
new_program, success := load_shaders(vertex_name, fragment_name)
|
||||
if success {
|
||||
DeleteProgram(old_program);
|
||||
old_program = new_program;
|
||||
fmt.println("Updated shaders");
|
||||
updated = true;
|
||||
DeleteProgram(old_program)
|
||||
old_program = new_program
|
||||
fmt.println("Updated shaders")
|
||||
updated = true
|
||||
} else {
|
||||
fmt.println("Failed to update shaders");
|
||||
fmt.println("Failed to update shaders")
|
||||
}
|
||||
}
|
||||
|
||||
return old_program, current_vertex_time, current_fragment_time, updated;
|
||||
return old_program, current_vertex_time, current_fragment_time, updated
|
||||
}
|
||||
|
||||
update_shader_if_changed_compute :: proc(
|
||||
@@ -226,22 +226,22 @@ when ODIN_OS == "windows" {
|
||||
current_compute_time: os.File_Time,
|
||||
updated: bool,
|
||||
) {
|
||||
current_compute_time, _ = os.last_write_time_by_name(compute_name);
|
||||
old_program = program;
|
||||
current_compute_time, _ = os.last_write_time_by_name(compute_name)
|
||||
old_program = program
|
||||
|
||||
if current_compute_time != last_compute_time {
|
||||
new_program, success := load_compute_file(compute_name);
|
||||
new_program, success := load_compute_file(compute_name)
|
||||
if success {
|
||||
DeleteProgram(old_program);
|
||||
old_program = new_program;
|
||||
fmt.println("Updated shaders");
|
||||
updated = true;
|
||||
DeleteProgram(old_program)
|
||||
old_program = new_program
|
||||
fmt.println("Updated shaders")
|
||||
updated = true
|
||||
} else {
|
||||
fmt.println("Failed to update shaders");
|
||||
fmt.println("Failed to update shaders")
|
||||
}
|
||||
}
|
||||
|
||||
return old_program, current_compute_time, updated;
|
||||
return old_program, current_compute_time, updated
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,34 +377,34 @@ Uniform_Info :: struct {
|
||||
name: string, // NOTE: This will need to be freed
|
||||
}
|
||||
|
||||
Uniforms :: map[string]Uniform_Info;
|
||||
Uniforms :: map[string]Uniform_Info
|
||||
|
||||
destroy_uniforms :: proc(u: Uniforms) {
|
||||
for _, v in u {
|
||||
delete(v.name);
|
||||
delete(v.name)
|
||||
}
|
||||
delete(u);
|
||||
delete(u)
|
||||
}
|
||||
|
||||
get_uniforms_from_program :: proc(program: u32) -> (uniforms: Uniforms) {
|
||||
uniform_count: i32;
|
||||
GetProgramiv(program, ACTIVE_UNIFORMS, &uniform_count);
|
||||
uniform_count: i32
|
||||
GetProgramiv(program, ACTIVE_UNIFORMS, &uniform_count)
|
||||
|
||||
if uniform_count > 0 {
|
||||
reserve(&uniforms, int(uniform_count));
|
||||
reserve(&uniforms, int(uniform_count))
|
||||
}
|
||||
|
||||
for i in 0..<uniform_count {
|
||||
uniform_info: Uniform_Info;
|
||||
uniform_info: Uniform_Info
|
||||
|
||||
length: i32;
|
||||
cname: [256]u8;
|
||||
GetActiveUniform(program, u32(i), 256, &length, &uniform_info.size, cast(^u32)&uniform_info.kind, &cname[0]);
|
||||
length: i32
|
||||
cname: [256]u8
|
||||
GetActiveUniform(program, u32(i), 256, &length, &uniform_info.size, cast(^u32)&uniform_info.kind, &cname[0])
|
||||
|
||||
uniform_info.location = GetUniformLocation(program, cstring(&cname[0]));
|
||||
uniform_info.name = strings.clone(string(cname[:length])); // @NOTE: These need to be freed
|
||||
uniforms[uniform_info.name] = uniform_info;
|
||||
uniform_info.location = GetUniformLocation(program, cstring(&cname[0]))
|
||||
uniform_info.name = strings.clone(string(cname[:length])) // @NOTE: These need to be freed
|
||||
uniforms[uniform_info.name] = uniform_info
|
||||
}
|
||||
|
||||
return uniforms;
|
||||
return uniforms
|
||||
}
|
||||
|
||||
Vendored
+1430
-1430
File diff suppressed because it is too large
Load Diff
Vendored
+17
-17
@@ -744,7 +744,7 @@ when !ODIN_DEBUG {
|
||||
import "core:fmt"
|
||||
|
||||
debug_helper :: #force_inline proc"c"(from_loc: runtime.Source_Code_Location, num_ret: int, args: ..any, loc := #caller_location) {
|
||||
context = runtime.default_context();
|
||||
context = runtime.default_context()
|
||||
|
||||
Error_Enum :: enum {
|
||||
NO_ERROR = NO_ERROR,
|
||||
@@ -756,50 +756,50 @@ when !ODIN_DEBUG {
|
||||
STACK_UNDERFLOW = STACK_UNDERFLOW,
|
||||
STACK_OVERFLOW = STACK_OVERFLOW,
|
||||
// TODO: What if the return enum is invalid?
|
||||
};
|
||||
}
|
||||
|
||||
// There can be multiple errors, so we're required to continuously call glGetError until there are no more errors
|
||||
for i := 0; /**/; i += 1 {
|
||||
err := cast(Error_Enum)impl_GetError();
|
||||
if err == .NO_ERROR do break;
|
||||
err := cast(Error_Enum)impl_GetError()
|
||||
if err == .NO_ERROR do break
|
||||
|
||||
fmt.printf("%d: glGetError() returned GL_%v\n", i, err);
|
||||
fmt.printf("%d: glGetError() returned GL_%v\n", i, err)
|
||||
|
||||
// add function call
|
||||
fmt.printf(" call: gl%s(", loc.procedure);
|
||||
fmt.printf(" call: gl%s(", loc.procedure)
|
||||
{
|
||||
// add input arguments
|
||||
for arg, i in args[num_ret:] {
|
||||
if i > 0 do fmt.printf(", ");
|
||||
if i > 0 do fmt.printf(", ")
|
||||
|
||||
if v, ok := arg.(u32); ok { // TODO: Assumes all u32 are GLenum (they're not, GLbitfield and GLuint are also mapped to u32), fix later by better typing
|
||||
if err == .INVALID_ENUM {
|
||||
fmt.printf("INVALID_ENUM=%d", v);
|
||||
fmt.printf("INVALID_ENUM=%d", v)
|
||||
} else {
|
||||
fmt.printf("GL_%v=%d", GL_Enum(v), v);
|
||||
fmt.printf("GL_%v=%d", GL_Enum(v), v)
|
||||
}
|
||||
} else {
|
||||
fmt.printf("%v", arg);
|
||||
fmt.printf("%v", arg)
|
||||
}
|
||||
}
|
||||
|
||||
// add return arguments
|
||||
if num_ret == 1 {
|
||||
fmt.printf(") -> %v \n", args[0]);
|
||||
fmt.printf(") -> %v \n", args[0])
|
||||
} else if num_ret > 1 {
|
||||
fmt.printf(") -> (");
|
||||
fmt.printf(") -> (")
|
||||
for arg, i in args[1:num_ret] {
|
||||
if i > 0 do fmt.printf(", ");
|
||||
fmt.printf("%v", arg);
|
||||
if i > 0 do fmt.printf(", ")
|
||||
fmt.printf("%v", arg)
|
||||
}
|
||||
fmt.printf(")\n");
|
||||
fmt.printf(")\n")
|
||||
} else {
|
||||
fmt.printf(")\n");
|
||||
fmt.printf(")\n")
|
||||
}
|
||||
}
|
||||
|
||||
// add location
|
||||
fmt.printf(" in: %s(%d:%d)\n", from_loc.file_path, from_loc.line, from_loc.column);
|
||||
fmt.printf(" in: %s(%d:%d)\n", from_loc.file_path, from_loc.line, from_loc.column)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user