-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9bc15a
commit 2543cc2
Showing
9 changed files
with
972 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(texture_arrays LANGUAGES C) | ||
|
||
add_executable(texture_arrays main.c) | ||
|
||
if (MSVC) | ||
add_compile_options(/W4) | ||
else() | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}/../ffi) | ||
include_directories(${CMAKE_SOURCE_DIR}/framework) | ||
include_directories(${DEP_GLFW_DIR}/include) | ||
|
||
if (WIN32) | ||
add_definitions(-DWGPU_TARGET_WINDOWS) | ||
set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll) | ||
elseif(UNIX AND NOT APPLE) | ||
add_definitions(-DWGPU_TARGET_LINUX_X11) | ||
set(OS_LIBRARIES "-lm -ldl") | ||
elseif(APPLE) | ||
add_definitions(-DWGPU_TARGET_MACOS) | ||
set(OS_LIBRARIES "-framework CoreFoundation -framework QuartzCore -framework Metal") | ||
endif() | ||
|
||
target_link_libraries(texture_arrays framework glfw ${WGPU_LIBRARY} ${OS_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
struct VertexInput { | ||
@location(0) position: vec2<f32>, | ||
@location(1) tex_coord: vec2<f32>, | ||
@location(2) index: i32, | ||
} | ||
|
||
struct VertexOutput { | ||
@builtin(position) position: vec4<f32>, | ||
@location(0) tex_coord: vec2<f32>, | ||
@location(1) index: i32, | ||
} | ||
|
||
@vertex | ||
fn vert_main(vertex: VertexInput) -> VertexOutput { | ||
var outval: VertexOutput; | ||
outval.position = vec4<f32>(vertex.position.x, vertex.position.y, 0.0, 1.0); | ||
outval.tex_coord = vertex.tex_coord; | ||
outval.index = vertex.index; | ||
return outval; | ||
} | ||
|
||
struct FragmentInput { | ||
@location(0) tex_coord: vec2<f32>, | ||
@location(1) index: i32, | ||
} | ||
|
||
@group(0) @binding(0) | ||
var texture_array_top: binding_array<texture_2d<f32>>; | ||
@group(0) @binding(1) | ||
var texture_array_bottom: binding_array<texture_2d<f32>>; | ||
@group(0) @binding(2) | ||
var sampler_array: binding_array<sampler>; | ||
|
||
struct Uniforms { | ||
index: u32, | ||
} | ||
|
||
@group(0) @binding(3) | ||
var<uniform> uniforms: Uniforms; | ||
|
||
@fragment | ||
fn uniform_main(fragment: FragmentInput) -> @location(0) vec4<f32> { | ||
var outval: vec3<f32>; | ||
if fragment.tex_coord.y <= 0.5 { | ||
outval = textureSampleLevel( | ||
texture_array_top[uniforms.index], | ||
sampler_array[uniforms.index], | ||
fragment.tex_coord, | ||
0.0 | ||
).rgb; | ||
} else { | ||
outval = textureSampleLevel( | ||
texture_array_bottom[uniforms.index], | ||
sampler_array[uniforms.index], | ||
fragment.tex_coord, | ||
0.0 | ||
).rgb; | ||
} | ||
|
||
return vec4<f32>(outval.x, outval.y, outval.z, 1.0); | ||
} |
Oops, something went wrong.