Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}

- name: Install Clang
run: sudo apt-get update && sudo apt-get install -y clang

# https://github.com/actions/runner/issues/504
# Removing the matchers won't keep the job from failing if there are errors,
# but will at least declutter pull request annotations (especially for warnings).
Expand Down Expand Up @@ -63,27 +66,11 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}

- name: Install Clang
run: sudo apt-get update && sudo apt-get install -y clang

- name: Hide duplicated warnings from lint job
run: echo "::remove-matcher owner=clippy::"

- name: Build and run macro tests
run: cargo test --package citro3d-macros

- name: Build and run lib and integration tests
uses: rust3ds/test-runner/run-tests@v1
with:
args: --tests --package citro3d

- name: Build and run doc tests
uses: rust3ds/test-runner/run-tests@v1
with:
args: --doc --package citro3d

- name: Upload citra logs and capture videos
uses: actions/upload-artifact@v4
if: success() || failure() # always run unless the workflow was cancelled
with:
name: citra-logs-${{ matrix.toolchain }}
path: |
target/armv6k-nintendo-3ds/debug/deps/*.txt
target/armv6k-nintendo-3ds/debug/deps/*.webm
3 changes: 3 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v4

- name: Install Clang
run: sudo apt-get update && sudo apt-get install -y clang

- name: Setup Pages
uses: actions/configure-pages@v3

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ rust-toolchain.toml

# Pica200 output files
*.shbin

# Tex3DS output files
*.t3d
9 changes: 9 additions & 0 deletions citro3d/examples/assets/create_texture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# Get the asset directory (containing this script)
ASSET_DIR=$(dirname $0)

echo "Kitten"
tex3ds -f auto-etc1 -z auto -o $ASSET_DIR/kitten.t3d $ASSET_DIR/kitten.png
echo "Skybox"
tex3ds -f auto-etc1 --skybox -z auto -o $ASSET_DIR/skybox.t3d $ASSET_DIR/skybox.png
Binary file added citro3d/examples/assets/kitten.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added citro3d/examples/assets/kitten.t3d
Binary file not shown.
Binary file added citro3d/examples/assets/skybox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added citro3d/examples/assets/skybox.t3d
Binary file not shown.
41 changes: 41 additions & 0 deletions citro3d/examples/assets/vshader_skybox.pica
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; Example PICA200 vertex shader

; Uniforms
.fvec projection[4], modelView[4]

; Constants
.constf myconst(0.0, 1.0, -1.0, -0.5)
.alias zeros myconst.xxxx ; Vector full of zeros
.alias ones myconst.yyyy ; Vector full of ones

; Outputs
.out outpos position
.out outtc0 texcoord0.st
.out - texcoord0w outtc0.p

; Inputs (defined as aliases for convenience)
.alias inpos v0

.proc main
; Force the w component of inpos to be 1.0
mov r0.xyz, inpos
mov r0.w, ones

; r1 = modelView * inpos
dp4 r1.x, modelView[0], r0
dp4 r1.y, modelView[1], r0
dp4 r1.z, modelView[2], r0
dp4 r1.w, modelView[3], r0

; outpos = projection * r1
dp4 outpos.x, projection[0], r1
dp4 outpos.y, projection[1], r1
dp4 outpos.z, projection[2], r1
dp4 outpos.w, projection[3], r1

; outtc0 = position
mov outtc0, inpos

; We're finished
end
.end
35 changes: 35 additions & 0 deletions citro3d/examples/assets/vshader_textured.pica
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
; Basic PICA200 vertex shader

; Uniforms
.fvec projection[4]

; Constants
.constf myconst(0.0, 1.0, -1.0, -0.5)
.constf zeros(0.0, 0.0, 0.0, 0.0)
.constf ones(1.0, 1.0, 1.0, 1.0)

; Outputs
.out outpos position
.out outtex texcoord0

; Inputs (defined as aliases for convenience)
.alias inpos v0
.alias intex v1

.proc main
; Force the w component of inpos to be 1.0
mov r0.xyz, inpos
mov r0.w, ones

; outpos = projectionMatrix * inpos
dp4 outpos.x, projection[0], r0
dp4 outpos.y, projection[1], r0
dp4 outpos.z, projection[2], r0
dp4 outpos.w, projection[3], r0

; outtex = intex
mov outtex, intex

; We're finished
end
.end
38 changes: 20 additions & 18 deletions citro3d/examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use citro3d::macros::include_shader;
use citro3d::math::{
AspectRatio, ClipPlanes, CoordinateOrientation, FVec3, Matrix4, Projection, StereoDisplacement,
};
use citro3d::render::{ClearFlags, RenderPass, Target};
use citro3d::render::{ClearFlags, Frame, ScreenTarget, Target};
use citro3d::{attrib, buffer, shader, texenv};
use ctru::prelude::*;
use ctru::services::gfx::{RawFrameBuffer, Screen, TopScreen3D};
Expand Down Expand Up @@ -143,52 +143,54 @@ fn main() {
];
let index_buffer = vbo_slice.index_buffer(indices).unwrap();

let stage0 = texenv::TexEnv::new()
.src(texenv::Mode::BOTH, texenv::Source::PrimaryColor, None, None)
.func(texenv::Mode::BOTH, texenv::CombineFunc::Replace);

while apt.main_loop() {
hid.scan_input();

if hid.keys_down().contains(KeyPad::START) {
break;
}

instance.render_frame_with(|mut pass| {
fn cast_lifetime_to_closure<'pass, T>(x: T) -> T
instance.render_frame_with(|mut frame| {
fn cast_lifetime_to_closure<'frame, T>(x: T) -> T
where
T: Fn(&mut RenderPass<'pass>, &'pass mut Target<'_>, &Matrix4),
T: Fn(&mut Frame<'frame>, &'frame mut ScreenTarget<'_>, &Matrix4),
{
x
}

let render_to = cast_lifetime_to_closure(|pass, target, projection| {
let render_to = cast_lifetime_to_closure(|frame, target, projection| {
target.clear(ClearFlags::ALL, CLEAR_COLOR, 0);

pass.select_render_target(target)
frame
.select_render_target(target)
.expect("failed to set render target");

pass.bind_vertex_uniform(projection_uniform_idx, projection * camera_transform);
frame.bind_vertex_uniform(projection_uniform_idx, projection * camera_transform);

pass.set_attr_info(&attr_info);
frame.set_attr_info(&attr_info);

pass.draw_elements(buffer::Primitive::Triangles, vbo_slice, &index_buffer);
frame.draw_elements(buffer::Primitive::Triangles, vbo_slice, &index_buffer);
});

pass.bind_program(&program);
frame.bind_program(&program);

let stage0 = texenv::Stage::new(0).unwrap();
pass.texenv(stage0)
.src(texenv::Mode::BOTH, texenv::Source::PrimaryColor, None, None)
.func(texenv::Mode::BOTH, texenv::CombineFunc::Replace);
frame.set_texenvs(&[stage0]);

let Projections {
left_eye,
right_eye,
center,
} = calculate_projections();

render_to(&mut pass, &mut top_left_target, &left_eye);
render_to(&mut pass, &mut top_right_target, &right_eye);
render_to(&mut pass, &mut bottom_target, &center);
render_to(&mut frame, &mut top_left_target, &left_eye);
render_to(&mut frame, &mut top_right_target, &right_eye);
render_to(&mut frame, &mut bottom_target, &center);

pass
frame
});
}
}
Expand Down
52 changes: 27 additions & 25 deletions citro3d/examples/fragment-light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use citro3d::{
color::Color,
light::{DistanceAttenuation, LightEnv, Lut, LutId, LutInput, Material, Spotlight},
math::{AspectRatio, ClipPlanes, FVec3, Matrix4, Projection, StereoDisplacement},
render::{ClearFlags, DepthFormat, RenderPass, Target},
render::{ClearFlags, DepthFormat, Frame, ScreenTarget, Target},
shader, texenv,
};
use citro3d_macros::include_shader;
Expand Down Expand Up @@ -340,58 +340,60 @@ fn main() {

let projection_uniform_idx = program.get_uniform("projection").unwrap();

let stage0 = texenv::TexEnv::new()
.src(
texenv::Mode::BOTH,
texenv::Source::FragmentPrimaryColor,
Some(texenv::Source::FragmentSecondaryColor),
None,
)
.func(texenv::Mode::BOTH, texenv::CombineFunc::Add);

while apt.main_loop() {
hid.scan_input();

if hid.keys_down().contains(KeyPad::START) {
break;
}

instance.render_frame_with(|mut pass| {
fn cast_lifetime_to_closure<'pass, T>(x: T) -> T
instance.render_frame_with(|mut frame| {
fn cast_lifetime_to_closure<'frame, T>(x: T) -> T
where
T: Fn(&mut RenderPass<'pass>, &'pass mut Target<'_>, &Matrix4),
T: Fn(&mut Frame<'frame>, &'frame mut ScreenTarget<'_>, &Matrix4),
{
x
}

let render_to = cast_lifetime_to_closure(|pass, target, projection| {
let render_to = cast_lifetime_to_closure(|frame, target, projection| {
target.clear(ClearFlags::ALL, 0, 0);
pass.select_render_target(target)
frame
.select_render_target(target)
.expect("failed to set render target");

pass.bind_vertex_uniform(projection_uniform_idx, projection);
pass.bind_vertex_uniform(model_idx, view);
frame.bind_vertex_uniform(projection_uniform_idx, projection);
frame.bind_vertex_uniform(model_idx, view);

pass.set_attr_info(&attr_info);
frame.set_attr_info(&attr_info);

pass.draw_arrays(buffer::Primitive::Triangles, vbo_data);
frame.draw_arrays(buffer::Primitive::Triangles, vbo_data);
});

pass.bind_program(&program);
pass.bind_light_env(Some(light_env.as_mut()));
frame.bind_program(&program);
frame.bind_light_env(Some(light_env.as_mut()));

let stage0 = texenv::Stage::new(0).unwrap();
pass.texenv(stage0)
.src(
texenv::Mode::BOTH,
texenv::Source::FragmentPrimaryColor,
Some(texenv::Source::FragmentSecondaryColor),
None,
)
.func(texenv::Mode::BOTH, texenv::CombineFunc::Add);
frame.set_texenvs(&[stage0]);

let Projections {
left_eye,
right_eye,
center,
} = calculate_projections();

render_to(&mut pass, &mut top_left_target, &left_eye);
render_to(&mut pass, &mut top_right_target, &right_eye);
render_to(&mut pass, &mut bottom_target, &center);
render_to(&mut frame, &mut top_left_target, &left_eye);
render_to(&mut frame, &mut top_right_target, &right_eye);
render_to(&mut frame, &mut bottom_target, &center);

pass
frame
});

// Rotate the modelView
Expand Down
Loading
Loading