Merge bc3d68efc4
into 9f21cf7b38
This commit is contained in:
commit
a24c7072ae
37
.github/workflows/doxygen.yaml
vendored
Normal file
37
.github/workflows/doxygen.yaml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
name: Deploy site
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ c3d-docs ]
|
||||
|
||||
jobs:
|
||||
doc-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Doxygen
|
||||
run: sudo apt install doxygen
|
||||
|
||||
- name: Display Doxygen version
|
||||
run: echo "Doxygen version $(doxygen -v)"
|
||||
|
||||
- name: Generate libctru tags
|
||||
run: |
|
||||
git clone --branch=master --single-branch --depth 1 https://github.com/devkitPro/libctru
|
||||
cd libctru/libctru
|
||||
doxygen
|
||||
|
||||
- name: Build documentation
|
||||
run: CTRU_DOCPATH="https://libctru.devkitpro.org/" doxygen
|
||||
|
||||
- name: Deploy 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BRANCH: gh-pages # The branch the action should deploy to.
|
||||
FOLDER: docs/html # The folder the action should deploy.
|
||||
CLEAN: true # Automatically remove deleted files from the deploy branch
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,10 +1,12 @@
|
||||
.*/
|
||||
!.github/
|
||||
*~
|
||||
*.3dsx
|
||||
*.elf
|
||||
*.exe
|
||||
*.smdh
|
||||
*.tar.bz2
|
||||
*.tag
|
||||
Thumbs.db
|
||||
build/
|
||||
deps/
|
||||
@ -12,4 +14,5 @@ release/
|
||||
debug/
|
||||
lib/
|
||||
bin/
|
||||
doc/
|
||||
docs/
|
||||
libctru/
|
||||
|
64
Changelog.md
Normal file
64
Changelog.md
Normal file
@ -0,0 +1,64 @@
|
||||
# Changelog
|
||||
|
||||
## Version 1.7.0
|
||||
|
||||
- Implement VRAM bank awareness for rendertarget allocations
|
||||
- Further improvements to overall system stability and other minor adjustments have been made to enhance the user experience.
|
||||
|
||||
## Version 1.6.2
|
||||
|
||||
- Added C3D_RenderTargetDetachOutput (called automatically on render target destroy)
|
||||
|
||||
## Version 1.6.1
|
||||
|
||||
- Pause the VBlank counters while the application is suspended
|
||||
- Use gfxScreenSwapBuffers; implement left->right eye duplication with it
|
||||
- Further improvements to overall system stability and other minor adjustments have been made to enhance the user experience.
|
||||
|
||||
## Version 1.6.0
|
||||
|
||||
- Simplified internal render queue framebuffer transfer system
|
||||
- Removed long-since obsolete flush functions
|
||||
- Further improvements to overall system stability and other minor adjustments have been made to enhance the user experience.
|
||||
|
||||
## Version 1.5.0
|
||||
|
||||
- Removed deprecated functionality (C3D_RenderTargetSetClear, C3D_SafeDisplayTransfer, C3D_SafeTextureCopy, C3D_SafeMemoryFill, TexEnv_Init, C3D_TexEnvOp).
|
||||
- Added experimental gas support.
|
||||
- Added logic to make sure that the framebuffer is flushed/reinitialized before changing program.
|
||||
|
||||
## Version 1.4.0
|
||||
|
||||
- Added an interface for loading .t3x files generated by tex3ds
|
||||
- TexEnv code was revamped and cleaner as to provide better error checking through stronger typing
|
||||
- C3D_TexEnvOp separated into C3D_TexEnvOpRgb and C3D_TexEnvOpAlpha
|
||||
- C3D_SafeXyz functions have been deprecated and replaced by C3D_SyncXyz functions
|
||||
- Miscellaneous bugfixes and optimizations
|
||||
|
||||
## Version 1.3.1
|
||||
|
||||
- Removed deprecated C3D_RenderBuffer functionality
|
||||
- Recompiled with libctru 1.4.0
|
||||
|
||||
## Version 1.3.0
|
||||
|
||||
Major changes:
|
||||
|
||||
- Overhauled texture API
|
||||
- Frame rate control & monitoring
|
||||
- CPU/GPU time profiling
|
||||
- Support for framebuffers (lightweight renderbuffers) - old renderbuffers are now deprecated
|
||||
- Rendertarget system now uses libctru GX queue
|
||||
- Corrected LUT code
|
||||
- Debug build for use with GDB
|
||||
- New GPU features:
|
||||
- Mipmaps
|
||||
- Cubemaps
|
||||
- Shadow textures
|
||||
- Procedural textures
|
||||
- Fog
|
||||
- Miscellaneous bugfixes and optimizations
|
||||
|
||||
## Version 0-1.2.0
|
||||
|
||||
No changelog avaliable
|
6
Makefile
6
Makefile
@ -83,13 +83,13 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I.
|
||||
|
||||
.PHONY: clean all doc
|
||||
.PHONY: clean all docs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: lib/libcitro3d.a lib/libcitro3dd.a
|
||||
|
||||
doc:
|
||||
@doxygen Doxyfile
|
||||
docs:
|
||||
@CITRO3D_VERSION=$(VERSION) CTRU_DOCPATH="https://libctru.devkitpro.org/" doxygen Doxyfile
|
||||
|
||||
dist-bin: all
|
||||
@tar --exclude=*~ -cjf citro3d-$(VERSION).tar.bz2 include lib
|
||||
|
@ -1,6 +1,11 @@
|
||||
/**
|
||||
* @file attribs.h
|
||||
* @brief Configure vertex attributes
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
/// Vertex attribute info
|
||||
typedef struct
|
||||
{
|
||||
u32 flags[2];
|
||||
@ -8,9 +13,44 @@ typedef struct
|
||||
int attrCount;
|
||||
} C3D_AttrInfo;
|
||||
|
||||
/**
|
||||
* @brief Resets and initializes \ref C3D_AttrInfo structure to default values.
|
||||
* @param[out] info Pointer to attribute info structure.
|
||||
*/
|
||||
void AttrInfo_Init(C3D_AttrInfo* info);
|
||||
|
||||
/**
|
||||
* @brief Defines an array of vertex attribute data.
|
||||
* @note The attribute index returned should be the same as the order used
|
||||
* when specifying \ref AttrInfo_AddLoader() and \ref AttrInfo_AddFixed().
|
||||
* @param[out] info Attribute info structure.
|
||||
* @param[in] regId Specifies the attribute register in the vertex shader that will be modified.
|
||||
* @param[in] format Specifies the data type of the array.
|
||||
* @param[in] count Specifies the length of the array.
|
||||
* @return Attribute index if successful, negative value on failure.
|
||||
*/
|
||||
int AttrInfo_AddLoader(C3D_AttrInfo* info, int regId, GPU_FORMATS format, int count);
|
||||
|
||||
/**
|
||||
* @brief Defines a fixed vertex attribute.
|
||||
* @note The attribute index returned should be the same as the order used
|
||||
* when specifying \ref AttrInfo_AddLoader() and \ref AttrInfo_AddFixed().
|
||||
* @param[out] info Attribute info structure.
|
||||
* @param[in] regId Specifies the attribute register in the vertex shader that will be modified.
|
||||
* @return Attribute index if successful, negative value on failure.
|
||||
*/
|
||||
int AttrInfo_AddFixed(C3D_AttrInfo* info, int regId);
|
||||
|
||||
/**
|
||||
* @brief Gets pointer to the global \ref C3D_AttrInfo structure.
|
||||
* @return Pointer to global \ref C3D_AttrInfo. This should not be freed.
|
||||
*/
|
||||
C3D_AttrInfo* C3D_GetAttrInfo(void);
|
||||
|
||||
/**
|
||||
* @brief Sets global \ref C3D_AttrInfo structure.
|
||||
* Copies values from the specified \ref C3D_AttrInfo structure to the
|
||||
* global \ref C3D_AttrInfo structure.
|
||||
* @param[in] info Pointer to user \ref C3D_AttrInfo.
|
||||
*/
|
||||
void C3D_SetAttrInfo(C3D_AttrInfo* info);
|
||||
|
@ -1,41 +1,152 @@
|
||||
/**
|
||||
* @file base.h
|
||||
* @brief Base citro3d functions
|
||||
*/
|
||||
#pragma once
|
||||
#include "buffers.h"
|
||||
#include "maths.h"
|
||||
|
||||
/// Default command buffer size
|
||||
#define C3D_DEFAULT_CMDBUF_SIZE 0x40000
|
||||
|
||||
/**
|
||||
* @brief Data type of indices for use with \ref C3D_DrawElements().
|
||||
*/
|
||||
enum
|
||||
{
|
||||
C3D_UNSIGNED_BYTE = 0,
|
||||
C3D_UNSIGNED_SHORT = 1,
|
||||
C3D_UNSIGNED_BYTE = 0, ///< Unsigned 8-bit integer
|
||||
C3D_UNSIGNED_SHORT = 1, ///< Unsigned 16-bit integer
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initializes citro3d.
|
||||
* @param[in] cmdBufSize Desired size of GPU command buffer. \ref C3D_DEFAULT_CMDBUF_SIZE should generally be used here.
|
||||
* @note If you have a particularly complex scene you might need to specify a larger \p cmdBufSize.
|
||||
* Conversely, you may want to decrease it if you're particularly concerned about memory consumption.
|
||||
* @return true if library was initialized successfully, false if there was an error.
|
||||
*/
|
||||
bool C3D_Init(size_t cmdBufSize);
|
||||
|
||||
/**
|
||||
* @brief Deinitializes citro3d
|
||||
* @sa C3D_Init()
|
||||
*/
|
||||
void C3D_Fini(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the current command buffer usage.
|
||||
* @return Fraction of command buffer used. (0.0f to 1.0f)
|
||||
*/
|
||||
float C3D_GetCmdBufUsage(void);
|
||||
|
||||
/**
|
||||
* @brief Binds a shader program to the current rendering state.
|
||||
* @param[in] program Specifies the pointer to a shader program object whose executables are to be used
|
||||
* as part of the current rendering state.
|
||||
*/
|
||||
void C3D_BindProgram(shaderProgram_s* program);
|
||||
|
||||
/**
|
||||
* @brief Sets the viewport for the current framebuffer.
|
||||
* @note This function is called by \ref C3D_FrameDrawOn(). (using values specified by \ref C3D_RenderTargetCreate())
|
||||
* @note When using this with a rendertarget intended for display, keep in mind the orientation of the screens.
|
||||
* @param[in] x X offset from the origin of the viewport in pixels.
|
||||
* @param[in] y Y offset from the origin of the viewport in pixels.
|
||||
* @param[in] w Width of the viewport in pixels.
|
||||
* @param[in] h Height of the viewport in pixels.
|
||||
*/
|
||||
void C3D_SetViewport(u32 x, u32 y, u32 w, u32 h);
|
||||
|
||||
/**
|
||||
* @brief Defines the scissor box.
|
||||
* @note When using this with a rendertarget intended for display, keep in mind the orientation of the screens.
|
||||
* @param[in] mode Specifies scissoring mode.
|
||||
* @param[in] left Leftmost boundary in pixels.
|
||||
* @param[in] top Topmost boundary in pixels.
|
||||
* @param[in] right Rightmost boundary in pixels.
|
||||
* @param[in] bottom Bottommost boundary in pixels.
|
||||
*/
|
||||
void C3D_SetScissor(GPU_SCISSORMODE mode, u32 left, u32 top, u32 right, u32 bottom);
|
||||
|
||||
/**
|
||||
* @brief Renders primitives from current vertex array buffer.
|
||||
* @param[in] primitive Specifies what kind of primitives to render.
|
||||
* @param[in] first Specifies the starting index in the current buffers.
|
||||
* @param[in] size Specifies the number of indices to be rendered.
|
||||
*/
|
||||
void C3D_DrawArrays(GPU_Primitive_t primitive, int first, int size);
|
||||
|
||||
/**
|
||||
* @brief Renders primitives from current vertex array buffer in a manually specified order.
|
||||
* @param[in] primitive Specifies what kind of primitives to render.
|
||||
* @param[in] count Specifies the number of indices to be rendered.
|
||||
* @param[in] type Specifies the data type of the indices.
|
||||
* May be \ref C3D_UNSIGNED_BYTE or \ref C3D_UNSIGNED_SHORT.
|
||||
* @param[in] indices Specifies a pointer to where the indices are stored.
|
||||
*/
|
||||
void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void* indices);
|
||||
|
||||
// Immediate-mode vertex submission
|
||||
/**
|
||||
* @name Immediate-mode vertex submission
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Delimits the vertices of a primitive or a group of like primitives.
|
||||
* @param[in] primitive Specifies type of primitive or primitives that will be created
|
||||
* using the vertices specified between \ref C3D_ImmDrawBegin() and \ref C3D_ImmDrawEnd().
|
||||
*/
|
||||
void C3D_ImmDrawBegin(GPU_Primitive_t primitive);
|
||||
|
||||
/**
|
||||
* @brief Specifies an immediate attribute.
|
||||
* @note Attributes must be specified in the same order they were specified using \ref AttrInfo_AddLoader().
|
||||
* @param[in] x Specifies the X value of the current attribute.
|
||||
* @param[in] y Specifies the Y value of the current attribute.
|
||||
* @param[in] z Specifies the Z value of the current attribute.
|
||||
* @param[in] w Specifies the W value of the current attribute.
|
||||
*/
|
||||
void C3D_ImmSendAttrib(float x, float y, float z, float w);
|
||||
|
||||
/**
|
||||
* @brief Delimits the vertices of a primitive or a group of like primitives.
|
||||
* @sa C3D_ImmDrawBegin()
|
||||
*/
|
||||
void C3D_ImmDrawEnd(void);
|
||||
|
||||
/**
|
||||
* @brief Specifies the end of the previous strip/fan and the beginning of a new one.
|
||||
* @sa C3D_ImmDrawBegin()
|
||||
*/
|
||||
static inline void C3D_ImmDrawRestartPrim(void)
|
||||
{
|
||||
GPUCMD_AddWrite(GPUREG_RESTART_PRIMITIVE, 1);
|
||||
}
|
||||
/** @} */
|
||||
|
||||
// Fixed vertex attributes
|
||||
/**
|
||||
* @name Fixed vertex attributes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gets the pointer to the fixed attribute vector for the specified attribute index.
|
||||
* @param[in] id Attribute index.
|
||||
* @return Pointer to the fixed attribute vector for the current attribute.
|
||||
* @sa C3D_FixedAttribSet()
|
||||
*/
|
||||
C3D_FVec* C3D_FixedAttribGetWritePtr(int id);
|
||||
|
||||
/**
|
||||
* @brief Sets fixed attribute vector for the specified attribute index.
|
||||
* @note The attribute index should be the same as returned by \ref AttrInfo_AddFixed().
|
||||
* @param[in] id Attribute index.
|
||||
* @param[in] x Specifies the X value of the attribute.
|
||||
* @param[in] y Specifies the Y value of the attribute.
|
||||
* @param[in] z Specifies the Z value of the attribute.
|
||||
* @param[in] w Specifies the W value of the attribute.
|
||||
*/
|
||||
static inline void C3D_FixedAttribSet(int id, float x, float y, float z, float w)
|
||||
{
|
||||
C3D_FVec* ptr = C3D_FixedAttribGetWritePtr(id);
|
||||
@ -44,3 +155,4 @@ static inline void C3D_FixedAttribSet(int id, float x, float y, float z, float w
|
||||
ptr->z = z;
|
||||
ptr->w = w;
|
||||
}
|
||||
/** @} */
|
||||
|
@ -1,12 +1,18 @@
|
||||
/**
|
||||
* @file buffers.h
|
||||
* @brief Configure vertex array buffers
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
/// Vertex buffer config
|
||||
typedef struct
|
||||
{
|
||||
u32 offset;
|
||||
u32 flags[2];
|
||||
} C3D_BufCfg;
|
||||
|
||||
/// Vertex buffer info
|
||||
typedef struct
|
||||
{
|
||||
u32 base_paddr;
|
||||
@ -14,8 +20,38 @@ typedef struct
|
||||
C3D_BufCfg buffers[12];
|
||||
} C3D_BufInfo;
|
||||
|
||||
/**
|
||||
* @brief Resets and initializes \ref C3D_BufInfo structure to default values.
|
||||
* @param[out] info Pointer to vertex buffer info structure.
|
||||
*/
|
||||
void BufInfo_Init(C3D_BufInfo* info);
|
||||
|
||||
/**
|
||||
* @brief Adds a buffer to the vertex buffer info struct.
|
||||
* @note The attribute indices specified in \p permutation should be the same as the ones returned by \ref AttrInfo_AddLoader()
|
||||
* @param[out] info Pointer to a \ref C3D_BufInfo struct.
|
||||
* @param[in] data Pointer to buffer.
|
||||
* @param[in] stride Distance in bytes between vertex entries in the buffer (usually set to the size of the vertex structure).
|
||||
* @param[in] attribCount Number of attributes to load from this buffer.
|
||||
* @param[in] permutation Specifies the order of attributes in the buffer. Each attribute index is a nibble (4 bits), and they are ordered from least significant to most significant.
|
||||
* Padding can be specified with 0xC, 0xD, 0xE and 0xF. (See https://3dbrew.org/wiki/GPU/Internal_Registers#GPUREG_ATTRIBBUFFERi_CONFIG1 for more info)
|
||||
* @remark Using this, one can rearrange the positions of attributes in the struct.
|
||||
* For example, with three attributes in this buffer, setting this to 0x210 would configure the permutation to be the first attribute index,
|
||||
* then the second, then the third. 0x120 would configure the permutation to be the first attribute index, then the third, then the second.
|
||||
* @return Buffer index if successful, negative value on failure.
|
||||
*/
|
||||
int BufInfo_Add(C3D_BufInfo* info, const void* data, ptrdiff_t stride, int attribCount, u64 permutation);
|
||||
|
||||
/**
|
||||
* @brief Gets pointer to the global \ref C3D_BufInfo structure.
|
||||
* @return Pointer to \ref C3D_BufInfo. This should not be freed.
|
||||
*/
|
||||
C3D_BufInfo* C3D_GetBufInfo(void);
|
||||
|
||||
/**
|
||||
* @brief Sets global \ref C3D_BufInfo structure.
|
||||
* Copies values from the specified \ref C3D_BufInfo structure to the
|
||||
* global \ref C3D_BufInfo structure.
|
||||
* @param[in] info Pointer to user \ref C3D_BufInfo.
|
||||
*/
|
||||
void C3D_SetBufInfo(C3D_BufInfo* info);
|
||||
|
@ -1,15 +1,92 @@
|
||||
/**
|
||||
* @file effect.h
|
||||
* @brief Configure GPU state
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @brief Specifies mapping of depth values from normalized device coordinates to window coordinates.
|
||||
* @param[in] bIsZBuffer Enables or disables depth range. The initial value is true.
|
||||
* @param[in] zScale Specifies mapping of depth values from normalized device coordinates to window coordinates (nearVal - farVal). The initial value is -1.0f.
|
||||
* @param[in] zOffset Sets the scale and units used to calculate depth values (nearVal + polygonOffset). The initial value is 0.0f.
|
||||
*/
|
||||
void C3D_DepthMap(bool bIsZBuffer, float zScale, float zOffset);
|
||||
|
||||
/**
|
||||
* @brief Specifies whether front-facing or back-facing facets can be culled.
|
||||
* @param[in] mode Specifies whether front-facing, back-facing, or no facets are candidates for culling. The inital value is \ref GPU_CULL_BACK_CCW.
|
||||
*/
|
||||
void C3D_CullFace(GPU_CULLMODE mode);
|
||||
|
||||
/**
|
||||
* @brief Sets front and back function and reference value for stencil testing
|
||||
* @param[in] enable Enables or disables stencil test. The initial value is false.
|
||||
* @param[in] function Specifies the test function. The initial value is \ref GPU_ALWAYS.
|
||||
* @param[in] ref Specifies the reference value for the stencil test. ref is clamped to the range 02^n - 1 , where n is the number of bitplanes in the stencil buffer. The initial value is 0.
|
||||
* @param[in] inputMask Specifies a mask that is ANDed with both the reference value and the stored stencil value when the test is done. The initial value is all 1's.
|
||||
* @param[in] writeMask Specifies a bit mask to enable and disable writing of individual bits in the stencil planes. Initially, the mask is all 0's.
|
||||
*/
|
||||
void C3D_StencilTest(bool enable, GPU_TESTFUNC function, int ref, int inputMask, int writeMask);
|
||||
|
||||
/**
|
||||
* @brief Sets front and back stencil test actions
|
||||
* @param[in] sfail Specifies the action to take when the stencil test fails. The initial value is \ref GPU_STENCIL_KEEP.
|
||||
* @param[in] dfail Specifies the stencil action when the stencil test passes, but the depth test fails. The initial value is \ref GPU_STENCIL_KEEP.
|
||||
* @param[in] pass Specifies the stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled. The initial value is \ref GPU_STENCIL_KEEP.
|
||||
*/
|
||||
void C3D_StencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass);
|
||||
|
||||
/**
|
||||
* @brief Sets the blend color
|
||||
* @param[in] color Specifies the RGBA blend color. The initial value is 0.
|
||||
*/
|
||||
void C3D_BlendingColor(u32 color);
|
||||
|
||||
void C3D_EarlyDepthTest(bool enable, GPU_EARLYDEPTHFUNC function, u32 ref);
|
||||
|
||||
/**
|
||||
* @brief Configures depth testing options.
|
||||
* @note Setting the enable parameter to false will not also disable depth writes. It will instead behave as if the depth function were set to \ref GPU_ALWAYS. To completely disable depth-related operations, the enable parameter must be false, and the writemask should be \ref GPU_WRITE_COLOR.
|
||||
* @param[in] enable If true, do depth comparisons on the outgoing fragments and write to the depth buffer. The initial value is true.
|
||||
* @param[in] function Specifies the depth comparison function. The initial value is \ref GPU_GREATER.
|
||||
* @param[in] writemask Configures buffer writemasks for the depth test stage. The initial value is \ref GPU_WRITE_ALL.
|
||||
*/
|
||||
void C3D_DepthTest(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask);
|
||||
|
||||
/**
|
||||
* @brief Configures Alpha testing
|
||||
* @param[in] enable Enables or disables alpha test. The initial value is false.
|
||||
* @param[in] function Specifies the alpha comparison function. The initial value is \ref GPU_ALWAYS.
|
||||
* @param[in] ref Specifies the reference value that incoming alpha values are compared to from 0 to 0xFF. The intial value is 0.
|
||||
*/
|
||||
void C3D_AlphaTest(bool enable, GPU_TESTFUNC function, int ref);
|
||||
|
||||
/**
|
||||
* @brief Configures blend functions
|
||||
* @note This causes LogicOp settings to be ignored, LogicOp and alpha blending cannot be used simultaneously.
|
||||
* @param[in] colorEq Specifies how source and destination colors are combined. The initial value is \ref GPU_BLEND_ADD.
|
||||
* @param[in] alphaEq Specifies how source and destination alphas are combined. The initial value is \ref GPU_BLEND_ADD.
|
||||
* @param[in] srcClr Specifies how the red, green, and blue source blending factors are computed. The initial value is \ref GPU_SRC_ALPHA.
|
||||
* @param[in] dstClr Specifies how the red, green, and blue destination blending factors are computed. The initial value is \ref GPU_ONE_MINUS_SRC_ALPHA.
|
||||
* @param[in] srcAlpha Specifies how the alpha source blending factors are computed. The initial value is \ref GPU_SRC_ALPHA.
|
||||
* @param[in] dstAlpha Specifies how the alpha destination blending factors are computed. The initial value is \ref GPU_ONE_MINUS_SRC_ALPHA.
|
||||
*/
|
||||
void C3D_AlphaBlend(GPU_BLENDEQUATION colorEq, GPU_BLENDEQUATION alphaEq, GPU_BLENDFACTOR srcClr, GPU_BLENDFACTOR dstClr, GPU_BLENDFACTOR srcAlpha, GPU_BLENDFACTOR dstAlpha);
|
||||
|
||||
/**
|
||||
* @brief Configures logical pixel write operation during rendering
|
||||
* @note This resets existing alpha blending settings, LogicOp and alpha blending cannot be used simultaneously.
|
||||
* @param[in] op Operation to perform when writing incomming pixels to existing framebuffer.
|
||||
*/
|
||||
void C3D_ColorLogicOp(GPU_LOGICOP op);
|
||||
|
||||
/**
|
||||
* @brief Configures fragment writing mode.
|
||||
* @note When using \ref GPU_FRAGOPMODE_SHADOW, the secondary depth stencil texture must be disabled.
|
||||
* @param[in] mode Mode used for writing fragments. \ref GPU_FRAGOPMODE_GL enables standard color/depth rendering,
|
||||
* \ref GPU_FRAGOPMODE_SHADOW enables writes color fragments as a D24X shadow depthmap (treated as RGBA8).
|
||||
*/
|
||||
void C3D_FragOpMode(GPU_FRAGOPMODE mode);
|
||||
|
||||
void C3D_FragOpShadow(float scale, float bias);
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @file framebuffer.h
|
||||
* @brief Process render target framebuffer
|
||||
*/
|
||||
#pragma once
|
||||
#include "texture.h"
|
||||
|
||||
@ -14,23 +18,79 @@ typedef struct
|
||||
u8 depthMask : 4;
|
||||
} C3D_FrameBuf;
|
||||
|
||||
// Flags for C3D_FrameBufClear
|
||||
/// Flags for C3D_FrameBufClear
|
||||
typedef enum
|
||||
{
|
||||
C3D_CLEAR_COLOR = BIT(0),
|
||||
C3D_CLEAR_DEPTH = BIT(1),
|
||||
C3D_CLEAR_ALL = C3D_CLEAR_COLOR | C3D_CLEAR_DEPTH,
|
||||
C3D_CLEAR_COLOR = BIT(0), ///< Clear the color buffer.
|
||||
C3D_CLEAR_DEPTH = BIT(1), ///< Clear the the depth/stencil buffer.
|
||||
C3D_CLEAR_ALL = C3D_CLEAR_COLOR | C3D_CLEAR_DEPTH, ///< Clear both buffers
|
||||
} C3D_ClearBits;
|
||||
|
||||
/**
|
||||
* @brief Calculates the size of a color buffer.
|
||||
* @param[in] width Width of the color buffer in pixels.
|
||||
* @param[in] height Height of the color buffer in pixels.
|
||||
* @param[in] fmt Format of the color buffer.
|
||||
* @return Calculated color buffer size.
|
||||
*/
|
||||
u32 C3D_CalcColorBufSize(u32 width, u32 height, GPU_COLORBUF fmt);
|
||||
|
||||
/**
|
||||
* @brief Calculates the size of a depth buffer.
|
||||
* @param[in] width Width of the depth buffer in pixels.
|
||||
* @param[in] height Height of the depth buffer in pixels.
|
||||
* @param[in] fmt Format of the depth buffer.
|
||||
* @return Calculated depth buffer size.
|
||||
*/
|
||||
u32 C3D_CalcDepthBufSize(u32 width, u32 height, GPU_DEPTHBUF fmt);
|
||||
|
||||
/**
|
||||
* @brief Returns global citro3d framebuffer structure.
|
||||
* @return Pointer to \ref C3D_FrameBuf struct.
|
||||
*/
|
||||
C3D_FrameBuf* C3D_GetFrameBuf(void);
|
||||
|
||||
/**
|
||||
* @brief Sets global citro3d framebuffer structure.
|
||||
* @param[in] fb Pointer to \ref C3D_FrameBuf struct.
|
||||
*/
|
||||
void C3D_SetFrameBuf(C3D_FrameBuf* fb);
|
||||
|
||||
/**
|
||||
* @brief Binds a texture to a framebuffer. This texture will be used as the color buffer.
|
||||
* @param[out] fb Pointer to \ref C3D_FrameBuf struct.
|
||||
* @param[in] tex Pointer to \ref C3D_Tex struct.
|
||||
* @param[in] face Specifies face of cubemap to be used (ignored if it is a 2D texture)
|
||||
* @param[in] level Specifies mipmap level. 0 is the original image, 1 is the first mipmap, and so on.
|
||||
* @remark This calls \ref C3D_FrameBufColor with the proper arguments for the buffer of the texture.
|
||||
*/
|
||||
void C3D_FrameBufTex(C3D_FrameBuf* fb, C3D_Tex* tex, GPU_TEXFACE face, int level);
|
||||
|
||||
/**
|
||||
* @brief Sets the clear bits and color for a framebuffer.
|
||||
* @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
|
||||
* @param[in] clearBits Specifies which buffers to clear. (see \ref C3D_ClearBits)
|
||||
* @param[in] clearColor 32 bit RGBA value to clear the color buffer with.
|
||||
* @param[in] clearDepth Value to clear the depth buffer with.
|
||||
*/
|
||||
void C3D_FrameBufClear(C3D_FrameBuf* fb, C3D_ClearBits clearBits, u32 clearColor, u32 clearDepth);
|
||||
|
||||
/**
|
||||
* @brief Transfers a framebuffer to the LCD display.
|
||||
* @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
|
||||
* @param[in] screen Screen to transfer the framebuffer to.
|
||||
* @param[in] side Side of the screen to transfer the framebuffer to (unused for the bottom screen)
|
||||
* @param[in] transferFlags Specifies GX_TRANSFER bitflags.
|
||||
*/
|
||||
void C3D_FrameBufTransfer(C3D_FrameBuf* fb, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags);
|
||||
|
||||
/**
|
||||
* @brief Sets framebuffer attributes.
|
||||
* @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
|
||||
* @param[in] width Width of framebuffer in pixels.
|
||||
* @param[in] height Height of framebuffer in pixels.
|
||||
* @param[in] block32 Specifies if using 32x32 tile format.
|
||||
*/
|
||||
static inline void C3D_FrameBufAttrib(C3D_FrameBuf* fb, u16 width, u16 height, bool block32)
|
||||
{
|
||||
fb->width = width;
|
||||
@ -38,6 +98,12 @@ static inline void C3D_FrameBufAttrib(C3D_FrameBuf* fb, u16 width, u16 height, b
|
||||
fb->block32 = block32;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns a color buffer to a framebuffer.
|
||||
* @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
|
||||
* @param[in] buf Pointer to the buffer to use.
|
||||
* @param[in] fmt Format of the color buffer.
|
||||
*/
|
||||
static inline void C3D_FrameBufColor(C3D_FrameBuf* fb, void* buf, GPU_COLORBUF fmt)
|
||||
{
|
||||
if (buf)
|
||||
@ -53,6 +119,13 @@ static inline void C3D_FrameBufColor(C3D_FrameBuf* fb, void* buf, GPU_COLORBUF f
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns a depth buffer to a framebuffer.
|
||||
* @param[in] fb Pointer to a \ref C3D_FrameBuf struct.
|
||||
* @param[in] buf Pointer to the buffer to use.
|
||||
* @param[in] fmt Format of the depth buffer.
|
||||
* @note Depending on the format chosen, this may be used as a stencil buffer as well.
|
||||
*/
|
||||
static inline void C3D_FrameBufDepth(C3D_FrameBuf* fb, void* buf, GPU_DEPTHBUF fmt)
|
||||
{
|
||||
if (buf)
|
||||
|
@ -1,23 +1,71 @@
|
||||
/**
|
||||
* @file light.h
|
||||
* @brief Configure dynamic light, shading, and shadows
|
||||
*
|
||||
* \section frag_eqn Fragment Light Equations
|
||||
* The equations used for calculating fragment lighting appears to be as follows:
|
||||
*
|
||||
* \f[ C_{pri} = s^{(a)} + \sum_{i = 0}^{\#lights} a * SpotlightLut(d_0) * o * (l_i^{(d)} * f_i(L_i \cdot N) + l_i^{(a)}) \f]
|
||||
* \f[ C_{sec} = \sum_{i = 0}^{\#lights} a * SpotlightLut(d_0) * h * o * (l_i^{(s_0)}LutD_0(d_1)*G_i^{(0)} + l_i^{(s_1)}LutD_1(d_3)*G_i^{(1)}*ReflectionLutsRGB(d_2)) \f]
|
||||
* \f[ C_{alpha} = FresnelLut(d_4) \f]
|
||||
*
|
||||
* Outputs:
|
||||
* - \f$C_{pri}\f$ - \ref GPU_FRAGMENT_PRIMARY_COLOR
|
||||
* - \f$C_{sec}\f$ - \ref GPU_FRAGMENT_SECONDARY_COLOR
|
||||
* - \f$C_{alpha}\f$ - Primary and/or secondary alpha. Output is selectable using \ref C3D_LightEnvFresnel().
|
||||
*
|
||||
* Inputs, per-fragment:
|
||||
* - \f$a\f$ - Distance attenuation factor calculated from distance attenuation LUT.
|
||||
* - \f$N\f$ - Interpolated normal
|
||||
* - \f$V\f$ - View direction vector (fragment <-> camera)
|
||||
* - \f$T\f$ - Tangent direction vector
|
||||
*
|
||||
* Inputs, per-pass:
|
||||
* - \f$d_{0...4}\f$ - Configurable LUT inputs - one of the following: \f$N \cdot H\f$, \f$V \cdot H_i\f$, \f$N \cdot V\f$, \f$L_i \cdot N\f$, \f$-L_i \cdot P\f$, \f$\cos \phi_i\f$.
|
||||
* - \f$s^{(a)}\f$ - Scene ambient color
|
||||
* - \f$o\f$ - Shadow attenuation from the shadow map (if there is one). Output is selectable using \ref C3D_LightEnvShadowMode().
|
||||
* - \f$h\f$ - Clamps lighting for \f$N \cdot L_i < 0\f$ if \ref C3D_LightEnvClampHighlights() is enabled
|
||||
*
|
||||
* Inputs, per-Light:
|
||||
* - \f$P_i\f$ - Spotlight direction
|
||||
* - \f$L_i\f$ - Light vector (just lightPosition when positional lighting is enabled, lightPosition + view when directional lighting is enabled)
|
||||
* - \f$H_i\f$ - Half-vector between \f$L_i\f$ and \f$V\f$
|
||||
* - \f$\phi_i\f$ - Angle between the projection of \f$H_i\f$ into the tangent plane and \f$T\f$
|
||||
* - \f$f_i\f$ - Clamps product of \f$N \cdot L_i\f$ to zero if \ref C3D_LightTwoSideDiffuse() is disabled for the light source, otherwise gets the absolute value
|
||||
* - \f$l_i^{(a)}\f$ - Light ambient color
|
||||
* - \f$l_i^{(d)}\f$ - Light diffuse color
|
||||
* - \f$l_i^{(s_0)}\f$ - Light specular0 color
|
||||
* - \f$l_i^{(s_1)}\f$ - Light specular1 color
|
||||
* - \f$G_i^{(0)},G_i^{(1)}\f$ - Cook-Torrance geometric factor, or 1 when disabled
|
||||
*
|
||||
* In citro3d, some inputs may be configured by multiple variables, for example:
|
||||
* - \f$s^{(a)}\f$ = mtl.emission + mtl.ambient * env.ambient
|
||||
* - \f$l_i^{(a)}\f$ = mtl.ambient * light.ambient
|
||||
* - \f$l_i^{(d)}\f$ = mtl.diffuse * light.diffuse
|
||||
* - \f$l_i^{(s_0)}\f$ = mtl.specular0 * light.specular0
|
||||
* - \f$l_i^{(s_1)}\f$ = mtl.specular1 * light.specular1
|
||||
*
|
||||
* \sa https://github.com/PabloMK7/citra/blob/baca2bfc6bd0af97ce74b911d69af2391815c9d7/src/video_core/renderer_software/sw_lighting.cpp#L26-L332
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "lightlut.h"
|
||||
#include "maths.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Material
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Material
|
||||
typedef struct
|
||||
{
|
||||
float ambient[3];
|
||||
float diffuse[3];
|
||||
float specular0[3];
|
||||
float specular1[3];
|
||||
float emission[3];
|
||||
float ambient[3]; ///< Color used for global illumination for the material, multiplied by \ref C3D_LightEnvAmbient()
|
||||
float diffuse[3]; ///< Color used when calculating directional lighting
|
||||
float specular0[3]; ///< Specular color, multiplied by lutD0
|
||||
float specular1[3]; ///< Specular color, multiplied by lutD1
|
||||
float emission[3]; ///< Color used for global illumination for the material, added to the product of the ambient illumination
|
||||
} C3D_Material;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Light environment
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @name Light Environment
|
||||
* @{
|
||||
*/
|
||||
|
||||
// Forward declarations
|
||||
typedef struct C3D_Light_t C3D_Light;
|
||||
@ -59,11 +107,52 @@ struct C3D_LightEnv_t
|
||||
C3D_Material material;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Resets and initializes \ref C3D_LightEnv structure to default values.
|
||||
* @note Using fragment lighting without at least one light source configured and enabled
|
||||
* may result in undefined behavior.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @return Light id on success, negative on failure.
|
||||
* @sa \ref C3D_LightInit()
|
||||
* @sa \ref frag_eqn
|
||||
*/
|
||||
void C3D_LightEnvInit(C3D_LightEnv* env);
|
||||
|
||||
/**
|
||||
* @brief Binds \ref C3D_LightEnv pointer to be used for configuring internal state.
|
||||
* @param[in] env Pointer to light environment structure or NULL to disable the fragment lighting stage altogether.
|
||||
*/
|
||||
void C3D_LightEnvBind(C3D_LightEnv* env);
|
||||
|
||||
/**
|
||||
* @brief Coppies material properties to \ref C3D_LightEnv.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] mtl Pointer to material properties structure.
|
||||
*/
|
||||
void C3D_LightEnvMaterial(C3D_LightEnv* env, const C3D_Material* mtl);
|
||||
|
||||
/**
|
||||
* @brief Sets global ambient lighting.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] r Red component.
|
||||
* @param[in] g Green component.
|
||||
* @param[in] b Blue component.
|
||||
*/
|
||||
void C3D_LightEnvAmbient(C3D_LightEnv* env, float r, float g, float b);
|
||||
|
||||
/**
|
||||
* @brief Uploads pre-calculated lighting lookup table for specified function.
|
||||
* @note For the full lighting equation see the \ref frag_eqn section.
|
||||
* This is used to calculate the values of \ref GPU_FRAGMENT_PRIMARY_COLOR
|
||||
* and \ref GPU_FRAGMENT_SECONDARY_COLOR.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] lutId Specify function of the lookup table.
|
||||
* @param[in] input Specify arguments of the function.
|
||||
* @param[in] negative If true, the LUT inputs can be read as positive or negative, if false the absolute value of the lut inputs will be used.
|
||||
* @param[in] lut Pointer to pre-computed lookup table, or NULL to disable the function.
|
||||
* @sa \ref LightLut_FromArray()
|
||||
* @sa \ref LightLut_FromFunc()
|
||||
*/
|
||||
void C3D_LightEnvLut(C3D_LightEnv* env, GPU_LIGHTLUTID lutId, GPU_LIGHTLUTINPUT input, bool negative, C3D_LightLut* lut);
|
||||
|
||||
enum
|
||||
@ -74,24 +163,71 @@ enum
|
||||
GPU_SHADOW_ALPHA = BIT(19),
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enables or disables writing fresnel and shadow alpha component to \ref GPU_FRAGMENT_PRIMARY_COLOR and \ref GPU_FRAGMENT_SECONDARY_COLOR.
|
||||
* @param[out] env Light environment.
|
||||
* @param[in] selector Output selector, or \ref GPU_NO_FRESNEL to disable writing the alpha
|
||||
* component to both \ref GPU_FRAGMENT_PRIMARY_COLOR and \ref GPU_FRAGMENT_SECONDARY_COLOR.
|
||||
* @sa \ref frag_eqn
|
||||
*/
|
||||
void C3D_LightEnvFresnel(C3D_LightEnv* env, GPU_FRESNELSEL selector);
|
||||
|
||||
/**
|
||||
* @brief Configures bump map texture properties.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] mode Bump map type. Use \ref GPU_BUMP_AS_BUMP to specify normal map,
|
||||
* use \ref GPU_BUMP_AS_TANG to specify tangent map, or use \ref GPU_BUMP_NOT_USED to disable bump mapping.
|
||||
* @sa C3D_LightEnvBumpSel()
|
||||
*/
|
||||
void C3D_LightEnvBumpMode(C3D_LightEnv* env, GPU_BUMPMODE mode);
|
||||
|
||||
/**
|
||||
* @brief Configures bump map texture unit id.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] texUnit Id of texture unit the bump texture is bound to (IDs 0 through 2).
|
||||
* @sa C3D_LightEnvBumpMode()
|
||||
* @sa C3D_TexBind()
|
||||
*/
|
||||
void C3D_LightEnvBumpSel(C3D_LightEnv* env, int texUnit);
|
||||
|
||||
/**
|
||||
* @brief Configures whether to use the z component of the normal map.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] enable false if the z component is reconstructed from the xy components
|
||||
* of the normal map, true if the z component is taken from the normal map.
|
||||
* @param[in] enable true enables using the z component from the normal map,
|
||||
* false enables z component reconstruction from the xy components of the normal map.
|
||||
*/
|
||||
void C3D_LightEnvBumpNormalZ(C3D_LightEnv *env, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Configures shadow mapping behavior.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] mode One or more of the following bitflags, \ref GPU_SHADOW_PRIMARY,
|
||||
* \ref GPU_SHADOW_SECONDARY, \ref GPU_INVERT_SHADOW, and \ref GPU_SHADOW_ALPHA.
|
||||
*/
|
||||
void C3D_LightEnvShadowMode(C3D_LightEnv* env, u32 mode);
|
||||
|
||||
/**
|
||||
* @brief Configures shadow mapping texture.
|
||||
* @note Shadow depth textures must be assigned to texture unit 0.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] texUnit Id of texture unit the shadow texture is bound to (IDs 0 through 2).
|
||||
*/
|
||||
void C3D_LightEnvShadowSel(C3D_LightEnv* env, int texUnit);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables clamping specular highlights.
|
||||
* @param[out] env Pointer to light environment structure.
|
||||
* @param[in] clamp true to enable clamping specular highlights based on the normal vector,
|
||||
* false to disable clamping specular highlights.
|
||||
*/
|
||||
void C3D_LightEnvClampHighlights(C3D_LightEnv* env, bool clamp);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Light
|
||||
//-----------------------------------------------------------------------------
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Light
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -133,25 +269,143 @@ struct C3D_Light_t
|
||||
C3D_LightConf conf;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Adds light to \ref C3D_LightEnv.
|
||||
* @note Only 8 lights can be configured simultaneously.
|
||||
* @param[in] light Light struct to add to light environment.
|
||||
* @param[out] env Light environment.
|
||||
* @return Light id on success, negative on failure.
|
||||
* @sa \ref frag_eqn
|
||||
*/
|
||||
int C3D_LightInit(C3D_Light* light, C3D_LightEnv* env);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables light source.
|
||||
* @note At least one light source must be enabled at all times. Disabling all
|
||||
* light sources will result in undefined behavior.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] enable true to enable light source, false to disable light source.
|
||||
*/
|
||||
void C3D_LightEnable(C3D_Light* light, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] enable true to enable two sided lighting (illuminates both the inside and outside of a mesh),
|
||||
* false to disable two sided lighting.
|
||||
*/
|
||||
void C3D_LightTwoSideDiffuse(C3D_Light* light, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables cock-torrance geometric factor.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] id Geometric factor id. (0 or 1)
|
||||
* @param[in] enable true to enable geometric factor id, false to disable it.
|
||||
*/
|
||||
void C3D_LightGeoFactor(C3D_Light* light, int id, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Configures global ambient color emitted by light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] r Red component.
|
||||
* @param[in] g Green component.
|
||||
* @param[in] b Blue component.
|
||||
*/
|
||||
void C3D_LightAmbient(C3D_Light* light, float r, float g, float b);
|
||||
|
||||
/**
|
||||
* @brief Configures diffuse lighting color emitted by light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] r Red component.
|
||||
* @param[in] g Green component.
|
||||
* @param[in] b Blue component.
|
||||
*/
|
||||
void C3D_LightDiffuse(C3D_Light* light, float r, float g, float b);
|
||||
|
||||
/**
|
||||
* @brief Configures specular0 lighting color emitted by light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] r Red component.
|
||||
* @param[in] g Green component.
|
||||
* @param[in] b Blue component.
|
||||
*/
|
||||
void C3D_LightSpecular0(C3D_Light* light, float r, float g, float b);
|
||||
|
||||
/**
|
||||
* @brief Configures specular1 lighting color emitted by light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] r Red component.
|
||||
* @param[in] g Green component.
|
||||
* @param[in] b Blue component.
|
||||
*/
|
||||
void C3D_LightSpecular1(C3D_Light* light, float r, float g, float b);
|
||||
|
||||
/**
|
||||
* @brief Configures light position vector.
|
||||
* @note The w-component of the position vector is a flag where
|
||||
* 0 specifies positional lighting and any other value specifies directional lighting.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] pos Position vector.
|
||||
*/
|
||||
void C3D_LightPosition(C3D_Light* light, C3D_FVec* pos);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables shadow mapping on light source.
|
||||
* @note The shadow mapping texture can be specified using \ref C3D_LightEnvShadowSel().
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] enable true to enable shadow mapping, false to disable shadow mapping.
|
||||
*/
|
||||
void C3D_LightShadowEnable(C3D_Light* light, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables spot light for specified light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] enable true to enable spot light, false to disable spot light.
|
||||
*/
|
||||
void C3D_LightSpotEnable(C3D_Light* light, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Configures spot light direction vector for specified light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] x X component.
|
||||
* @param[in] y Y component.
|
||||
* @param[in] z Z component.
|
||||
*/
|
||||
void C3D_LightSpotDir(C3D_Light* light, float x, float y, float z);
|
||||
|
||||
/**
|
||||
* @brief Configures spotlight lookup table.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] lut Pointer to pre-computed lighting lookup table.
|
||||
*/
|
||||
void C3D_LightSpotLut(C3D_Light* light, C3D_LightLut* lut);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables distance attenuation for specified light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] enable Enable distance attenuation factor for light source.
|
||||
*/
|
||||
void C3D_LightDistAttnEnable(C3D_Light* light, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Uploads pre-calculated distance attenuation lookup table for specified light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] lut Pointer to pre-computed distance attenuation lookup table.
|
||||
*/
|
||||
void C3D_LightDistAttn(C3D_Light* light, C3D_LightLutDA* lut);
|
||||
|
||||
/**
|
||||
* @brief Configures diffuse and specular0/1 color emitted by light source.
|
||||
* @param[out] light Light source structure.
|
||||
* @param[in] r Red component.
|
||||
* @param[in] g Green component.
|
||||
* @param[in] b Blue component.
|
||||
*/
|
||||
static inline void C3D_LightColor(C3D_Light* light, float r, float g, float b)
|
||||
{
|
||||
C3D_LightDiffuse(light, r, g, b);
|
||||
C3D_LightSpecular0(light, r, g, b);
|
||||
C3D_LightSpecular1(light, r, g, b);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @file lightlut.h
|
||||
* @brief Generate lighting lookup tables
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
#include <math.h>
|
||||
@ -26,10 +30,53 @@ static inline float spot_step(float angle, float cutoff)
|
||||
return angle >= cutoff ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generates lighting lookup table from pre-computed float array.
|
||||
* @param[out] lut Pointer to lighting lookup table structure.
|
||||
* @param[in] data Pointer to pre-computed float array.
|
||||
*/
|
||||
void LightLut_FromArray(C3D_LightLut* lut, float* data);
|
||||
|
||||
/**
|
||||
* @brief Generates lighting lookup table using specified callback function.
|
||||
* @param[out] lut Pointer to light environment structure.
|
||||
* @param[in] func Callback function.
|
||||
* @param[in] param User-specified parameter to callback function.
|
||||
* @param[in] negative If false, x argument of callback function will be in range [0,256]. If true, x argument will be in range [-128,128].
|
||||
*/
|
||||
void LightLut_FromFunc(C3D_LightLut* lut, C3D_LightLutFunc func, float param, bool negative);
|
||||
|
||||
/**
|
||||
* @brief Generates distance attenuation lookup table using specified callback function.
|
||||
* @param[out] lut Pointer to light environment structure.
|
||||
* @param[in] func Callback function.
|
||||
* @param[in] from Starting distance of lighting.
|
||||
* @param[in] to Ending distance of lighting.
|
||||
* @param[in] arg0 User-specified parameter to callback function.
|
||||
* @param[in] arg1 User-specified parameter to callback function.
|
||||
*/
|
||||
void LightLutDA_Create(C3D_LightLutDA* lut, C3D_LightLutFuncDA func, float from, float to, float arg0, float arg1);
|
||||
|
||||
/**
|
||||
* @brief Generates lighting lookup table using powf function (phong lighting).
|
||||
* @param[out] lut Pointer to light environment structure.
|
||||
* @param[in] shininess Shininess value of specular highlights (pow function exponent).
|
||||
*/
|
||||
#define LightLut_Phong(lut, shininess) LightLut_FromFunc((lut), powf, (shininess), false)
|
||||
|
||||
/**
|
||||
* @brief Generates lighting lookup table for spotlights.
|
||||
* @param[out] lut Pointer to light environment structure.
|
||||
* @param[in] angle Beam angle of the spotlight.
|
||||
*/
|
||||
#define LightLut_Spotlight(lut, angle) LightLut_FromFunc((lut), spot_step, cosf(angle), true)
|
||||
|
||||
/**
|
||||
* @brief Generates distance attenuation lookup table.
|
||||
* @param[out] lut Pointer to light environment structure.
|
||||
* @param[in] from Minimum distance from light source.
|
||||
* @param[in] to Maximum distance from light source.
|
||||
* @param[in] linear Linear coefficient.
|
||||
* @param[in] quad Quadratic coefficient.
|
||||
*/
|
||||
#define LightLutDA_Quadratic(lut, from, to, linear, quad) LightLutDA_Create((lut), quadratic_dist_attn, (from), (to), (linear), (quad))
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @file maths.h
|
||||
* @brief Basic math library for matrix, vector, and quaternion operations
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
#include <math.h>
|
||||
|
@ -1,6 +1,11 @@
|
||||
/**
|
||||
* @file renderqueue.h
|
||||
* @brief Set up rendertarget and render frame
|
||||
*/
|
||||
#pragma once
|
||||
#include "framebuffer.h"
|
||||
|
||||
/// Render target structure
|
||||
typedef struct C3D_RenderTarget_tag C3D_RenderTarget;
|
||||
|
||||
struct C3D_RenderTarget_tag
|
||||
@ -17,25 +22,80 @@ struct C3D_RenderTarget_tag
|
||||
u32 transferFlags;
|
||||
};
|
||||
|
||||
// Flags for C3D_FrameBegin
|
||||
/// Flags for C3D_FrameBegin
|
||||
enum
|
||||
{
|
||||
C3D_FRAME_SYNCDRAW = BIT(0), // Perform C3D_FrameSync before checking the GPU status
|
||||
C3D_FRAME_NONBLOCK = BIT(1), // Return false instead of waiting if the GPU is busy
|
||||
C3D_FRAME_SYNCDRAW = BIT(0), ///< Perform \ref C3D_FrameSync() before checking the GPU status
|
||||
C3D_FRAME_NONBLOCK = BIT(1), ///< Return false instead of waiting if the GPU is busy
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Specifies framerate cap.
|
||||
* Specifies target framerate for \ref C3D_FrameSync().
|
||||
* @param[in] fps Specifies the target framerate. Must be between 0.0 and 60.0 fps.
|
||||
* @return Previous framerate.
|
||||
*/
|
||||
float C3D_FrameRate(float fps);
|
||||
|
||||
/**
|
||||
* @brief Performs framerate limiting.
|
||||
* Waits for the required amount of vblanks specified by \ref C3D_FrameRate().
|
||||
* @note Used by \ref C3D_FrameBegin() when using \ref C3D_FRAME_SYNCDRAW.
|
||||
*/
|
||||
void C3D_FrameSync(void);
|
||||
|
||||
/**
|
||||
* @brief Returns total number of frames drawn.
|
||||
* @param[in] id Vblank frame counter id.
|
||||
* @return Total number of frames.
|
||||
*/
|
||||
u32 C3D_FrameCounter(int id);
|
||||
|
||||
/**
|
||||
* @brief Begins drawing frame.
|
||||
* @param[in] flags Specifies options for rendering; 0 or more flags may be provided.
|
||||
* \ref C3D_FRAME_SYNCDRAW specifies that \ref C3D_FrameSync() should be performed before checking the GPU status,
|
||||
* \ref C3D_FRAME_NONBLOCK specifies that the function should return false instead of waiting for GPU to be ready.
|
||||
* @return True if frame began successfully, otherwise false.
|
||||
*/
|
||||
bool C3D_FrameBegin(u8 flags);
|
||||
|
||||
/**
|
||||
* @brief Specifies render target to draw frame to.
|
||||
* @param[in] target Pointer to render target.
|
||||
* @return True if rendertarget was set successfully, otherwise false.
|
||||
*/
|
||||
bool C3D_FrameDrawOn(C3D_RenderTarget* target);
|
||||
|
||||
/**
|
||||
* @brief Splits and submits the GPU cmdlist in the middle of a renderqueue frame.
|
||||
* @param[in] flags Specifies 0 or more GX_CMDLIST flags.
|
||||
*/
|
||||
void C3D_FrameSplit(u8 flags);
|
||||
|
||||
/**
|
||||
* @brief Ends drawing frame.
|
||||
* @param[in] flags Specifies 0 or more GX_CMDLIST flags.
|
||||
*/
|
||||
void C3D_FrameEnd(u8 flags);
|
||||
|
||||
/**
|
||||
* @brief Executes callback upon \ref C3D_FrameEnd().
|
||||
* @param[in] hook Function callback.
|
||||
* @param[in] param User data.
|
||||
*/
|
||||
void C3D_FrameEndHook(void (* hook)(void*), void* param);
|
||||
|
||||
/**
|
||||
* @brief Gets time spent by the GPU during last render.
|
||||
* @return Drawing time in milliseconds.
|
||||
*/
|
||||
float C3D_GetDrawingTime(void);
|
||||
|
||||
/**
|
||||
* @brief Gets time elapsed between last \ref C3D_FrameBegin() and \ref C3D_FrameEnd().
|
||||
* @return Time in milliseconds.
|
||||
*/
|
||||
float C3D_GetProcessingTime(void);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__cplusplus)
|
||||
@ -59,21 +119,97 @@ public:
|
||||
#define C3D_DEPTHTYPE_OK(_x) ((_x).__i >= 0)
|
||||
#define C3D_DEPTHTYPE_VAL(_x) ((_x).__e)
|
||||
|
||||
/**
|
||||
* @brief Creates a new render target.
|
||||
* @note When creating a rendertarget intended for display, keep in mind the orientation of the screens.
|
||||
* When you hold a 3DS normally, the screens are rotated 90 degrees counter-clockwise.
|
||||
* @param[in] width Specifies width of the render target in pixels.
|
||||
* @param[in] height Specifies height of the render target in pixels.
|
||||
* @param[in] colorFmt Specifies the color format of the render target.
|
||||
* @param[in] depthFmt Specifies the depth format of the render target using \ref GPU_DEPTHBUF. (-1 for no depth type)
|
||||
* @return Pointer to newly created render target.
|
||||
*/
|
||||
C3D_RenderTarget* C3D_RenderTargetCreate(int width, int height, GPU_COLORBUF colorFmt, C3D_DEPTHTYPE depthFmt);
|
||||
|
||||
/**
|
||||
* @brief Constructs render target for texture.
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] face Specifies face of cubemap to be used. (GPU_TEXFACE_2D if not cubemap)
|
||||
* @param[in] level Specifies mipmap level to use.
|
||||
* @param[in] depthFmt Specifies the depth format of the render target using \ref GPU_DEPTHBUF. (-1 for no depth type)
|
||||
* @return Pointer to newly created render target.
|
||||
*/
|
||||
C3D_RenderTarget* C3D_RenderTargetCreateFromTex(C3D_Tex* tex, GPU_TEXFACE face, int level, C3D_DEPTHTYPE depthFmt);
|
||||
|
||||
/**
|
||||
* @brief Deletes render target.
|
||||
* @param[in] target Pointer to render target.
|
||||
*/
|
||||
void C3D_RenderTargetDelete(C3D_RenderTarget* target);
|
||||
|
||||
/**
|
||||
* @brief Sets render target output to screen.
|
||||
* @param[in] target Pointer to render target.
|
||||
* @param[in] screen Screen to transfer the framebuffer to.
|
||||
* @param[in] side Side of the screen to transfer the framebuffer to. (unused for the bottom screen)
|
||||
* @param[in] transferFlags Specifies GX_TRANSFER bitflags.
|
||||
*/
|
||||
void C3D_RenderTargetSetOutput(C3D_RenderTarget* target, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags);
|
||||
|
||||
/**
|
||||
* @brief Detaches render target from screen output.
|
||||
* @param[in] target Pointer to render target.
|
||||
*/
|
||||
static inline void C3D_RenderTargetDetachOutput(C3D_RenderTarget* target)
|
||||
{
|
||||
C3D_RenderTargetSetOutput(NULL, target->screen, target->side, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears framebuffer of target.
|
||||
* @param[in] target Pointer to render target.
|
||||
* @param[in] clearBits Specifies which buffers to clear. (see \ref C3D_ClearBits)
|
||||
* @param[in] clearColor 32 bit RGBA value to clear color buffer with.
|
||||
* @param[in] clearDepth Value to clear depth buffer with.
|
||||
*/
|
||||
static inline void C3D_RenderTargetClear(C3D_RenderTarget* target, C3D_ClearBits clearBits, u32 clearColor, u32 clearDepth)
|
||||
{
|
||||
C3D_FrameBufClear(&target->frameBuf, clearBits, clearColor, clearDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Synchronizes and initiates a display transfer.
|
||||
* Synchronizes and initiates a \ref GX_DisplayTransfer().
|
||||
* @param[in] inadr Address of the input.
|
||||
* @param[in] indim \ref GX_BUFFER_DIM() of the input.
|
||||
* @param[out] outadr Address of the output.
|
||||
* @param[in] outdim \ref GX_BUFFER_DIM() of the output.
|
||||
* @param[in] flags Flags to transfer with.
|
||||
*/
|
||||
void C3D_SyncDisplayTransfer(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 flags);
|
||||
|
||||
/**
|
||||
* @brief Synchronizes and initiates a texture copy.
|
||||
* Synchronizes and initiates a \ref GX_TextureCopy().
|
||||
* @param[in] inadr Address of the input.
|
||||
* @param[in] indim \ref GX_BUFFER_DIM() of the input.
|
||||
* @param[out] outadr Address of the output.
|
||||
* @param[in] outdim \ref GX_BUFFER_DIM() of the output.
|
||||
* @param[in] size Size of the data to transfer.
|
||||
* @param[in] flags Flags to transfer with.
|
||||
*/
|
||||
void C3D_SyncTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags);
|
||||
|
||||
/**
|
||||
* @brief Synchronizes and fills the memory of two buffers with the given values.
|
||||
* Synchronizes and initiates a \ref GX_MemoryFill().
|
||||
* @param[in] buf0a Start address of the first buffer.
|
||||
* @param[in] buf0v Value to fill first buffer.
|
||||
* @param[in] buf0e End address of the first buffer.
|
||||
* @param[in] control0 Value to fill the first buffer with.
|
||||
* @param[in] buf1a Start address of the second buffer.
|
||||
* @param[in] buf1v Value to fill second buffer.
|
||||
* @param[in] buf1e End address of the second buffer.
|
||||
* @param[in] control1 Value to fill the second buffer with.
|
||||
*/
|
||||
void C3D_SyncMemoryFill(u32* buf0a, u32 buf0v, u32* buf0e, u16 control0, u32* buf1a, u32 buf1v, u32* buf1e, u16 control1);
|
||||
|
@ -1,6 +1,13 @@
|
||||
/**
|
||||
* @file texenv.h
|
||||
* @brief Configure texture combiner stages (TexEnv)
|
||||
* @see https://www.khronos.org/opengl/wiki/Texture_Combiners
|
||||
* @see https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTexEnv.xml
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
/// TexEnv stage configuration
|
||||
typedef struct
|
||||
{
|
||||
u16 srcRgb, srcAlpha;
|
||||
@ -14,20 +21,52 @@ typedef struct
|
||||
u16 scaleRgb, scaleAlpha;
|
||||
} C3D_TexEnv;
|
||||
|
||||
/// TexEnv operation mode
|
||||
typedef enum
|
||||
{
|
||||
C3D_RGB = BIT(0),
|
||||
C3D_Alpha = BIT(1),
|
||||
C3D_Both = C3D_RGB | C3D_Alpha,
|
||||
C3D_RGB = BIT(0), ///< RGB mode
|
||||
C3D_Alpha = BIT(1), ///< Alpha mode
|
||||
C3D_Both = C3D_RGB | C3D_Alpha, ///< Both
|
||||
} C3D_TexEnvMode;
|
||||
|
||||
/**
|
||||
* @brief Gets the global TexEnv for a given stage.
|
||||
* @param[in] id TexEnv stage between 0-5 to return.
|
||||
* @return TexEnv of the given stage.
|
||||
*/
|
||||
C3D_TexEnv* C3D_GetTexEnv(int id);
|
||||
|
||||
/**
|
||||
* @brief Sets the global TexEnv for a given stage.
|
||||
* @param[in] id TexEnv stage between 0-5 to set.
|
||||
* @param[in] env Pointer to user TexEnv.
|
||||
*/
|
||||
void C3D_SetTexEnv(int id, C3D_TexEnv* env);
|
||||
|
||||
/**
|
||||
* @brief Marks a TexEnv as needing to be updated.
|
||||
* @note One must use this if they are continuing to use a TexEnv pointer they got from \ref C3D_GetTexEnv() after performing an action that flushes state.
|
||||
* @param[in] env Pointer to a TexEnv struct.
|
||||
*/
|
||||
void C3D_DirtyTexEnv(C3D_TexEnv* env);
|
||||
|
||||
/**
|
||||
* @brief Configures the stages where the GPU_PREVIOUS_BUFFER source value should be updated with the output of that stage.
|
||||
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
||||
* @param[in] mask Bitmask containing which stages update GPU_PREVIOUS_BUFFER (bitmask can be created using \ref GPU_TEV_BUFFER_WRITE_CONFIG())
|
||||
*/
|
||||
void C3D_TexEnvBufUpdate(int mode, int mask);
|
||||
|
||||
/**
|
||||
* @brief Configure the initial value of GPU_PREVIOUS_BUFFER. This value will be kept until it is updated; see \ref C3D_TexEnvBufUpdate().
|
||||
* @param[in] color Color value.
|
||||
*/
|
||||
void C3D_TexEnvBufColor(u32 color);
|
||||
|
||||
/**
|
||||
* @brief Resets a TexEnv to its default values.
|
||||
* @param[out] env TexEnv to initialize.
|
||||
*/
|
||||
static inline void C3D_TexEnvInit(C3D_TexEnv* env)
|
||||
{
|
||||
env->srcRgb = GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0);
|
||||
@ -46,6 +85,14 @@ static inline void C3D_TexEnvInit(C3D_TexEnv* env)
|
||||
#define _C3D_DEFAULT(x)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Sets the input source of a TexEnv.
|
||||
* @param[out] env Pointer to TexEnv struct.
|
||||
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
||||
* @param[in] s1 First source.
|
||||
* @param[in] s2 Second source.
|
||||
* @param[in] s3 Third source.
|
||||
*/
|
||||
static inline void C3D_TexEnvSrc(C3D_TexEnv* env, C3D_TexEnvMode mode,
|
||||
GPU_TEVSRC s1,
|
||||
GPU_TEVSRC s2 _C3D_DEFAULT(GPU_PRIMARY_COLOR),
|
||||
@ -58,6 +105,13 @@ static inline void C3D_TexEnvSrc(C3D_TexEnv* env, C3D_TexEnvMode mode,
|
||||
env->srcAlpha = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the operation to be applied to the input color of a TexEnv before the function is applied.
|
||||
* @param[out] env Pointer to TexEnv struct.
|
||||
* @param[in] o1 Operation to perform on the first source.
|
||||
* @param[in] o2 Operation to perform on the second source.
|
||||
* @param[in] o3 Operation to perform on the third source.
|
||||
*/
|
||||
static inline void C3D_TexEnvOpRgb(C3D_TexEnv* env,
|
||||
GPU_TEVOP_RGB o1,
|
||||
GPU_TEVOP_RGB o2 _C3D_DEFAULT(GPU_TEVOP_RGB_SRC_COLOR),
|
||||
@ -66,6 +120,13 @@ static inline void C3D_TexEnvOpRgb(C3D_TexEnv* env,
|
||||
env->opRgb = GPU_TEVOPERANDS((int)o1, (int)o2, (int)o3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the operation to be applied to the input alpha of a TexEnv before the function is applied.
|
||||
* @param[out] env Pointer to TexEnv struct.
|
||||
* @param[in] o1 Operation to perform on the first source.
|
||||
* @param[in] o2 Operation to perform on the second source.
|
||||
* @param[in] o3 Operation to perform on the third source.
|
||||
*/
|
||||
static inline void C3D_TexEnvOpAlpha(C3D_TexEnv* env,
|
||||
GPU_TEVOP_A o1,
|
||||
GPU_TEVOP_A o2 _C3D_DEFAULT(GPU_TEVOP_A_SRC_ALPHA),
|
||||
@ -74,6 +135,12 @@ static inline void C3D_TexEnvOpAlpha(C3D_TexEnv* env,
|
||||
env->opAlpha = GPU_TEVOPERANDS((int)o1, (int)o2, (int)o3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the combiner function to perform in this TexEnv.
|
||||
* @param[out] env Pointer to TexEnv struct.
|
||||
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
||||
* @param[in] param Function to use.
|
||||
*/
|
||||
static inline void C3D_TexEnvFunc(C3D_TexEnv* env, C3D_TexEnvMode mode, GPU_COMBINEFUNC param)
|
||||
{
|
||||
if ((int)mode & C3D_RGB)
|
||||
@ -82,11 +149,22 @@ static inline void C3D_TexEnvFunc(C3D_TexEnv* env, C3D_TexEnvMode mode, GPU_COMB
|
||||
env->funcAlpha = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the value of the GPU_CONSTANT source for a TexEnv stage.
|
||||
* @param[out] env Pointer to TexEnv struct.
|
||||
* @param[in] color RGBA color value to apply.
|
||||
*/
|
||||
static inline void C3D_TexEnvColor(C3D_TexEnv* env, u32 color)
|
||||
{
|
||||
env->color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the scaling to be applied to the output of a TexEnv.
|
||||
* @param[out] env Pointer to TexEnv struct.
|
||||
* @param[in] mode TexEnv update modes (see \ref C3D_TexEnvMode)
|
||||
* @param[in] param Scale factor to apply.
|
||||
*/
|
||||
static inline void C3D_TexEnvScale(C3D_TexEnv* env, int mode, GPU_TEVSCALE param)
|
||||
{
|
||||
if (mode & C3D_RGB)
|
||||
|
@ -1,11 +1,17 @@
|
||||
/**
|
||||
* @file texture.h
|
||||
* @brief Create and manipulate textures
|
||||
*/
|
||||
#pragma once
|
||||
#include "types.h"
|
||||
|
||||
/// Cubemap texture data
|
||||
typedef struct
|
||||
{
|
||||
void* data[6];
|
||||
} C3D_TexCube;
|
||||
|
||||
/// Texture data
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
@ -41,35 +47,101 @@ typedef struct
|
||||
};
|
||||
} C3D_Tex;
|
||||
|
||||
/// Parameters for \ref C3D_TexInitWithParams()
|
||||
typedef struct CTR_ALIGN(8)
|
||||
{
|
||||
u16 width;
|
||||
u16 height;
|
||||
u8 maxLevel : 4;
|
||||
GPU_TEXCOLOR format : 4;
|
||||
GPU_TEXTURE_MODE_PARAM type : 3;
|
||||
bool onVram : 1;
|
||||
u16 width; ///< Width of texture in pixels. (must be a power of 2)
|
||||
u16 height; ///< Height of texture in pixels. (must be a power of 2)
|
||||
u8 maxLevel : 4; ///< Maximum mipmap level.
|
||||
GPU_TEXCOLOR format : 4; ///< GPU texture format.
|
||||
GPU_TEXTURE_MODE_PARAM type : 3; ///< Texture type
|
||||
bool onVram : 1; ///< Specifies whether to allocate texture data in Vram or linearMemory
|
||||
} C3D_TexInitParams;
|
||||
|
||||
/**
|
||||
* @brief Initializes texture with specified parameters
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[out] cube Pointer to \ref C3D_TexCube. (Only used if texture type is cubemap)
|
||||
* @param[in] p Parameters. See \ref C3D_TexInitParams.
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
bool C3D_TexInitWithParams(C3D_Tex* tex, C3D_TexCube* cube, C3D_TexInitParams p);
|
||||
|
||||
/**
|
||||
* @brief Copies raw texture data into \ref C3D_Tex
|
||||
* @param[out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] data Pointer to raw texture data.
|
||||
* @param[in] face Specifies texture face.
|
||||
* @param[in] level Specifies mipmap level.
|
||||
*/
|
||||
void C3D_TexLoadImage(C3D_Tex* tex, const void* data, GPU_TEXFACE face, int level);
|
||||
|
||||
/**
|
||||
* @brief Generates mipmaps for \ref C3D_Tex using previously specified max level
|
||||
* The max level should have been specified using \ref C3D_TexInitMipmap() or \ref C3D_TexInitWithParams()
|
||||
* @note Does not support generating mipmaps for VRAM textures.
|
||||
* @param[in,out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] face Specifies texture face.
|
||||
*/
|
||||
void C3D_TexGenerateMipmap(C3D_Tex* tex, GPU_TEXFACE face);
|
||||
|
||||
/**
|
||||
* @brief Binds C3D_Tex to texture unit
|
||||
* @note The 3DS has 3 normal texture units (IDs 0 through 2).
|
||||
* @param[in] unitId Specifies texture unit.
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
*/
|
||||
void C3D_TexBind(int unitId, C3D_Tex* tex);
|
||||
|
||||
/**
|
||||
* @brief Flushes texture data from cache into memory
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
* @sa GSPGPU_FlushDataCache()
|
||||
*/
|
||||
void C3D_TexFlush(C3D_Tex* tex);
|
||||
|
||||
/**
|
||||
* @brief Deletes texture data
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
*/
|
||||
void C3D_TexDelete(C3D_Tex* tex);
|
||||
|
||||
/**
|
||||
* @brief Configues texunit0 shadow depth texture properties
|
||||
* @param[in] perspective true if the shadow texture was generated with perspective projection,
|
||||
* false if the shadow texture was generated with orthogonal projection.
|
||||
* @param[in] bias Bias subtracted from the texture0w value in the shader.
|
||||
*/
|
||||
void C3D_TexShadowParams(bool perspective, float bias);
|
||||
|
||||
/**
|
||||
* @brief Calculates maximum mipmap level for given texture size
|
||||
* @param[in] width Width of texture.
|
||||
* @param[in] height Height of texture.
|
||||
* @returns Calculated maximum mipmap level.
|
||||
*/
|
||||
static inline int C3D_TexCalcMaxLevel(u32 width, u32 height)
|
||||
{
|
||||
return (31-__builtin_clz(width < height ? width : height)) - 3; // avoid sizes smaller than 8
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates size of mipmap level
|
||||
* @param[in] size Size of original texture.
|
||||
* @param[in] level Mipmap level.
|
||||
* @returns Calculated level size.
|
||||
*/
|
||||
static inline u32 C3D_TexCalcLevelSize(u32 size, int level)
|
||||
{
|
||||
return size >> (2*level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates total size of mipmap texture data
|
||||
* @param[in] size Size of original texture.
|
||||
* @param[in] maxLevel Maximum mipmap level.
|
||||
* @returns Calculated total size.
|
||||
*/
|
||||
static inline u32 C3D_TexCalcTotalSize(u32 size, int maxLevel)
|
||||
{
|
||||
/*
|
||||
@ -91,47 +163,108 @@ static inline u32 C3D_TexCalcTotalSize(u32 size, int maxLevel)
|
||||
return (size - C3D_TexCalcLevelSize(size,maxLevel+1)) * 4 / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes standard 2D texture
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[in] width Specifies width of texture. (must be a power of 2)
|
||||
* @param[in] height Specifies height of texture. (must be a power of 2)
|
||||
* @param[in] format Specifies texture format.
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
static inline bool C3D_TexInit(C3D_Tex* tex, u16 width, u16 height, GPU_TEXCOLOR format)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, NULL,
|
||||
(C3D_TexInitParams){ width, height, 0, format, GPU_TEX_2D, false });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes standard 2D texture with mipmap
|
||||
* Maximum miplevel is calculated using \ref C3D_TexCalcMaxLevel()
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[in] width Specifies width of texture. (must be a power of 2)
|
||||
* @param[in] height Specifies height of texture. (must be a power of 2)
|
||||
* @param[in] format Specifies texture format.
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
static inline bool C3D_TexInitMipmap(C3D_Tex* tex, u16 width, u16 height, GPU_TEXCOLOR format)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, NULL,
|
||||
(C3D_TexInitParams){ width, height, (u8)C3D_TexCalcMaxLevel(width, height), format, GPU_TEX_2D, false });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes cubemap texture
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[out] cube Pointer to \ref C3D_TexCube.
|
||||
* @param[in] width Specifies width of texture. (must be a power of 2)
|
||||
* @param[in] height Specifies height of texture. (must be a power of 2)
|
||||
* @param[in] format Specifies texture format.
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
static inline bool C3D_TexInitCube(C3D_Tex* tex, C3D_TexCube* cube, u16 width, u16 height, GPU_TEXCOLOR format)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, cube,
|
||||
(C3D_TexInitParams){ width, height, 0, format, GPU_TEX_CUBE_MAP, false });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes 2D texture in VRAM
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[in] width Specifies width of texture. (must be a power of 2)
|
||||
* @param[in] height Specifies height of texture. (must be a power of 2)
|
||||
* @param[in] format Specifies texture format.
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
static inline bool C3D_TexInitVRAM(C3D_Tex* tex, u16 width, u16 height, GPU_TEXCOLOR format)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, NULL,
|
||||
(C3D_TexInitParams){ width, height, 0, format, GPU_TEX_2D, true });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes 2D shadowmap texture
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[in] width Specifies width of texture. (must be a power of 2)
|
||||
* @param[in] height Specifies height of texture. (must be a power of 2)
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
static inline bool C3D_TexInitShadow(C3D_Tex* tex, u16 width, u16 height)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, NULL,
|
||||
(C3D_TexInitParams){ width, height, 0, GPU_RGBA8, GPU_TEX_SHADOW_2D, true });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes shadowmap cubemap texture
|
||||
* @param[out] tex Pointer to uninitialized \ref C3D_Tex.
|
||||
* @param[out] cube Pointer to \ref C3D_TexCube.
|
||||
* @param[in] width Specifies width of texture. (must be a power of 2)
|
||||
* @param[in] height Specifies height of texture. (must be a power of 2)
|
||||
* @return True if texture was initialized successfully, otherwise false.
|
||||
*/
|
||||
static inline bool C3D_TexInitShadowCube(C3D_Tex* tex, C3D_TexCube* cube, u16 width, u16 height)
|
||||
{
|
||||
return C3D_TexInitWithParams(tex, cube,
|
||||
(C3D_TexInitParams){ width, height, 0, GPU_RGBA8, GPU_TEX_SHADOW_CUBE, true });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets type of texture
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
*/
|
||||
static inline GPU_TEXTURE_MODE_PARAM C3D_TexGetType(C3D_Tex* tex)
|
||||
{
|
||||
return (GPU_TEXTURE_MODE_PARAM)((tex->param>>28)&0x7);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets pointer to texture image
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] data Pointer texture face.
|
||||
* @param[in] level Specifies mipmap level.
|
||||
* @param[out] size Can be used to get the size of the image data.
|
||||
* @returns Pointer to raw image data.
|
||||
*/
|
||||
static inline void* C3D_TexGetImagePtr(C3D_Tex* tex, void* data, int level, u32* size)
|
||||
{
|
||||
if (size) *size = level >= 0 ? C3D_TexCalcLevelSize(tex->size, level) : C3D_TexCalcTotalSize(tex->size, tex->maxLevel);
|
||||
@ -139,39 +272,81 @@ static inline void* C3D_TexGetImagePtr(C3D_Tex* tex, void* data, int level, u32*
|
||||
return (u8*)data + (level > 0 ? C3D_TexCalcTotalSize(tex->size, level-1) : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets pointer to 2D texture image
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] level Specifies mipmap level.
|
||||
* @param[out] size Can be used to get the size of the image data.
|
||||
* @returns Pointer to raw image data.
|
||||
*/
|
||||
static inline void* C3D_Tex2DGetImagePtr(C3D_Tex* tex, int level, u32* size)
|
||||
{
|
||||
return C3D_TexGetImagePtr(tex, tex->data, level, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets pointer to cubemap texture image
|
||||
* @param[in] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] face Specifies the cubemap texture face.
|
||||
* @param[in] level Specifies mipmap level.
|
||||
* @param[out] size Can be used to get the size of the image data.
|
||||
* @returns Pointer to raw image data.
|
||||
*/
|
||||
static inline void* C3D_TexCubeGetImagePtr(C3D_Tex* tex, GPU_TEXFACE face, int level, u32* size)
|
||||
{
|
||||
return C3D_TexGetImagePtr(tex, tex->cube->data[face], level, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copies raw texture data into standard 2D texture
|
||||
* @param[out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] data Pointer to raw texture data.
|
||||
*/
|
||||
static inline void C3D_TexUpload(C3D_Tex* tex, const void* data)
|
||||
{
|
||||
C3D_TexLoadImage(tex, data, GPU_TEXFACE_2D, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures texture magnification and minification filters
|
||||
* @param[out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] magFilter Specifies the filtering to use when magnifying the the texture.
|
||||
* @param[in] minFilter Specifies the filtering to use when minifying the the texture.
|
||||
*/
|
||||
static inline void C3D_TexSetFilter(C3D_Tex* tex, GPU_TEXTURE_FILTER_PARAM magFilter, GPU_TEXTURE_FILTER_PARAM minFilter)
|
||||
{
|
||||
tex->param &= ~(GPU_TEXTURE_MAG_FILTER(GPU_LINEAR) | GPU_TEXTURE_MIN_FILTER(GPU_LINEAR));
|
||||
tex->param |= GPU_TEXTURE_MAG_FILTER(magFilter) | GPU_TEXTURE_MIN_FILTER(minFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures texture mipmap minification filters
|
||||
* @param[out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] filter Specifies the filtering to use when minifying the the mipmap.
|
||||
*/
|
||||
static inline void C3D_TexSetFilterMipmap(C3D_Tex* tex, GPU_TEXTURE_FILTER_PARAM filter)
|
||||
{
|
||||
tex->param &= ~GPU_TEXTURE_MIP_FILTER(GPU_LINEAR);
|
||||
tex->param |= GPU_TEXTURE_MIP_FILTER(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures texture wrapping options
|
||||
* @param[out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] wrapS Specifies the texture wrapping mode for texture coordinate S (aka U).
|
||||
* @param[in] wrapT Specifies the texture wrapping mode for texture coordinate T (aka V).
|
||||
*/
|
||||
static inline void C3D_TexSetWrap(C3D_Tex* tex, GPU_TEXTURE_WRAP_PARAM wrapS, GPU_TEXTURE_WRAP_PARAM wrapT)
|
||||
{
|
||||
tex->param &= ~(GPU_TEXTURE_WRAP_S(3) | GPU_TEXTURE_WRAP_T(3));
|
||||
tex->param |= GPU_TEXTURE_WRAP_S(wrapS) | GPU_TEXTURE_WRAP_T(wrapT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures texture level of detail bias used to select the correct mipmap during sampling
|
||||
* @param[out] tex Pointer to \ref C3D_Tex.
|
||||
* @param[in] lodBias Specifies the texture level of detail bias.
|
||||
*/
|
||||
static inline void C3D_TexSetLodBias(C3D_Tex* tex, float lodBias)
|
||||
{
|
||||
int iLodBias = (int)(lodBias*0x100);
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @file types.h
|
||||
* @brief Various citro3d types.
|
||||
*/
|
||||
#pragma once
|
||||
#if defined(__3DS__) || defined(_3DS)
|
||||
#include <3ds.h>
|
||||
@ -14,8 +18,19 @@ typedef uint32_t u32;
|
||||
#define C3D_DEPRECATED
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Integer vector
|
||||
*/
|
||||
typedef u32 C3D_IVec;
|
||||
|
||||
/**
|
||||
* @brief Packs 4 u8 integers into a vector.
|
||||
* @param[in] x X component of the vector.
|
||||
* @param[in] y Y component of the vector.
|
||||
* @param[in] z Z component of the vector.
|
||||
* @param[in] w W component of the vector.
|
||||
* @return Returns \ref C3D_IVec.
|
||||
*/
|
||||
static inline C3D_IVec IVec_Pack(u8 x, u8 y, u8 z, u8 w)
|
||||
{
|
||||
return (u32)x | ((u32)y << 8) | ((u32)z << 16) | ((u32)w << 24);
|
||||
@ -64,7 +79,6 @@ typedef union
|
||||
} C3D_FVec;
|
||||
|
||||
/**
|
||||
* @struct C3D_FQuat
|
||||
* @brief Float quaternion. See @ref C3D_FVec.
|
||||
*/
|
||||
typedef C3D_FVec C3D_FQuat;
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @file uniforms.h
|
||||
* @brief Write to shader uniforms
|
||||
*/
|
||||
#pragma once
|
||||
#include "maths.h"
|
||||
|
||||
@ -12,6 +16,13 @@ extern bool C3D_FVUnifDirty[2][C3D_FVUNIF_COUNT];
|
||||
extern bool C3D_IVUnifDirty[2][C3D_IVUNIF_COUNT];
|
||||
extern bool C3D_BoolUnifsDirty[2];
|
||||
|
||||
/**
|
||||
* @brief Provides a writable pointer for a floating-point uniform.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] size Number of registers allocated for this uniform.
|
||||
* @return Writable pointer. This should not be freed.
|
||||
*/
|
||||
static inline C3D_FVec* C3D_FVUnifWritePtr(GPU_SHADER_TYPE type, int id, int size)
|
||||
{
|
||||
int i;
|
||||
@ -20,6 +31,12 @@ static inline C3D_FVec* C3D_FVUnifWritePtr(GPU_SHADER_TYPE type, int id, int siz
|
||||
return &C3D_FVUnif[type][id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Provides a writable pointer for an integer uniform.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @return Writable pointer. This should not be freed.
|
||||
*/
|
||||
static inline C3D_IVec* C3D_IVUnifWritePtr(GPU_SHADER_TYPE type, int id)
|
||||
{
|
||||
id -= 0x60;
|
||||
@ -27,6 +44,14 @@ static inline C3D_IVec* C3D_IVUnifWritePtr(GPU_SHADER_TYPE type, int id)
|
||||
return &C3D_IVUnif[type][id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes an Nx4 matrix to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] mtx Matrix to be written.
|
||||
* @param[in] num Row count of the matrix.
|
||||
* @remark Usually, one should use the helper functions for 4x4, 3x4, and 2x4 matrices listed below.
|
||||
*/
|
||||
static inline void C3D_FVUnifMtxNx4(GPU_SHADER_TYPE type, int id, const C3D_Mtx* mtx, int num)
|
||||
{
|
||||
int i;
|
||||
@ -35,21 +60,48 @@ static inline void C3D_FVUnifMtxNx4(GPU_SHADER_TYPE type, int id, const C3D_Mtx*
|
||||
ptr[i] = mtx->r[i]; // Struct copy.
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a 4x4 matrix to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] mtx Matrix to be written.
|
||||
*/
|
||||
static inline void C3D_FVUnifMtx4x4(GPU_SHADER_TYPE type, int id, const C3D_Mtx* mtx)
|
||||
{
|
||||
C3D_FVUnifMtxNx4(type, id, mtx, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a 3x4 matrix to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] mtx Matrix to be written.
|
||||
*/
|
||||
static inline void C3D_FVUnifMtx3x4(GPU_SHADER_TYPE type, int id, const C3D_Mtx* mtx)
|
||||
{
|
||||
C3D_FVUnifMtxNx4(type, id, mtx, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a 2x4 matrix to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] mtx Matrix to be written.
|
||||
*/
|
||||
static inline void C3D_FVUnifMtx2x4(GPU_SHADER_TYPE type, int id, const C3D_Mtx* mtx)
|
||||
{
|
||||
C3D_FVUnifMtxNx4(type, id, mtx, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a 4-component floating-point vector to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] x X component of the vector.
|
||||
* @param[in] y Y component of the vector.
|
||||
* @param[in] z Z component of the vector.
|
||||
* @param[in] w W component of the vector.
|
||||
*/
|
||||
static inline void C3D_FVUnifSet(GPU_SHADER_TYPE type, int id, float x, float y, float z, float w)
|
||||
{
|
||||
C3D_FVec* ptr = C3D_FVUnifWritePtr(type, id, 1);
|
||||
@ -59,12 +111,27 @@ static inline void C3D_FVUnifSet(GPU_SHADER_TYPE type, int id, float x, float y,
|
||||
ptr->w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a 4-component integer vector to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] x X component of the vector.
|
||||
* @param[in] y Y component of the vector.
|
||||
* @param[in] z Z component of the vector.
|
||||
* @param[in] w W component of the vector.
|
||||
*/
|
||||
static inline void C3D_IVUnifSet(GPU_SHADER_TYPE type, int id, int x, int y, int z, int w)
|
||||
{
|
||||
C3D_IVec* ptr = C3D_IVUnifWritePtr(type, id);
|
||||
*ptr = IVec_Pack(x, y, z, w);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a boolean value to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniform to be set.
|
||||
* @param[in] id ID of the uniform (retrievable using libctru's \ref shaderInstanceGetUniformLocation())
|
||||
* @param[in] value Boolean value to write.
|
||||
*/
|
||||
static inline void C3D_BoolUnifSet(GPU_SHADER_TYPE type, int id, bool value)
|
||||
{
|
||||
id -= 0x68;
|
||||
@ -75,4 +142,9 @@ static inline void C3D_BoolUnifSet(GPU_SHADER_TYPE type, int id, bool value)
|
||||
C3D_BoolUnifs[type] &= ~BIT(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flushes newly-updated uniforms to the uniform registers.
|
||||
* @param[in] type \ref GPU_SHADER_TYPE of the uniforms to be flushed.
|
||||
* @remark This is called internally, and generally does not need to be handled by the user.
|
||||
*/
|
||||
void C3D_UpdateUniforms(GPU_SHADER_TYPE type);
|
||||
|
@ -1,3 +1,7 @@
|
||||
/**
|
||||
* @file citro3d.h
|
||||
* @brief Central citro3d header. Includes all others.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifdef CITRO3D_BUILD
|
||||
|
Loading…
Reference in New Issue
Block a user