From 484e971dd5e004721211815b97ba65328325e56e Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Wed, 11 May 2022 22:48:46 -0400 Subject: [PATCH] Add compiling example using -sys bindings Fix some more issues with bindings and add README --- Cargo.toml | 5 +- README.md | 11 + citro3d-sys/bindgen.sh | 14 +- citro3d-sys/src/bindings.rs | 919 ++++++++++++++++++++++++++- citro3d/Cargo.toml | 12 + citro3d/examples/assets/.gitignore | 1 + citro3d/examples/assets/vshader.pica | 36 ++ citro3d/examples/triangle.rs | 217 +++++++ citro3d/src/lib.rs | 8 + 9 files changed, 1214 insertions(+), 9 deletions(-) create mode 100644 README.md create mode 100644 citro3d/Cargo.toml create mode 100644 citro3d/examples/assets/.gitignore create mode 100644 citro3d/examples/assets/vshader.pica create mode 100644 citro3d/examples/triangle.rs create mode 100644 citro3d/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index cc6ef8e..e2d84ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,5 @@ [workspace] -members = ["citro3d-sys"] +members = ["citro3d-sys", "citro3d"] + +[patch."https://github.com/ian-h-chamberlain/citro3d-rs.git"] +citro3d-sys = { path = "citro3d-sys" } diff --git a/README.md b/README.md new file mode 100644 index 0000000..65371c2 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# citro3d-rs + +⚠️ WIP ⚠️ + +Bindings and safe wrapper to the [citro3d](https://github.com/devkitPro/citro3d) +library, to write homebrew graphical programs for the Nintendo 3DS. + +## Crates + +* `citro3d-sys` - C bindings to `libcitro3d` +* `citro3d` - safe Rust wrappers for `citro3d-sys` (WIP) diff --git a/citro3d-sys/bindgen.sh b/citro3d-sys/bindgen.sh index b28408b..2fb51c9 100755 --- a/citro3d-sys/bindgen.sh +++ b/citro3d-sys/bindgen.sh @@ -11,21 +11,23 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \ --no-prepend-enum-name \ --generate "functions,types,vars" \ --blocklist-type "u(8|16|32|64)" \ - --blocklist-type "__builtin_va_list" \ - --blocklist-type "__va_list" \ --opaque-type "GPU_.*" \ --opaque-type "GFX_.*" \ - --opaque-type "gfx.*_t" \ - --opaque-type "DVL.*" \ - --opaque-type "shader.*" \ --opaque-type "float24Uniform_s" \ --allowlist-type "C3D_.*" \ + --allowlist-type "DVLB_.*" \ + --allowlist-type "shader.*" \ + --allowlist-type "float24Uniform_s" \ --allowlist-function "C3D_.*" \ + --allowlist-function "shader.*" \ + --allowlist-function "DVLB_.*" \ + --allowlist-function "linear.*" \ --allowlist-var "C3D_.*" \ + --allowlist-type "GPU_.*" \ + --allowlist-type "GX_.*" \ --allowlist-function 'AttrInfo_(Init|AddLoader|AddFixed)' \ --allowlist-function 'BufInfo_(Init|Add)' \ --allowlist-function 'Mtx_.*' \ - --raw-line "use ctru_sys::*;" \ -- \ --target=arm-none-eabi \ --sysroot=$DEVKITARM/arm-none-eabi \ diff --git a/citro3d-sys/src/bindings.rs b/citro3d-sys/src/bindings.rs index 111c342..30364ca 100644 --- a/citro3d-sys/src/bindings.rs +++ b/citro3d-sys/src/bindings.rs @@ -1,7 +1,5 @@ /* automatically generated by rust-bindgen 0.59.2 */ -use ctru_sys::*; - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -88,8 +86,10 @@ pub const C3D_MTXSTACK_SIZE: u32 = 8; pub const C3D_FVUNIF_COUNT: u32 = 96; pub const C3D_IVUNIF_COUNT: u32 = 4; pub const C3D_DEFAULT_CMDBUF_SIZE: u32 = 262144; +pub type __int8_t = ::libc::c_schar; pub type __uint8_t = ::libc::c_uchar; pub type __uint16_t = ::libc::c_ushort; +pub type __int32_t = ::libc::c_int; pub type __uint32_t = ::libc::c_uint; pub type __uint64_t = ::libc::c_ulonglong; pub type size_t = ::libc::c_uint; @@ -97,6 +97,921 @@ pub type u8_ = u8; pub type u16_ = u16; pub type u32_ = u32; pub type u64_ = u64; +pub type s8 = i8; +pub type s32 = i32; +pub type Result = s32; +#[doc = "< Top screen"] +pub const GFX_TOP: gfxScreen_t = 0; +#[doc = "< Bottom screen"] +pub const GFX_BOTTOM: gfxScreen_t = 1; +#[doc = " Screen IDs."] +pub type gfxScreen_t = ::libc::c_uint; +#[doc = "< Left eye framebuffer"] +pub const GFX_LEFT: gfx3dSide_t = 0; +#[doc = "< Right eye framebuffer"] +pub const GFX_RIGHT: gfx3dSide_t = 1; +#[doc = " @brief Top screen framebuffer side."] +#[doc = ""] +#[doc = " This is only meaningful when stereoscopic 3D is enabled on the top screen."] +#[doc = " In any other case, use \\ref GFX_LEFT."] +pub type gfx3dSide_t = ::libc::c_uint; +extern "C" { + #[doc = " @brief Allocates a 0x80-byte aligned buffer."] + #[doc = " @param size Size of the buffer to allocate."] + #[doc = " @return The allocated buffer."] + pub fn linearAlloc(size: size_t) -> *mut ::libc::c_void; +} +extern "C" { + #[doc = " @brief Allocates a buffer aligned to the given size."] + #[doc = " @param size Size of the buffer to allocate."] + #[doc = " @param alignment Alignment to use."] + #[doc = " @return The allocated buffer."] + pub fn linearMemAlign(size: size_t, alignment: size_t) -> *mut ::libc::c_void; +} +extern "C" { + #[doc = " @brief Reallocates a buffer."] + #[doc = " Note: Not implemented yet."] + #[doc = " @param mem Buffer to reallocate."] + #[doc = " @param size Size of the buffer to allocate."] + #[doc = " @return The reallocated buffer."] + pub fn linearRealloc(mem: *mut ::libc::c_void, size: size_t) -> *mut ::libc::c_void; +} +extern "C" { + #[doc = " @brief Retrieves the allocated size of a buffer."] + #[doc = " @return The size of the buffer."] + pub fn linearGetSize(mem: *mut ::libc::c_void) -> size_t; +} +extern "C" { + #[doc = " @brief Frees a buffer."] + #[doc = " @param mem Buffer to free."] + pub fn linearFree(mem: *mut ::libc::c_void); +} +extern "C" { + #[doc = " @brief Gets the current linear free space."] + #[doc = " @return The current linear free space."] + pub fn linearSpaceFree() -> u32_; +} +#[doc = "< 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha"] +pub const GX_TRANSFER_FMT_RGBA8: GX_TRANSFER_FORMAT = 0; +#[doc = "< 8-bit Red + 8-bit Green + 8-bit Blue"] +pub const GX_TRANSFER_FMT_RGB8: GX_TRANSFER_FORMAT = 1; +#[doc = "< 5-bit Red + 6-bit Green + 5-bit Blue"] +pub const GX_TRANSFER_FMT_RGB565: GX_TRANSFER_FORMAT = 2; +#[doc = "< 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha"] +pub const GX_TRANSFER_FMT_RGB5A1: GX_TRANSFER_FORMAT = 3; +#[doc = "< 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha"] +pub const GX_TRANSFER_FMT_RGBA4: GX_TRANSFER_FORMAT = 4; +#[doc = " @brief Supported transfer pixel formats."] +#[doc = " @sa GSPGPU_FramebufferFormat"] +pub type GX_TRANSFER_FORMAT = ::libc::c_uint; +#[doc = "< No anti-aliasing"] +pub const GX_TRANSFER_SCALE_NO: GX_TRANSFER_SCALE = 0; +#[doc = "< 2x1 anti-aliasing"] +pub const GX_TRANSFER_SCALE_X: GX_TRANSFER_SCALE = 1; +#[doc = "< 2x2 anti-aliasing"] +pub const GX_TRANSFER_SCALE_XY: GX_TRANSFER_SCALE = 2; +#[doc = " @brief Anti-aliasing modes"] +#[doc = ""] +#[doc = " Please remember that the framebuffer is sideways."] +#[doc = " Hence if you activate 2x1 anti-aliasing the destination dimensions are w = 240*2 and h = 400"] +pub type GX_TRANSFER_SCALE = ::libc::c_uint; +#[doc = "< Trigger the PPF event"] +pub const GX_FILL_TRIGGER: GX_FILL_CONTROL = 1; +#[doc = "< Indicates if the memory fill is complete. You should not use it when requesting a transfer."] +pub const GX_FILL_FINISHED: GX_FILL_CONTROL = 2; +#[doc = "< The buffer has a 16 bit per pixel depth"] +pub const GX_FILL_16BIT_DEPTH: GX_FILL_CONTROL = 0; +#[doc = "< The buffer has a 24 bit per pixel depth"] +pub const GX_FILL_24BIT_DEPTH: GX_FILL_CONTROL = 256; +#[doc = "< The buffer has a 32 bit per pixel depth"] +pub const GX_FILL_32BIT_DEPTH: GX_FILL_CONTROL = 512; +#[doc = " GX transfer control flags"] +pub type GX_FILL_CONTROL = ::libc::c_uint; +#[doc = "< Nearest-neighbor interpolation."] +pub const GPU_NEAREST: GPU_TEXTURE_FILTER_PARAM = 0; +#[doc = "< Linear interpolation."] +pub const GPU_LINEAR: GPU_TEXTURE_FILTER_PARAM = 1; +#[doc = " Texture filters."] +pub type GPU_TEXTURE_FILTER_PARAM = ::libc::c_uint; +#[doc = "< Clamps to edge."] +pub const GPU_CLAMP_TO_EDGE: GPU_TEXTURE_WRAP_PARAM = 0; +#[doc = "< Clamps to border."] +pub const GPU_CLAMP_TO_BORDER: GPU_TEXTURE_WRAP_PARAM = 1; +#[doc = "< Repeats texture."] +pub const GPU_REPEAT: GPU_TEXTURE_WRAP_PARAM = 2; +#[doc = "< Repeats with mirrored texture."] +pub const GPU_MIRRORED_REPEAT: GPU_TEXTURE_WRAP_PARAM = 3; +#[doc = " Texture wrap modes."] +pub type GPU_TEXTURE_WRAP_PARAM = ::libc::c_uint; +#[doc = "< 2D texture"] +pub const GPU_TEX_2D: GPU_TEXTURE_MODE_PARAM = 0; +#[doc = "< Cube map"] +pub const GPU_TEX_CUBE_MAP: GPU_TEXTURE_MODE_PARAM = 1; +#[doc = "< 2D Shadow texture"] +pub const GPU_TEX_SHADOW_2D: GPU_TEXTURE_MODE_PARAM = 2; +#[doc = "< Projection texture"] +pub const GPU_TEX_PROJECTION: GPU_TEXTURE_MODE_PARAM = 3; +#[doc = "< Shadow cube map"] +pub const GPU_TEX_SHADOW_CUBE: GPU_TEXTURE_MODE_PARAM = 4; +#[doc = "< Disabled"] +pub const GPU_TEX_DISABLED: GPU_TEXTURE_MODE_PARAM = 5; +#[doc = " Texture modes."] +pub type GPU_TEXTURE_MODE_PARAM = ::libc::c_uint; +#[doc = "< Texture unit 0."] +pub const GPU_TEXUNIT0: GPU_TEXUNIT = 1; +#[doc = "< Texture unit 1."] +pub const GPU_TEXUNIT1: GPU_TEXUNIT = 2; +#[doc = "< Texture unit 2."] +pub const GPU_TEXUNIT2: GPU_TEXUNIT = 4; +#[doc = " Supported texture units."] +pub type GPU_TEXUNIT = ::libc::c_uint; +#[doc = "< 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha"] +pub const GPU_RGBA8: GPU_TEXCOLOR = 0; +#[doc = "< 8-bit Red + 8-bit Green + 8-bit Blue"] +pub const GPU_RGB8: GPU_TEXCOLOR = 1; +#[doc = "< 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha"] +pub const GPU_RGBA5551: GPU_TEXCOLOR = 2; +#[doc = "< 5-bit Red + 6-bit Green + 5-bit Blue"] +pub const GPU_RGB565: GPU_TEXCOLOR = 3; +#[doc = "< 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha"] +pub const GPU_RGBA4: GPU_TEXCOLOR = 4; +#[doc = "< 8-bit Luminance + 8-bit Alpha"] +pub const GPU_LA8: GPU_TEXCOLOR = 5; +#[doc = "< 8-bit Hi + 8-bit Lo"] +pub const GPU_HILO8: GPU_TEXCOLOR = 6; +#[doc = "< 8-bit Luminance"] +pub const GPU_L8: GPU_TEXCOLOR = 7; +#[doc = "< 8-bit Alpha"] +pub const GPU_A8: GPU_TEXCOLOR = 8; +#[doc = "< 4-bit Luminance + 4-bit Alpha"] +pub const GPU_LA4: GPU_TEXCOLOR = 9; +#[doc = "< 4-bit Luminance"] +pub const GPU_L4: GPU_TEXCOLOR = 10; +#[doc = "< 4-bit Alpha"] +pub const GPU_A4: GPU_TEXCOLOR = 11; +#[doc = "< ETC1 texture compression"] +pub const GPU_ETC1: GPU_TEXCOLOR = 12; +#[doc = "< ETC1 texture compression + 4-bit Alpha"] +pub const GPU_ETC1A4: GPU_TEXCOLOR = 13; +#[doc = " Supported texture formats."] +pub type GPU_TEXCOLOR = ::libc::c_uint; +#[doc = "< 2D face"] +pub const GPU_TEXFACE_2D: GPU_TEXFACE = 0; +#[doc = "< +X face"] +pub const GPU_POSITIVE_X: GPU_TEXFACE = 0; +#[doc = "< -X face"] +pub const GPU_NEGATIVE_X: GPU_TEXFACE = 1; +#[doc = "< +Y face"] +pub const GPU_POSITIVE_Y: GPU_TEXFACE = 2; +#[doc = "< -Y face"] +pub const GPU_NEGATIVE_Y: GPU_TEXFACE = 3; +#[doc = "< +Z face"] +pub const GPU_POSITIVE_Z: GPU_TEXFACE = 4; +#[doc = "< -Z face"] +pub const GPU_NEGATIVE_Z: GPU_TEXFACE = 5; +#[doc = " Texture faces."] +pub type GPU_TEXFACE = ::libc::c_uint; +#[doc = "< Clamp to zero."] +pub const GPU_PT_CLAMP_TO_ZERO: GPU_PROCTEX_CLAMP = 0; +#[doc = "< Clamp to edge."] +pub const GPU_PT_CLAMP_TO_EDGE: GPU_PROCTEX_CLAMP = 1; +#[doc = "< Symmetrical repeat."] +pub const GPU_PT_REPEAT: GPU_PROCTEX_CLAMP = 2; +#[doc = "< Mirrored repeat."] +pub const GPU_PT_MIRRORED_REPEAT: GPU_PROCTEX_CLAMP = 3; +#[doc = "< Pulse."] +pub const GPU_PT_PULSE: GPU_PROCTEX_CLAMP = 4; +#[doc = " Procedural texture clamp modes."] +pub type GPU_PROCTEX_CLAMP = ::libc::c_uint; +#[doc = "< U"] +pub const GPU_PT_U: GPU_PROCTEX_MAPFUNC = 0; +#[doc = "< U2"] +pub const GPU_PT_U2: GPU_PROCTEX_MAPFUNC = 1; +#[doc = "< V"] +pub const GPU_PT_V: GPU_PROCTEX_MAPFUNC = 2; +#[doc = "< V2"] +pub const GPU_PT_V2: GPU_PROCTEX_MAPFUNC = 3; +#[doc = "< U+V"] +pub const GPU_PT_ADD: GPU_PROCTEX_MAPFUNC = 4; +#[doc = "< U2+V2"] +pub const GPU_PT_ADD2: GPU_PROCTEX_MAPFUNC = 5; +#[doc = "< sqrt(U2+V2)"] +pub const GPU_PT_SQRT2: GPU_PROCTEX_MAPFUNC = 6; +#[doc = "< min"] +pub const GPU_PT_MIN: GPU_PROCTEX_MAPFUNC = 7; +#[doc = "< max"] +pub const GPU_PT_MAX: GPU_PROCTEX_MAPFUNC = 8; +#[doc = "< rmax"] +pub const GPU_PT_RMAX: GPU_PROCTEX_MAPFUNC = 9; +#[doc = " Procedural texture mapping functions."] +pub type GPU_PROCTEX_MAPFUNC = ::libc::c_uint; +#[doc = "< No shift."] +pub const GPU_PT_NONE: GPU_PROCTEX_SHIFT = 0; +#[doc = "< Odd shift."] +pub const GPU_PT_ODD: GPU_PROCTEX_SHIFT = 1; +#[doc = "< Even shift."] +pub const GPU_PT_EVEN: GPU_PROCTEX_SHIFT = 2; +#[doc = " Procedural texture shift values."] +pub type GPU_PROCTEX_SHIFT = ::libc::c_uint; +#[doc = "< Nearest-neighbor"] +pub const GPU_PT_NEAREST: GPU_PROCTEX_FILTER = 0; +#[doc = "< Linear interpolation"] +pub const GPU_PT_LINEAR: GPU_PROCTEX_FILTER = 1; +#[doc = "< Nearest-neighbor with mipmap using nearest-neighbor"] +pub const GPU_PT_NEAREST_MIP_NEAREST: GPU_PROCTEX_FILTER = 2; +#[doc = "< Linear interpolation with mipmap using nearest-neighbor"] +pub const GPU_PT_LINEAR_MIP_NEAREST: GPU_PROCTEX_FILTER = 3; +#[doc = "< Nearest-neighbor with mipmap using linear interpolation"] +pub const GPU_PT_NEAREST_MIP_LINEAR: GPU_PROCTEX_FILTER = 4; +#[doc = "< Linear interpolation with mipmap using linear interpolation"] +pub const GPU_PT_LINEAR_MIP_LINEAR: GPU_PROCTEX_FILTER = 5; +#[doc = " Procedural texture filter values."] +pub type GPU_PROCTEX_FILTER = ::libc::c_uint; +#[doc = "< Noise table"] +pub const GPU_LUT_NOISE: GPU_PROCTEX_LUTID = 0; +#[doc = "< RGB mapping function table"] +pub const GPU_LUT_RGBMAP: GPU_PROCTEX_LUTID = 2; +#[doc = "< Alpha mapping function table"] +pub const GPU_LUT_ALPHAMAP: GPU_PROCTEX_LUTID = 3; +#[doc = "< Color table"] +pub const GPU_LUT_COLOR: GPU_PROCTEX_LUTID = 4; +#[doc = "< Color difference table"] +pub const GPU_LUT_COLORDIF: GPU_PROCTEX_LUTID = 5; +#[doc = " Procedural texture LUT IDs."] +pub type GPU_PROCTEX_LUTID = ::libc::c_uint; +#[doc = "< 8-bit Red + 8-bit Green + 8-bit Blue + 8-bit Alpha"] +pub const GPU_RB_RGBA8: GPU_COLORBUF = 0; +#[doc = "< 8-bit Red + 8-bit Green + 8-bit Blue"] +pub const GPU_RB_RGB8: GPU_COLORBUF = 1; +#[doc = "< 5-bit Red + 5-bit Green + 5-bit Blue + 1-bit Alpha"] +pub const GPU_RB_RGBA5551: GPU_COLORBUF = 2; +#[doc = "< 5-bit Red + 6-bit Green + 5-bit Blue"] +pub const GPU_RB_RGB565: GPU_COLORBUF = 3; +#[doc = "< 4-bit Red + 4-bit Green + 4-bit Blue + 4-bit Alpha"] +pub const GPU_RB_RGBA4: GPU_COLORBUF = 4; +#[doc = " Supported color buffer formats."] +pub type GPU_COLORBUF = ::libc::c_uint; +#[doc = "< 16-bit Depth"] +pub const GPU_RB_DEPTH16: GPU_DEPTHBUF = 0; +#[doc = "< 24-bit Depth"] +pub const GPU_RB_DEPTH24: GPU_DEPTHBUF = 2; +#[doc = "< 24-bit Depth + 8-bit Stencil"] +pub const GPU_RB_DEPTH24_STENCIL8: GPU_DEPTHBUF = 3; +#[doc = " Supported depth buffer formats."] +pub type GPU_DEPTHBUF = ::libc::c_uint; +#[doc = "< Never pass."] +pub const GPU_NEVER: GPU_TESTFUNC = 0; +#[doc = "< Always pass."] +pub const GPU_ALWAYS: GPU_TESTFUNC = 1; +#[doc = "< Pass if equal."] +pub const GPU_EQUAL: GPU_TESTFUNC = 2; +#[doc = "< Pass if not equal."] +pub const GPU_NOTEQUAL: GPU_TESTFUNC = 3; +#[doc = "< Pass if less than."] +pub const GPU_LESS: GPU_TESTFUNC = 4; +#[doc = "< Pass if less than or equal."] +pub const GPU_LEQUAL: GPU_TESTFUNC = 5; +#[doc = "< Pass if greater than."] +pub const GPU_GREATER: GPU_TESTFUNC = 6; +#[doc = "< Pass if greater than or equal."] +pub const GPU_GEQUAL: GPU_TESTFUNC = 7; +#[doc = " Test functions."] +pub type GPU_TESTFUNC = ::libc::c_uint; +#[doc = "< Pass if greater than or equal."] +pub const GPU_EARLYDEPTH_GEQUAL: GPU_EARLYDEPTHFUNC = 0; +#[doc = "< Pass if greater than."] +pub const GPU_EARLYDEPTH_GREATER: GPU_EARLYDEPTHFUNC = 1; +#[doc = "< Pass if less than or equal."] +pub const GPU_EARLYDEPTH_LEQUAL: GPU_EARLYDEPTHFUNC = 2; +#[doc = "< Pass if less than."] +pub const GPU_EARLYDEPTH_LESS: GPU_EARLYDEPTHFUNC = 3; +#[doc = " Early depth test functions."] +pub type GPU_EARLYDEPTHFUNC = ::libc::c_uint; +#[doc = "< Never pass (0)."] +pub const GPU_GAS_NEVER: GPU_GASDEPTHFUNC = 0; +#[doc = "< Always pass (1)."] +pub const GPU_GAS_ALWAYS: GPU_GASDEPTHFUNC = 1; +#[doc = "< Pass if greater than (1-X)."] +pub const GPU_GAS_GREATER: GPU_GASDEPTHFUNC = 2; +#[doc = "< Pass if less than (X)."] +pub const GPU_GAS_LESS: GPU_GASDEPTHFUNC = 3; +#[doc = " Gas depth functions."] +pub type GPU_GASDEPTHFUNC = ::libc::c_uint; +#[doc = "< Disable."] +pub const GPU_SCISSOR_DISABLE: GPU_SCISSORMODE = 0; +#[doc = "< Exclude pixels inside the scissor box."] +pub const GPU_SCISSOR_INVERT: GPU_SCISSORMODE = 1; +#[doc = "< Exclude pixels outside of the scissor box."] +pub const GPU_SCISSOR_NORMAL: GPU_SCISSORMODE = 3; +#[doc = " Scissor test modes."] +pub type GPU_SCISSORMODE = ::libc::c_uint; +#[doc = "< Keep old value. (old_stencil)"] +pub const GPU_STENCIL_KEEP: GPU_STENCILOP = 0; +#[doc = "< Zero. (0)"] +pub const GPU_STENCIL_ZERO: GPU_STENCILOP = 1; +#[doc = "< Replace value. (ref)"] +pub const GPU_STENCIL_REPLACE: GPU_STENCILOP = 2; +#[doc = "< Increment value. (old_stencil + 1 saturated to [0, 255])"] +pub const GPU_STENCIL_INCR: GPU_STENCILOP = 3; +#[doc = "< Decrement value. (old_stencil - 1 saturated to [0, 255])"] +pub const GPU_STENCIL_DECR: GPU_STENCILOP = 4; +#[doc = "< Invert value. (~old_stencil)"] +pub const GPU_STENCIL_INVERT: GPU_STENCILOP = 5; +#[doc = "< Increment value. (old_stencil + 1)"] +pub const GPU_STENCIL_INCR_WRAP: GPU_STENCILOP = 6; +#[doc = "< Decrement value. (old_stencil - 1)"] +pub const GPU_STENCIL_DECR_WRAP: GPU_STENCILOP = 7; +#[doc = " Stencil operations."] +pub type GPU_STENCILOP = ::libc::c_uint; +#[doc = "< Write red."] +pub const GPU_WRITE_RED: GPU_WRITEMASK = 1; +#[doc = "< Write green."] +pub const GPU_WRITE_GREEN: GPU_WRITEMASK = 2; +#[doc = "< Write blue."] +pub const GPU_WRITE_BLUE: GPU_WRITEMASK = 4; +#[doc = "< Write alpha."] +pub const GPU_WRITE_ALPHA: GPU_WRITEMASK = 8; +#[doc = "< Write depth."] +pub const GPU_WRITE_DEPTH: GPU_WRITEMASK = 16; +#[doc = "< Write all color components."] +pub const GPU_WRITE_COLOR: GPU_WRITEMASK = 15; +#[doc = "< Write all components."] +pub const GPU_WRITE_ALL: GPU_WRITEMASK = 31; +#[doc = " Pixel write mask."] +pub type GPU_WRITEMASK = ::libc::c_uint; +#[doc = "< Add colors."] +pub const GPU_BLEND_ADD: GPU_BLENDEQUATION = 0; +#[doc = "< Subtract colors."] +pub const GPU_BLEND_SUBTRACT: GPU_BLENDEQUATION = 1; +#[doc = "< Reverse-subtract colors."] +pub const GPU_BLEND_REVERSE_SUBTRACT: GPU_BLENDEQUATION = 2; +#[doc = "< Use the minimum color."] +pub const GPU_BLEND_MIN: GPU_BLENDEQUATION = 3; +#[doc = "< Use the maximum color."] +pub const GPU_BLEND_MAX: GPU_BLENDEQUATION = 4; +#[doc = " Blend modes."] +pub type GPU_BLENDEQUATION = ::libc::c_uint; +#[doc = "< Zero."] +pub const GPU_ZERO: GPU_BLENDFACTOR = 0; +#[doc = "< One."] +pub const GPU_ONE: GPU_BLENDFACTOR = 1; +#[doc = "< Source color."] +pub const GPU_SRC_COLOR: GPU_BLENDFACTOR = 2; +#[doc = "< Source color - 1."] +pub const GPU_ONE_MINUS_SRC_COLOR: GPU_BLENDFACTOR = 3; +#[doc = "< Destination color."] +pub const GPU_DST_COLOR: GPU_BLENDFACTOR = 4; +#[doc = "< Destination color - 1."] +pub const GPU_ONE_MINUS_DST_COLOR: GPU_BLENDFACTOR = 5; +#[doc = "< Source alpha."] +pub const GPU_SRC_ALPHA: GPU_BLENDFACTOR = 6; +#[doc = "< Source alpha - 1."] +pub const GPU_ONE_MINUS_SRC_ALPHA: GPU_BLENDFACTOR = 7; +#[doc = "< Destination alpha."] +pub const GPU_DST_ALPHA: GPU_BLENDFACTOR = 8; +#[doc = "< Destination alpha - 1."] +pub const GPU_ONE_MINUS_DST_ALPHA: GPU_BLENDFACTOR = 9; +#[doc = "< Constant color."] +pub const GPU_CONSTANT_COLOR: GPU_BLENDFACTOR = 10; +#[doc = "< Constant color - 1."] +pub const GPU_ONE_MINUS_CONSTANT_COLOR: GPU_BLENDFACTOR = 11; +#[doc = "< Constant alpha."] +pub const GPU_CONSTANT_ALPHA: GPU_BLENDFACTOR = 12; +#[doc = "< Constant alpha - 1."] +pub const GPU_ONE_MINUS_CONSTANT_ALPHA: GPU_BLENDFACTOR = 13; +#[doc = "< Saturated alpha."] +pub const GPU_SRC_ALPHA_SATURATE: GPU_BLENDFACTOR = 14; +#[doc = " Blend factors."] +pub type GPU_BLENDFACTOR = ::libc::c_uint; +#[doc = "< Clear."] +pub const GPU_LOGICOP_CLEAR: GPU_LOGICOP = 0; +#[doc = "< Bitwise AND."] +pub const GPU_LOGICOP_AND: GPU_LOGICOP = 1; +#[doc = "< Reverse bitwise AND."] +pub const GPU_LOGICOP_AND_REVERSE: GPU_LOGICOP = 2; +#[doc = "< Copy."] +pub const GPU_LOGICOP_COPY: GPU_LOGICOP = 3; +#[doc = "< Set."] +pub const GPU_LOGICOP_SET: GPU_LOGICOP = 4; +#[doc = "< Inverted copy."] +pub const GPU_LOGICOP_COPY_INVERTED: GPU_LOGICOP = 5; +#[doc = "< No operation."] +pub const GPU_LOGICOP_NOOP: GPU_LOGICOP = 6; +#[doc = "< Invert."] +pub const GPU_LOGICOP_INVERT: GPU_LOGICOP = 7; +#[doc = "< Bitwise NAND."] +pub const GPU_LOGICOP_NAND: GPU_LOGICOP = 8; +#[doc = "< Bitwise OR."] +pub const GPU_LOGICOP_OR: GPU_LOGICOP = 9; +#[doc = "< Bitwise NOR."] +pub const GPU_LOGICOP_NOR: GPU_LOGICOP = 10; +#[doc = "< Bitwise XOR."] +pub const GPU_LOGICOP_XOR: GPU_LOGICOP = 11; +#[doc = "< Equivalent."] +pub const GPU_LOGICOP_EQUIV: GPU_LOGICOP = 12; +#[doc = "< Inverted bitwise AND."] +pub const GPU_LOGICOP_AND_INVERTED: GPU_LOGICOP = 13; +#[doc = "< Reverse bitwise OR."] +pub const GPU_LOGICOP_OR_REVERSE: GPU_LOGICOP = 14; +#[doc = "< Inverted bitwize OR."] +pub const GPU_LOGICOP_OR_INVERTED: GPU_LOGICOP = 15; +#[doc = " Logical operations."] +pub type GPU_LOGICOP = ::libc::c_uint; +#[doc = "< OpenGL mode."] +pub const GPU_FRAGOPMODE_GL: GPU_FRAGOPMODE = 0; +#[doc = "< Gas mode (?)."] +pub const GPU_FRAGOPMODE_GAS_ACC: GPU_FRAGOPMODE = 1; +#[doc = "< Shadow mode (?)."] +pub const GPU_FRAGOPMODE_SHADOW: GPU_FRAGOPMODE = 3; +#[doc = " Fragment operation modes."] +pub type GPU_FRAGOPMODE = ::libc::c_uint; +#[doc = "< 8-bit byte."] +pub const GPU_BYTE: GPU_FORMATS = 0; +#[doc = "< 8-bit unsigned byte."] +pub const GPU_UNSIGNED_BYTE: GPU_FORMATS = 1; +#[doc = "< 16-bit short."] +pub const GPU_SHORT: GPU_FORMATS = 2; +#[doc = "< 32-bit float."] +pub const GPU_FLOAT: GPU_FORMATS = 3; +#[doc = " Supported component formats."] +pub type GPU_FORMATS = ::libc::c_uint; +#[doc = "< Disabled."] +pub const GPU_CULL_NONE: GPU_CULLMODE = 0; +#[doc = "< Front, counter-clockwise."] +pub const GPU_CULL_FRONT_CCW: GPU_CULLMODE = 1; +#[doc = "< Back, counter-clockwise."] +pub const GPU_CULL_BACK_CCW: GPU_CULLMODE = 2; +#[doc = " Cull modes."] +pub type GPU_CULLMODE = ::libc::c_uint; +#[doc = "< Primary color."] +pub const GPU_PRIMARY_COLOR: GPU_TEVSRC = 0; +#[doc = "< Primary fragment color."] +pub const GPU_FRAGMENT_PRIMARY_COLOR: GPU_TEVSRC = 1; +#[doc = "< Secondary fragment color."] +pub const GPU_FRAGMENT_SECONDARY_COLOR: GPU_TEVSRC = 2; +#[doc = "< Texture unit 0."] +pub const GPU_TEXTURE0: GPU_TEVSRC = 3; +#[doc = "< Texture unit 1."] +pub const GPU_TEXTURE1: GPU_TEVSRC = 4; +#[doc = "< Texture unit 2."] +pub const GPU_TEXTURE2: GPU_TEVSRC = 5; +#[doc = "< Texture unit 3."] +pub const GPU_TEXTURE3: GPU_TEVSRC = 6; +#[doc = "< Previous buffer."] +pub const GPU_PREVIOUS_BUFFER: GPU_TEVSRC = 13; +#[doc = "< Constant value."] +pub const GPU_CONSTANT: GPU_TEVSRC = 14; +#[doc = "< Previous value."] +pub const GPU_PREVIOUS: GPU_TEVSRC = 15; +#[doc = " Texture combiner sources."] +pub type GPU_TEVSRC = ::libc::c_uint; +#[doc = "< Source color."] +pub const GPU_TEVOP_RGB_SRC_COLOR: GPU_TEVOP_RGB = 0; +#[doc = "< Source color - 1."] +pub const GPU_TEVOP_RGB_ONE_MINUS_SRC_COLOR: GPU_TEVOP_RGB = 1; +#[doc = "< Source alpha."] +pub const GPU_TEVOP_RGB_SRC_ALPHA: GPU_TEVOP_RGB = 2; +#[doc = "< Source alpha - 1."] +pub const GPU_TEVOP_RGB_ONE_MINUS_SRC_ALPHA: GPU_TEVOP_RGB = 3; +#[doc = "< Source red."] +pub const GPU_TEVOP_RGB_SRC_R: GPU_TEVOP_RGB = 4; +#[doc = "< Source red - 1."] +pub const GPU_TEVOP_RGB_ONE_MINUS_SRC_R: GPU_TEVOP_RGB = 5; +#[doc = "< Unknown."] +pub const GPU_TEVOP_RGB_0x06: GPU_TEVOP_RGB = 6; +#[doc = "< Unknown."] +pub const GPU_TEVOP_RGB_0x07: GPU_TEVOP_RGB = 7; +#[doc = "< Source green."] +pub const GPU_TEVOP_RGB_SRC_G: GPU_TEVOP_RGB = 8; +#[doc = "< Source green - 1."] +pub const GPU_TEVOP_RGB_ONE_MINUS_SRC_G: GPU_TEVOP_RGB = 9; +#[doc = "< Unknown."] +pub const GPU_TEVOP_RGB_0x0A: GPU_TEVOP_RGB = 10; +#[doc = "< Unknown."] +pub const GPU_TEVOP_RGB_0x0B: GPU_TEVOP_RGB = 11; +#[doc = "< Source blue."] +pub const GPU_TEVOP_RGB_SRC_B: GPU_TEVOP_RGB = 12; +#[doc = "< Source blue - 1."] +pub const GPU_TEVOP_RGB_ONE_MINUS_SRC_B: GPU_TEVOP_RGB = 13; +#[doc = "< Unknown."] +pub const GPU_TEVOP_RGB_0x0E: GPU_TEVOP_RGB = 14; +#[doc = "< Unknown."] +pub const GPU_TEVOP_RGB_0x0F: GPU_TEVOP_RGB = 15; +#[doc = " Texture RGB combiner operands."] +pub type GPU_TEVOP_RGB = ::libc::c_uint; +#[doc = "< Source alpha."] +pub const GPU_TEVOP_A_SRC_ALPHA: GPU_TEVOP_A = 0; +#[doc = "< Source alpha - 1."] +pub const GPU_TEVOP_A_ONE_MINUS_SRC_ALPHA: GPU_TEVOP_A = 1; +#[doc = "< Source red."] +pub const GPU_TEVOP_A_SRC_R: GPU_TEVOP_A = 2; +#[doc = "< Source red - 1."] +pub const GPU_TEVOP_A_ONE_MINUS_SRC_R: GPU_TEVOP_A = 3; +#[doc = "< Source green."] +pub const GPU_TEVOP_A_SRC_G: GPU_TEVOP_A = 4; +#[doc = "< Source green - 1."] +pub const GPU_TEVOP_A_ONE_MINUS_SRC_G: GPU_TEVOP_A = 5; +#[doc = "< Source blue."] +pub const GPU_TEVOP_A_SRC_B: GPU_TEVOP_A = 6; +#[doc = "< Source blue - 1."] +pub const GPU_TEVOP_A_ONE_MINUS_SRC_B: GPU_TEVOP_A = 7; +#[doc = " Texture Alpha combiner operands."] +pub type GPU_TEVOP_A = ::libc::c_uint; +#[doc = "< Replace."] +pub const GPU_REPLACE: GPU_COMBINEFUNC = 0; +#[doc = "< Modulate."] +pub const GPU_MODULATE: GPU_COMBINEFUNC = 1; +#[doc = "< Add."] +pub const GPU_ADD: GPU_COMBINEFUNC = 2; +#[doc = "< Signed add."] +pub const GPU_ADD_SIGNED: GPU_COMBINEFUNC = 3; +#[doc = "< Interpolate."] +pub const GPU_INTERPOLATE: GPU_COMBINEFUNC = 4; +#[doc = "< Subtract."] +pub const GPU_SUBTRACT: GPU_COMBINEFUNC = 5; +#[doc = "< Dot3. RGB only."] +pub const GPU_DOT3_RGB: GPU_COMBINEFUNC = 6; +#[doc = "< Multiply then add."] +pub const GPU_MULTIPLY_ADD: GPU_COMBINEFUNC = 8; +#[doc = "< Add then multiply."] +pub const GPU_ADD_MULTIPLY: GPU_COMBINEFUNC = 9; +#[doc = " Texture combiner functions."] +pub type GPU_COMBINEFUNC = ::libc::c_uint; +#[doc = "< 1x"] +pub const GPU_TEVSCALE_1: GPU_TEVSCALE = 0; +#[doc = "< 2x"] +pub const GPU_TEVSCALE_2: GPU_TEVSCALE = 1; +#[doc = "< 4x"] +pub const GPU_TEVSCALE_4: GPU_TEVSCALE = 2; +#[doc = " Texture scale factors."] +pub type GPU_TEVSCALE = ::libc::c_uint; +#[doc = "< None."] +pub const GPU_NO_FRESNEL: GPU_FRESNELSEL = 0; +#[doc = "< Primary alpha."] +pub const GPU_PRI_ALPHA_FRESNEL: GPU_FRESNELSEL = 1; +#[doc = "< Secondary alpha."] +pub const GPU_SEC_ALPHA_FRESNEL: GPU_FRESNELSEL = 2; +#[doc = "< Primary and secondary alpha."] +pub const GPU_PRI_SEC_ALPHA_FRESNEL: GPU_FRESNELSEL = 3; +#[doc = " Fresnel options."] +pub type GPU_FRESNELSEL = ::libc::c_uint; +#[doc = "< Disabled."] +pub const GPU_BUMP_NOT_USED: GPU_BUMPMODE = 0; +#[doc = "< Bump as bump mapping."] +pub const GPU_BUMP_AS_BUMP: GPU_BUMPMODE = 1; +#[doc = "< Bump as tangent/normal mapping."] +pub const GPU_BUMP_AS_TANG: GPU_BUMPMODE = 2; +#[doc = " Bump map modes."] +pub type GPU_BUMPMODE = ::libc::c_uint; +#[doc = "< D0 LUT."] +pub const GPU_LUT_D0: GPU_LIGHTLUTID = 0; +#[doc = "< D1 LUT."] +pub const GPU_LUT_D1: GPU_LIGHTLUTID = 1; +#[doc = "< Spotlight LUT."] +pub const GPU_LUT_SP: GPU_LIGHTLUTID = 2; +#[doc = "< Fresnel LUT."] +pub const GPU_LUT_FR: GPU_LIGHTLUTID = 3; +#[doc = "< Reflection-Blue LUT."] +pub const GPU_LUT_RB: GPU_LIGHTLUTID = 4; +#[doc = "< Reflection-Green LUT."] +pub const GPU_LUT_RG: GPU_LIGHTLUTID = 5; +#[doc = "< Reflection-Red LUT."] +pub const GPU_LUT_RR: GPU_LIGHTLUTID = 6; +#[doc = "< Distance attenuation LUT."] +pub const GPU_LUT_DA: GPU_LIGHTLUTID = 7; +#[doc = " LUT IDs."] +pub type GPU_LIGHTLUTID = ::libc::c_uint; +#[doc = "< Normal*HalfVector"] +pub const GPU_LUTINPUT_NH: GPU_LIGHTLUTINPUT = 0; +#[doc = "< View*HalfVector"] +pub const GPU_LUTINPUT_VH: GPU_LIGHTLUTINPUT = 1; +#[doc = "< Normal*View"] +pub const GPU_LUTINPUT_NV: GPU_LIGHTLUTINPUT = 2; +#[doc = "< LightVector*Normal"] +pub const GPU_LUTINPUT_LN: GPU_LIGHTLUTINPUT = 3; +#[doc = "< -LightVector*SpotlightVector"] +pub const GPU_LUTINPUT_SP: GPU_LIGHTLUTINPUT = 4; +#[doc = "< cosine of phi"] +pub const GPU_LUTINPUT_CP: GPU_LIGHTLUTINPUT = 5; +#[doc = " LUT inputs."] +pub type GPU_LIGHTLUTINPUT = ::libc::c_uint; +#[doc = "< 1x scale."] +pub const GPU_LUTSCALER_1x: GPU_LIGHTLUTSCALER = 0; +#[doc = "< 2x scale."] +pub const GPU_LUTSCALER_2x: GPU_LIGHTLUTSCALER = 1; +#[doc = "< 4x scale."] +pub const GPU_LUTSCALER_4x: GPU_LIGHTLUTSCALER = 2; +#[doc = "< 8x scale."] +pub const GPU_LUTSCALER_8x: GPU_LIGHTLUTSCALER = 3; +#[doc = "< 0.25x scale."] +pub const GPU_LUTSCALER_0_25x: GPU_LIGHTLUTSCALER = 6; +#[doc = "< 0.5x scale."] +pub const GPU_LUTSCALER_0_5x: GPU_LIGHTLUTSCALER = 7; +#[doc = " LUT scalers."] +pub type GPU_LIGHTLUTSCALER = ::libc::c_uint; +#[doc = "< LUTs that are common to all lights."] +pub const GPU_LUTSELECT_COMMON: GPU_LIGHTLUTSELECT = 0; +#[doc = "< Spotlight LUT."] +pub const GPU_LUTSELECT_SP: GPU_LIGHTLUTSELECT = 1; +#[doc = "< Distance attenuation LUT."] +pub const GPU_LUTSELECT_DA: GPU_LIGHTLUTSELECT = 2; +#[doc = " LUT selection."] +pub type GPU_LIGHTLUTSELECT = ::libc::c_uint; +#[doc = "< Fog/Gas unit disabled."] +pub const GPU_NO_FOG: GPU_FOGMODE = 0; +#[doc = "< Fog/Gas unit configured in Fog mode."] +pub const GPU_FOG: GPU_FOGMODE = 5; +#[doc = "< Fog/Gas unit configured in Gas mode."] +pub const GPU_GAS: GPU_FOGMODE = 7; +#[doc = " Fog modes."] +pub type GPU_FOGMODE = ::libc::c_uint; +#[doc = "< Plain density."] +pub const GPU_PLAIN_DENSITY: GPU_GASMODE = 0; +#[doc = "< Depth density."] +pub const GPU_DEPTH_DENSITY: GPU_GASMODE = 1; +#[doc = " Gas shading density source values."] +pub type GPU_GASMODE = ::libc::c_uint; +#[doc = "< Gas density used as input."] +pub const GPU_GAS_DENSITY: GPU_GASLUTINPUT = 0; +#[doc = "< Light factor used as input."] +pub const GPU_GAS_LIGHT_FACTOR: GPU_GASLUTINPUT = 1; +#[doc = " Gas color LUT inputs."] +pub type GPU_GASLUTINPUT = ::libc::c_uint; +#[doc = "< Triangles."] +pub const GPU_TRIANGLES: GPU_Primitive_t = 0; +#[doc = "< Triangle strip."] +pub const GPU_TRIANGLE_STRIP: GPU_Primitive_t = 256; +#[doc = "< Triangle fan."] +pub const GPU_TRIANGLE_FAN: GPU_Primitive_t = 512; +#[doc = "< Geometry shader primitive."] +pub const GPU_GEOMETRY_PRIM: GPU_Primitive_t = 768; +#[doc = " Supported primitives."] +pub type GPU_Primitive_t = ::libc::c_uint; +#[doc = "< Vertex shader."] +pub const GPU_VERTEX_SHADER: GPU_SHADER_TYPE = 0; +#[doc = "< Geometry shader."] +pub const GPU_GEOMETRY_SHADER: GPU_SHADER_TYPE = 1; +#[doc = " Shader types."] +pub type GPU_SHADER_TYPE = ::libc::c_uint; +#[doc = "< Vertex shader."] +pub const VERTEX_SHDR: DVLE_type = 0; +#[doc = "< Geometry shader."] +pub const GEOMETRY_SHDR: DVLE_type = 1; +#[doc = " DVLE type."] +pub type DVLE_type = ::libc::c_uint; +#[doc = "< Point processing mode."] +pub const GSH_POINT: DVLE_geoShaderMode = 0; +#[doc = "< Variable-size primitive processing mode."] +pub const GSH_VARIABLE_PRIM: DVLE_geoShaderMode = 1; +#[doc = "< Fixed-size primitive processing mode."] +pub const GSH_FIXED_PRIM: DVLE_geoShaderMode = 2; +#[doc = " Geometry shader operation modes."] +pub type DVLE_geoShaderMode = ::libc::c_uint; +#[doc = " DVLP data."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DVLP_s { + #[doc = "< Code size."] + pub codeSize: u32_, + #[doc = "< Code data."] + pub codeData: *mut u32_, + #[doc = "< Operand description size."] + pub opdescSize: u32_, + #[doc = "< Operand description data."] + pub opcdescData: *mut u32_, +} +#[doc = " DVLE constant entry data."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DVLE_constEntry_s { + #[doc = "< Constant type. See @ref DVLE_constantType"] + pub type_: u16_, + #[doc = "< Constant ID."] + pub id: u16_, + #[doc = "< Constant data."] + pub data: [u32_; 4usize], +} +#[doc = " DVLE output entry data."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DVLE_outEntry_s { + #[doc = "< Output type. See @ref DVLE_outputAttribute_t"] + pub type_: u16_, + #[doc = "< Output register ID."] + pub regID: u16_, + #[doc = "< Output mask."] + pub mask: u8_, + #[doc = "< Unknown."] + pub unk: [u8_; 3usize], +} +#[doc = " DVLE uniform entry data."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DVLE_uniformEntry_s { + #[doc = "< Symbol offset."] + pub symbolOffset: u32_, + #[doc = "< Start register."] + pub startReg: u16_, + #[doc = "< End register."] + pub endReg: u16_, +} +#[doc = " DVLE data."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DVLE_s { + #[doc = "< DVLE type."] + pub type_: DVLE_type, + #[doc = "< true = merge vertex/geometry shader outmaps ('dummy' output attribute is present)."] + pub mergeOutmaps: bool, + #[doc = "< Geometry shader operation mode."] + pub gshMode: DVLE_geoShaderMode, + #[doc = "< Starting float uniform register number for storing the fixed-size primitive vertex array."] + pub gshFixedVtxStart: u8_, + #[doc = "< Number of fully-defined vertices in the variable-size primitive vertex array."] + pub gshVariableVtxNum: u8_, + #[doc = "< Number of vertices in the fixed-size primitive vertex array."] + pub gshFixedVtxNum: u8_, + #[doc = "< Contained DVLPs."] + pub dvlp: *mut DVLP_s, + #[doc = "< Offset of the start of the main function."] + pub mainOffset: u32_, + #[doc = "< Offset of the end of the main function."] + pub endmainOffset: u32_, + #[doc = "< Constant table size."] + pub constTableSize: u32_, + #[doc = "< Constant table data."] + pub constTableData: *mut DVLE_constEntry_s, + #[doc = "< Output table size."] + pub outTableSize: u32_, + #[doc = "< Output table data."] + pub outTableData: *mut DVLE_outEntry_s, + #[doc = "< Uniform table size."] + pub uniformTableSize: u32_, + #[doc = "< Uniform table data."] + pub uniformTableData: *mut DVLE_uniformEntry_s, + #[doc = "< Symbol table data."] + pub symbolTableData: *mut ::libc::c_char, + #[doc = "< Output map mask."] + pub outmapMask: u8_, + #[doc = "< Output map data."] + pub outmapData: [u32_; 8usize], + #[doc = "< Output map mode."] + pub outmapMode: u32_, + #[doc = "< Output map attribute clock."] + pub outmapClock: u32_, +} +#[doc = " DVLB data."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DVLB_s { + #[doc = "< DVLE count."] + pub numDVLE: u32_, + #[doc = "< Primary DVLP."] + pub DVLP: DVLP_s, + #[doc = "< Contained DVLE."] + pub DVLE: *mut DVLE_s, +} +extern "C" { + #[doc = " @brief Parses a shader binary."] + #[doc = " @param shbinData Shader binary data."] + #[doc = " @param shbinSize Shader binary size."] + #[doc = " @return The parsed shader binary."] + pub fn DVLB_ParseFile(shbinData: *mut u32_, shbinSize: u32_) -> *mut DVLB_s; +} +extern "C" { + #[doc = " @brief Frees shader binary data."] + #[doc = " @param dvlb DVLB to free."] + pub fn DVLB_Free(dvlb: *mut DVLB_s); +} +#[doc = " 24-bit float uniforms."] +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Copy, Clone)] +pub struct float24Uniform_s { + pub _bindgen_opaque_blob: [u32; 4usize], +} +#[doc = " Describes an instance of either a vertex or geometry shader."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct shaderInstance_s { + #[doc = "< Shader DVLE."] + pub dvle: *mut DVLE_s, + #[doc = "< Boolean uniforms."] + pub boolUniforms: u16_, + #[doc = "< Used boolean uniform mask."] + pub boolUniformMask: u16_, + #[doc = "< Integer uniforms."] + pub intUniforms: [u32_; 4usize], + #[doc = "< 24-bit float uniforms."] + pub float24Uniforms: *mut float24Uniform_s, + #[doc = "< Used integer uniform mask."] + pub intUniformMask: u8_, + #[doc = "< Float uniform count."] + pub numFloat24Uniforms: u8_, +} +#[doc = " Describes an instance of a full shader program."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct shaderProgram_s { + #[doc = "< Vertex shader."] + pub vertexShader: *mut shaderInstance_s, + #[doc = "< Geometry shader."] + pub geometryShader: *mut shaderInstance_s, + #[doc = "< Geometry shader input permutation."] + pub geoShaderInputPermutation: [u32_; 2usize], + #[doc = "< Geometry shader input stride."] + pub geoShaderInputStride: u8_, +} +extern "C" { + #[doc = " @brief Initializes a shader instance."] + #[doc = " @param si Shader instance to initialize."] + #[doc = " @param dvle DVLE to initialize the shader instance with."] + pub fn shaderInstanceInit(si: *mut shaderInstance_s, dvle: *mut DVLE_s) -> Result; +} +extern "C" { + #[doc = " @brief Frees a shader instance."] + #[doc = " @param si Shader instance to free."] + pub fn shaderInstanceFree(si: *mut shaderInstance_s) -> Result; +} +extern "C" { + #[doc = " @brief Sets a bool uniform of a shader."] + #[doc = " @param si Shader instance to use."] + #[doc = " @param id ID of the bool uniform."] + #[doc = " @param value Value to set."] + pub fn shaderInstanceSetBool( + si: *mut shaderInstance_s, + id: ::libc::c_int, + value: bool, + ) -> Result; +} +extern "C" { + #[doc = " @brief Gets a bool uniform of a shader."] + #[doc = " @param si Shader instance to use."] + #[doc = " @param id ID of the bool uniform."] + #[doc = " @param value Pointer to output the value to."] + pub fn shaderInstanceGetBool( + si: *mut shaderInstance_s, + id: ::libc::c_int, + value: *mut bool, + ) -> Result; +} +extern "C" { + #[doc = " @brief Gets the location of a shader's uniform."] + #[doc = " @param si Shader instance to use."] + #[doc = " @param name Name of the uniform."] + pub fn shaderInstanceGetUniformLocation( + si: *mut shaderInstance_s, + name: *const ::libc::c_char, + ) -> s8; +} +extern "C" { + #[doc = " @brief Initializes a shader program."] + #[doc = " @param sp Shader program to initialize."] + pub fn shaderProgramInit(sp: *mut shaderProgram_s) -> Result; +} +extern "C" { + #[doc = " @brief Frees a shader program."] + #[doc = " @param sp Shader program to free."] + pub fn shaderProgramFree(sp: *mut shaderProgram_s) -> Result; +} +extern "C" { + #[doc = " @brief Sets the vertex shader of a shader program."] + #[doc = " @param sp Shader program to use."] + #[doc = " @param dvle Vertex shader to set."] + pub fn shaderProgramSetVsh(sp: *mut shaderProgram_s, dvle: *mut DVLE_s) -> Result; +} +extern "C" { + #[doc = " @brief Sets the geometry shader of a shader program."] + #[doc = " @param sp Shader program to use."] + #[doc = " @param dvle Geometry shader to set."] + #[doc = " @param stride Input stride of the shader (pass 0 to match the number of outputs of the vertex shader)."] + pub fn shaderProgramSetGsh(sp: *mut shaderProgram_s, dvle: *mut DVLE_s, stride: u8_) -> Result; +} +extern "C" { + #[doc = " @brief Configures the permutation of the input attributes of the geometry shader of a shader program."] + #[doc = " @param sp Shader program to use."] + #[doc = " @param permutation Attribute permutation to use."] + pub fn shaderProgramSetGshInputPermutation( + sp: *mut shaderProgram_s, + permutation: u64_, + ) -> Result; +} +extern "C" { + #[doc = " @brief Configures the shader units to use the specified shader program."] + #[doc = " @param sp Shader program to use."] + #[doc = " @param sendVshCode When true, the vertex shader's code and operand descriptors are uploaded."] + #[doc = " @param sendGshCode When true, the geometry shader's code and operand descriptors are uploaded."] + pub fn shaderProgramConfigure( + sp: *mut shaderProgram_s, + sendVshCode: bool, + sendGshCode: bool, + ) -> Result; +} +extern "C" { + #[doc = " @brief Same as shaderProgramConfigure, but always loading code/operand descriptors and uploading DVLE constants afterwards."] + #[doc = " @param sp Shader program to use."] + pub fn shaderProgramUse(sp: *mut shaderProgram_s) -> Result; +} pub type C3D_IVec = u32_; #[doc = " @struct C3D_FVec"] #[doc = " @brief Float vector"] diff --git a/citro3d/Cargo.toml b/citro3d/Cargo.toml new file mode 100644 index 0000000..6cf4742 --- /dev/null +++ b/citro3d/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "citro3d" +version = "0.1.0" +edition = "2021" +authors = [""] + +[dependencies] +citro3d-sys = { git = "https://github.com/ian-h-chamberlain/citro3d-rs.git" } +libc = "0.2.125" + +[dev-dependencies] +ctru-rs = { git = "https://github.com/Meziu/ctru-rs.git" } diff --git a/citro3d/examples/assets/.gitignore b/citro3d/examples/assets/.gitignore new file mode 100644 index 0000000..7852bdf --- /dev/null +++ b/citro3d/examples/assets/.gitignore @@ -0,0 +1 @@ +*.shbin diff --git a/citro3d/examples/assets/vshader.pica b/citro3d/examples/assets/vshader.pica new file mode 100644 index 0000000..79077d1 --- /dev/null +++ b/citro3d/examples/assets/vshader.pica @@ -0,0 +1,36 @@ +; Example PICA200 vertex shader + +; Uniforms +.fvec projection[4] + +; Constants +.constf myconst(0.0, 1.0, -1.0, 0.1) +.constf myconst2(0.3, 0.0, 0.0, 0.0) +.alias zeros myconst.xxxx ; Vector full of zeros +.alias ones myconst.yyyy ; Vector full of ones + +; Outputs +.out outpos position +.out outclr color + +; Inputs (defined as aliases for convenience) +.alias inpos v0 +.alias inclr 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 + + ; outclr = inclr + mov outclr, inclr + + ; We're finished + end +.end diff --git a/citro3d/examples/triangle.rs b/citro3d/examples/triangle.rs new file mode 100644 index 0000000..230ab46 --- /dev/null +++ b/citro3d/examples/triangle.rs @@ -0,0 +1,217 @@ +use citro3d_sys::C3D_Mtx; +use citro3d_sys::{shaderProgram_s, DVLB_s}; +use ctru::gfx::{Gfx, Screen, Side}; +use ctru::services::apt::Apt; +use ctru::services::hid::{Hid, KeyPad}; + +use std::ffi::CString; +use std::mem::MaybeUninit; + +const VERTICES: [Vertex; 3] = [ + Vertex::new(200.0, 200.0, 0.5), + Vertex::new(100.0, 40.0, 0.5), + Vertex::new(300.0, 40.0, 0.5), +]; + +fn main() { + ctru::init(); + + let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); + let hid = Hid::init().expect("Couldn't obtain HID controller"); + let apt = Apt::init().expect("Couldn't obtain APT controller"); + + let top_screen = gfx.top_screen.borrow_mut(); + + let target = unsafe { + citro3d_sys::C3D_Init(citro3d_sys::C3D_DEFAULT_CMDBUF_SIZE); + + let depth_fmt = citro3d_sys::C3D_DEPTHTYPE { + __e: citro3d_sys::GPU_RB_DEPTH24_STENCIL8, + }; + + let target = + citro3d_sys::C3D_RenderTargetCreate(240, 400, citro3d_sys::GPU_RB_RGBA8, depth_fmt); + + // TODO: easier construction of flags + let transfer_flags = + citro3d_sys::GX_TRANSFER_FMT_RGBA8 << 8 | citro3d_sys::GX_TRANSFER_FMT_RGB8 << 12; + + citro3d_sys::C3D_RenderTargetSetOutput( + target, + top_screen.as_raw(), + Side::Left.into(), + transfer_flags, + ); + + target + }; + + let (program, uloc_projection, projection, vbo_data, vshader_dvlb) = scene_init(); + + // Main loop + while apt.main_loop() { + //Scan all the inputs. This should be done once for each frame + hid.scan_input(); + + if hid.keys_down().contains(KeyPad::KEY_START) { + break; + } + + const CLEAR_COLOR: u32 = 0x68B0D8FF; + + unsafe { + citro3d_sys::C3D_FrameBegin(citro3d_sys::C3D_FRAME_SYNCDRAW as u8); + + citro3d_sys::C3D_RenderTargetClear(target, citro3d_sys::C3D_CLEAR_ALL, CLEAR_COLOR, 0); + citro3d_sys::C3D_FrameDrawOn(target); + } + scene_render(uloc_projection.into(), &projection); + unsafe { + citro3d_sys::C3D_FrameEnd(0); + } + } + + scene_exit(vbo_data, program, vshader_dvlb); + + unsafe { + citro3d_sys::C3D_Fini(); + } +} +struct Vertex { + x: f32, + y: f32, + z: f32, +} + +impl Vertex { + const fn new(x: f32, y: f32, z: f32) -> Self { + Self { x, y, z } + } +} + +fn scene_init() -> (shaderProgram_s, i8, C3D_Mtx, *mut libc::c_void, *mut DVLB_s) { + // Load the vertex shader, create a shader program and bind it + unsafe { + // To compile the shader: + // ```sh + // picasso assets/vshader.v.pica -o assets/vshader.shbin + // ``` + // TODO: can we do this in a build script? + + // boo, this way we have to specify the length. Alternative seems to be allocating a + // slice first, then copying into it with a transmute... + const SHBIN_BYTES: &[u8; 280] = include_bytes!("assets/vshader.shbin"); + // Assume the data is aligned properly... + let mut shbin_data: [u32; SHBIN_BYTES.len() / 4] = std::mem::transmute_copy(SHBIN_BYTES); + + let vshader_dvlb = citro3d_sys::DVLB_ParseFile( + shbin_data.as_mut_ptr(), + shbin_data + .len() + .try_into() + .expect("shader len fits in a u32"), + ); + let mut program = MaybeUninit::::uninit(); + + citro3d_sys::shaderProgramInit(program.as_mut_ptr()); + citro3d_sys::shaderProgramSetVsh(program.as_mut_ptr(), (*vshader_dvlb).DVLE); + + let mut program = program.assume_init(); + + citro3d_sys::C3D_BindProgram(&mut program); + + // Get the location of the uniforms + let projection_name = CString::new("projection").unwrap(); + let uloc_projection = citro3d_sys::shaderInstanceGetUniformLocation( + program.vertexShader, + projection_name.as_ptr(), + ); + + // Configure attributes for use with the vertex shader + let attr_info = citro3d_sys::C3D_GetAttrInfo(); + citro3d_sys::AttrInfo_Init(attr_info); + citro3d_sys::AttrInfo_AddLoader(attr_info, 0, citro3d_sys::GPU_FLOAT, 3); // v0=position + citro3d_sys::AttrInfo_AddFixed(attr_info, 1); // v1=color + + // Set the fixed attribute (color) to solid white + citro3d_sys::C3D_FixedAttribSet(1, 1.0, 1.0, 1.0, 1.0); + + let mut projection = MaybeUninit::::uninit(); + // Compute the projection matrix + citro3d_sys::Mtx_OrthoTilt( + projection.as_mut_ptr(), + 0.0, + 400.0, + 0.0, + 240.0, + 0.0, + 1.0, + true, + ); + let projection = projection.assume_init(); + + let vertices_len = std::mem::size_of_val(&VERTICES); + + // Create the VBO (vertex buffer object) + let vbo_data = + citro3d_sys::linearAlloc(vertices_len.try_into().expect("size does not fit in u32")); + + vbo_data.copy_from(VERTICES.as_ptr() as _, vertices_len); + + // Configure buffers + let buf_info = citro3d_sys::C3D_GetBufInfo(); + citro3d_sys::BufInfo_Init(buf_info); + citro3d_sys::BufInfo_Add( + buf_info, + vbo_data, + std::mem::size_of::() + .try_into() + .expect("size of vertex fits in u32"), + 1, + 0x0, + ); + + // Configure the first fragment shading substage to just pass through the vertex color + // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight + let env = citro3d_sys::C3D_GetTexEnv(0); + citro3d_sys::C3D_TexEnvInit(env); + citro3d_sys::C3D_TexEnvSrc( + env, + citro3d_sys::C3D_Both as i32, + citro3d_sys::GPU_PRIMARY_COLOR as i32, + 0, + 0, + ); + citro3d_sys::C3D_TexEnvFunc( + env, + citro3d_sys::C3D_Both as i32, + citro3d_sys::GPU_REPLACE as i32, + ); + + (program, uloc_projection, projection, vbo_data, vshader_dvlb) + } +} + +fn scene_render(uloc_projection: i32, projection: &C3D_Mtx) { + unsafe { + // Update the uniforms + citro3d_sys::C3D_FVUnifMtx4x4(citro3d_sys::GPU_VERTEX_SHADER, uloc_projection, projection); + + // Draw the VBO + citro3d_sys::C3D_DrawArrays(citro3d_sys::GPU_TRIANGLES, 0, VERTICES.len() as i32); + } +} + +fn scene_exit( + vbo_data: *mut libc::c_void, + mut program: shaderProgram_s, + vshader_dvlb: *mut DVLB_s, +) { + unsafe { + citro3d_sys::linearFree(vbo_data); + + citro3d_sys::shaderProgramFree(&mut program); + + citro3d_sys::DVLB_Free(vshader_dvlb); + } +} diff --git a/citro3d/src/lib.rs b/citro3d/src/lib.rs new file mode 100644 index 0000000..1b4a90c --- /dev/null +++ b/citro3d/src/lib.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +}