/*---------------------------------------------------------------------------* Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #ifndef _DEMO_GFX_SHADER_H_ #define _DEMO_GFX_SHADER_H_ #ifdef __cplusplus extern "C" { #endif /// @addtogroup demoShader /// @{ /// \brief The structure for vertex/pixel samplers /// /// Each member map to each sampler number. /// typedef struct _DEMOGfxSamplers { /// Current number of sampler u32 count; /// The locations in the shader. u32 location[GX2_MAX_SAMPLERS]; } DEMOGfxSamplers; /// \brief The structure for vertex uniforms /// /// Each member map to each uniform number. /// typedef struct _DEMOGfxUniformsVS { /// Current number of uniforms u32 count; /// The locations in the vertex shader. u32 location[GX2_MAX_VS_UNIFORM_VARS]; } DEMOGfxUniformsVS; /// \brief The structure for pixel uniforms /// /// Each member map to each uniform number. /// typedef struct _DEMOGfxUniformsPS { /// Current number of uniforms u32 count; /// The locations in the pixel shader. u32 location[GX2_MAX_PS_UNIFORM_VARS]; } DEMOGfxUniformsPS; /// \brief The structure for vertex uniform blocks /// /// Each member map to each uniform number. /// typedef struct _DEMOGfxUniformBlocks { /// Current number of uniform blocks u32 count; /// The locations in the shader. u32 location[GX2_MAX_UNIFORM_BLOCKS]; /// The size of uniform blocks u32 size[GX2_MAX_UNIFORM_BLOCKS]; } DEMOGfxUniformBlocks; /// \brief The structure for shader data /// /// Includes members to setup shader /// typedef struct _DEMOGfxShader { /// Current number of attributes u32 attribCount; /// The attribute streams are used to bind the variables used by the vertex shader with the fetch shader. GX2AttribStream attribs[GX2_MAX_ATTRIB_BUFFERS]; /// The structure holds vertex shader samplers locations DEMOGfxSamplers samplersVS; /// The structure holds pixel shader samplers locations DEMOGfxSamplers samplersPS; /// The structure holds geometry shader samplers locations DEMOGfxSamplers samplersGS; /// The structure holds vertex shader uniforms locations DEMOGfxUniformsVS uniformsVS; /// The structure holds pixel shader uniforms locations DEMOGfxUniformsPS uniformsPS; // GS is UB only /// The structure holds vertex shader uniform blocks location and size DEMOGfxUniformBlocks uniformBlocksVS; /// The structure holds pixel shader uniform blocks location and size DEMOGfxUniformBlocks uniformBlocksPS; /// The structure holds geometry shader uniform blocks location and size DEMOGfxUniformBlocks uniformBlocksGS; /// The vertex shader structure pointers which are loaded from the GSH file GX2VertexShader *pVertexShader; /// The pixel shader structure pointers which are loaded from the GSH file GX2PixelShader *pPixelShader; /// The geometry shader structure pointers which are loaded from the GSH file GX2GeometryShader *pGeometryShader; /// The fetch shader which is based on the specified attribute stream list. GX2FetchShader fetchShader; /// An aligned, user-allocated buffer for the fetch shader binary code. void * pFetchShaderBuffer; } DEMOGfxShader; // // Functions // /// \brief Checks number of shader location /// /// \param location number of shader location /// \return result (TRUE or FALSE) /// inline BOOL DEMOGfxCheckShaderLocation(u32 location) { if(location == (u32)(-1)) { OSReport("Warning: Could not find the correct location.\n"); return FALSE; } return TRUE; } /// \brief Loads shaders from file buffer (.gsh) /// /// \param pShader Pointer to DEMOGfxShader structure /// \param index Index of shader in the file buffer /// \param pData Pointer to the file buffer /// \return result (TRUE or FALSE) /// BOOL DEMOGfxLoadShaders(DEMOGfxShader *pShader, u32 index, const void *pData); /// \brief Sets attribute members to DEMOGfxShader structure and initializes stream /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of attribute (for example, a_position, a_color etc.) /// \param bufferIndex Index of attribute buffer /// \param offset Offset value for attribute data /// \param format Attribute format /// \return result (TRUE or FALSE) /// BOOL DEMOGfxInitShaderAttribute(DEMOGfxShader *pShader, const char *name, u32 bufferIndex, u32 offset, GX2AttribFormat format); /// \brief Gets vertex shader sampler location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of sampler (for example, s_texture) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetVertexShaderSamplerLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets pixel shader sampler location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of sampler (for example, s_texture) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetPixelShaderSamplerLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets geometry shader sampler location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of sampler (for example, s_texture) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetGeometryShaderSamplerLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets vertex shader uniform location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of uniform (for example, u_scale) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetVertexShaderUniformLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets pixel shader uniform location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of uniform (for example, u_scale) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetPixelShaderUniformLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets vertex shader uniform block location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of uniform block (for example, ub_staticBlock) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetVertexShaderUniformBlockLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets pixel shader uniform block location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of uniform block (for example, ub_dynamicBlock) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetPixelShaderUniformBlockLocation(DEMOGfxShader *pShader, const char *name); /// \brief Gets geometry shader uniform block location and sets to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// \param name Pointer to name of uniform block (for example, ub_dynamicBlock) /// \return result (TRUE or FALSE) /// BOOL DEMOGfxGetGeometryShaderUniformBlockLocation(DEMOGfxShader *pShader, const char *name); /// \brief Sets fetch shader with attrib stream data to DEMOGfxShader structure /// /// \param pShader Pointer to DEMOGfxShader structure /// BOOL DEMOGfxInitFetchShader(DEMOGfxShader *pShader); /// \brief Free shaders (Vertex, Pixel, Geometry and Fetch shader ) /// /// \param pShader Pointer to DEMOGfxShader structure /// BOOL DEMOGfxFreeShaders(DEMOGfxShader *pShader); /// @} #ifdef __cplusplus } #endif #endif // _DEMO_GFX_SHADER_H_