-
Notifications
You must be signed in to change notification settings - Fork 0
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
shader restructure #16
Changes from all commits
23517fb
388dcea
7267bef
cd0ab27
0f15f5e
1984bc2
ebf466c
adbe181
2fcbf18
82d2f2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"enableCMake": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"CurrentProjectSetting": "x64-Debug" | ||
"CurrentProjectSetting": "x64-Release" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#version 330 core | ||
|
||
in vec4 v_Color; | ||
in vec2 v_TexCoord; | ||
in float v_TexIndex; | ||
in float v_TilingFactor; | ||
|
||
uniform sampler2D u_Textures[32]; | ||
|
||
out vec4 FragColor; | ||
|
||
void main() { | ||
vec4 texColor = v_Color; | ||
texColor *= texture(u_Textures[int(v_TexIndex)], v_TexCoord * v_TilingFactor); | ||
FragColor = texColor; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#version 330 core | ||
|
||
layout (location = 0) in vec3 a_Position; | ||
layout (location = 1) in vec4 a_Color; | ||
layout (location = 2) in vec2 a_TexCoord; | ||
layout (location = 3) in float a_TexIndex; | ||
layout (location = 4) in float a_TilingFactor; | ||
|
||
uniform mat4 u_ViewProjection; | ||
|
||
out vec4 v_Color; | ||
out vec2 v_TexCoord; | ||
out float v_TexIndex; | ||
out float v_TilingFactor; | ||
|
||
void main() { | ||
v_Color = a_Color; | ||
v_TexCoord = a_TexCoord; | ||
v_TexIndex = a_TexIndex; | ||
v_TilingFactor = a_TilingFactor; | ||
gl_Position = u_ViewProjection * vec4(a_Position, 1.0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
engine.trace("Starting init.lua execution") | ||
|
||
-- Create build directory structure first | ||
-- Create build directory structure | ||
local buildDir = "build/assets/scripts" | ||
local scriptDir = "sandbox/assets/scripts" | ||
|
||
|
@@ -29,7 +27,7 @@ local function copyScript(name) | |
end | ||
|
||
if not isPathSafe(name) then | ||
engine.error(string.format("Invalid script name (potential path traversal): %s", name)) | ||
engine.warn(string.format("Invalid script name (potential path traversal): %s", name)) | ||
return false | ||
end | ||
Comment on lines
+30
to
31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix string concatenation in error messages. The string.format calls have mismatched format specifiers and arguments. - engine.warn(string.format("Could not open source script ", sourcePath, ": ", sourceErr))
+ engine.warn(string.format("Could not open source script %s: %s", sourcePath, sourceErr))
- engine.warn(string.format("Failed to read from ", sourcePath))
+ engine.warn(string.format("Failed to read from %s", sourcePath))
- engine.warn(string.format("Failed to create destination file", destPath, ": ", destErr))
+ engine.warn(string.format("Failed to create destination file %s: %s", destPath, destErr))
- engine.warn(string.format("Failed to write to ", destPath))
+ engine.warn(string.format("Failed to write to %s", destPath)) Also applies to: 39-40, 56-59, 63-66, 70-73 🛠️ Refactor suggestion Reconsider using warnings for critical failures. Several critical operations are now using warnings instead of errors, which might hide important issues:
Also applies to: 39-40, 48-52, 56-59, 63-66, 70-73 |
||
|
||
|
@@ -38,7 +36,7 @@ local function copyScript(name) | |
|
||
local source, sourceErr = io.open(sourcePath, "rb") | ||
if not source then | ||
engine.error(string.format("Could not open source script ", sourcePath, ": ", sourceErr)) | ||
engine.warn(string.format("Could not open source script ", sourcePath, ": ", sourceErr)) | ||
return false | ||
end | ||
|
||
|
@@ -47,43 +45,42 @@ local function copyScript(name) | |
local size = source:seek("end") | ||
source:seek("set") | ||
if size > MAX_FILE_SIZE then | ||
engine.error(string.format("Script %s is too large (%d bytes > %d bytes limit)", | ||
engine.warn(string.format("Script %s is too large (%d bytes > %d bytes limit)", | ||
sourcePath, size, MAX_FILE_SIZE)) | ||
closeFiles(source) | ||
return false | ||
end | ||
|
||
local content = source:read("*all") | ||
if not content then | ||
engine.error(string.format("Failed to read from ", sourcePath)) | ||
engine.warn(string.format("Failed to read from ", sourcePath)) | ||
closeFiles(source) | ||
return false | ||
end | ||
|
||
local dest, destErr = io.open(destPath, "wb") | ||
if not dest then | ||
engine.error(string.format("Failed to create destination file", destPath, ": ", destErr)) | ||
engine.warn(string.format("Failed to create destination file", destPath, ": ", destErr)) | ||
closeFiles(source) | ||
return false | ||
end | ||
|
||
local success = dest:write(content) | ||
if not success then | ||
engine.error(string.format("Failed to write to ", destPath)) | ||
engine.warn(string.format("Failed to write to ", destPath)) | ||
closeFiles(source, dest) | ||
return false | ||
end | ||
|
||
closeFiles(source, dest) | ||
engine.trace(string.format("Successfully copied: ", name)) | ||
return true | ||
end | ||
|
||
-- Only copy scripts, don't execute them | ||
local scripts = { "main.lua", "engine.lua" } | ||
for _, script in ipairs(scripts) do | ||
if not copyScript(script) then | ||
engine.error("Failed to copy " .. script) | ||
engine.warn("Failed to copy " .. script) | ||
return | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicate include directory entry.
The same include path
${CMAKE_SOURCE_DIR}/build/vcpkg_installed/x86-windows/include
is added twice.Apply this diff to fix the redundancy:
target_include_directories(voxel-engine PUBLIC ${CMAKE_SOURCE_DIR}/src ${IMGUI_DIR} ${IMGUI_DIR}/backends ${CMAKE_SOURCE_DIR}/build/vcpkg_installed/x86-windows/include ${CMAKE_SOURCE_DIR}/external/stb_image/src ${CMAKE_SOURCE_DIR}/external/json ${CMAKE_SOURCE_DIR}/external/glad/include - ${CMAKE_SOURCE_DIR}/build/vcpkg_installed/x86-windows/include ${CMAKE_SOURCE_DIR}/external/sol2 )
Also applies to: 104-104