Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Render - Type.h
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, Andrew Aye.  All Rights Reserved.
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
#if !defined(_TGS_RENDER_TYPE_H_)
#define _TGS_RENDER_TYPE_H_
#pragma once

#include "TgS Render - Constants.h"
#include "TgS Ring 3 - Type.h"


// == Render ==================================================================================================================== //

// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Types
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

// -- Resource ------------------------------------------------------------------------------------------------------------------ //

typedef struct
{
    TgUINT16                                    m_uiWidth, m_uiHeight, m_uiRefreshRate;
    TgBOOL                                      m_bFullscreen; //« Only Valid for non-console environment
} STg2_RN_Mode;
TgTYPE_PREFIX( STg2_RN_Mode );

typedef TgBOOL (*TgFCN_TX_CUBE_LOADER)( C_TgRN_TX_CUBE_ID, CPC_STg2_Input );
TgTYPE_PREFIX(TgFCN_TX_CUBE_LOADER);

typedef TgBOOL (*TgFCN_TX_IMG_LOADER)( C_TgRN_TX_IMG_ID, CPC_STg2_Input );
TgTYPE_PREFIX(TgFCN_TX_IMG_LOADER);

typedef TgBOOL (*TgFCN_TX_VOL_LOADER)( C_TgRN_TX_VOL_ID, CPC_STg2_Input );
TgTYPE_PREFIX(TgFCN_TX_VOL_LOADER);

// Function pointer that will return a new material id for a given data stream parameter.
typedef TgRN_MT_ID (*TgFCN_MATERIAL_INIT)( PC_STg2_Input );

typedef TgVOID (*TgMATERIAL_PIPELINE)( //« Function pointer used to set the material into the pipeline.
    C_TgRN_MT_ID,     //« Material ID - The material to be set into the pipeline
    C_TgUINT32,       //« Light Count - The number of lights affecting this mesh
    C_TgRN_MESH_ID    //« Mesh ID - The mesh being drawn with this material
    );

typedef struct
{
    CPCU_TgCHAR                                 m_pszName;
    TgFCN_MATERIAL_INIT                         m_pfnInit;
    TgMATERIAL_PIPELINE                         m_apfn[ETgRN_MT_MODE_MAX];
} STg2_RN_DEFN_Material;
TgTYPE_PREFIX(STg2_RN_DEFN_Material);


// -- Vertex Descriptors -------------------------------------------------------------------------------------------------------- //

// Create the vertex data structures

#define RENDER_VERTEX_LAYOUT_START(A,B)         typedef struct {
#define RENDER_VERTEX_LAYOUT(A,B,C,D,E,...)         C __VA_ARGS__;
#define RENDER_VERTEX_LAYOUT_END(A)             } STg2_##A; TgTYPE_PREFIX( STg2_##A );
#define RENDER_VERTEX_ALIGNMENT_CHECK(A,B)      TgCOMPILER_ASSERT(A == sizeof(STg2_##B),99);

#include "TgS Render - Type [Vertex].h_inc"

#undef RENDER_VERTEX_LAYOUT_START
#undef RENDER_VERTEX_LAYOUT
#undef RENDER_VERTEX_LAYOUT_END
#undef RENDER_VERTEX_ALIGNMENT_CHECK


// -- Post Process Settings ----------------------------------------------------------------------------------------------------- //

typedef struct
{
    TgFLOAT32                                   m_fUser_Brightness, m_fUser_Contrast, m_fUser_Gamma;
    TgFLOAT32                                   m_fGame_Brightness, m_fGame_Contrast, m_fGame_Gamma;
    TgFLOAT32                                   m_fGame_Hue, m_fGame_Saturation, m_fWhite_Point;
    TgVEC_F32_04                                m_vFilter_Colour;
} STg2_RN_Settings__Colour_Correction;
TgTYPE_PREFIX(STg2_RN_Settings__Colour_Correction);

typedef struct
{
    TgFLOAT32                                   m_fDummy;
} STg2_RN_Settings__SSAO;
TgTYPE_PREFIX(STg2_RN_Settings__SSAO);

typedef struct
{
    TgFLOAT32                                   m_fThreshold;
    TgFLOAT32                                   m_fFactor;
    TgFLOAT32                                   m_fIntensity;
} STg2_RN_Settings__Image_Bloom;
TgTYPE_PREFIX(STg2_RN_Settings__Image_Bloom);

typedef struct
{
    TgFLOAT32                                   m_fThreshold;
    TgFLOAT32                                   m_fFactor;
    TgFLOAT32                                   m_fIntensity;
} STg2_RN_Settings__Directed_Bloom;
TgTYPE_PREFIX(STg2_RN_Settings__Directed_Bloom);

typedef struct
{
    TgFLOAT32                                   m_fFog_Near_Plane, m_fFog_Far_Plane;
    TgVEC_F32_04                                m_vFog_Colour;
} STg2_RN_Settings__Fog;
TgTYPE_PREFIX(STg2_RN_Settings__Fog);

typedef struct
{
    TgFLOAT32                                   m_fDoF_Near_Dist, m_fDoF_Near_Mult;
    TgFLOAT32                                   m_fDoF_Far_Dist, m_fDoF_Far_Mult;
    TgBOOL                                      m_bDoF_Sky_Box;
} STg2_RN_Settings__DoF;
TgTYPE_PREFIX(STg2_RN_Settings__DoF);


// -- Context Parameters -------------------------------------------------------------------------------------------------------- //

typedef struct
{
    STg2_RN_Settings__Colour_Correction         m_sColour_Correction;
    STg2_RN_Settings__SSAO                      m_sSSAO;
    STg2_RN_Settings__Image_Bloom               m_sImage_Bloom;
    STg2_RN_Settings__Directed_Bloom            m_sDirected_Bloom;
    STg2_RN_Settings__Fog                       m_sFog;
    STg2_RN_Settings__DoF                       m_sDoF;

    TgVEC_F32_04                                m_vClear_Colour;
    ETgRN_MT_MODE                               m_enMaterial_Mode;

    // Flags: Colour Balance
    TgBOOL                                      m_bEnable_User_Colour_Correction;
    TgBOOL                                      m_bEnable_Filter_Colour;
    TgBOOL                                      m_bEnable_Game_Gamma;
    TgBOOL                                      m_bEnable_Game_Colour_Hue;
    TgBOOL                                      m_bEnable_Game_Colour_Saturation;
    TgBOOL                                      m_bEnable_Game_Colour_Brightness;
    TgBOOL                                      m_bEnable_Game_Colour_Contrast;

    // Flags: Image

    TgBOOL                                      m_bEnable_Shadow;

    // Flags: Post Process

    TgBOOL                                      m_bEnable_Fog;
    TgBOOL                                      m_bEnable_Fog_Near_Plane;
    TgBOOL                                      m_bEnable_Fog_Far_Plane;
    TgBOOL                                      m_bEnable_Fog_Colour;

    TgBOOL                                      m_bEnable_Image_Bloom;

    TgBOOL                                      m_bEnable_Directed_Bloom;

    TgBOOL                                      m_bEnable_SSAO;

    TgBOOL                                      m_bEnable_Frame_Motion_Blur;

    TgBOOL                                      m_bEnable_Velocity_Blur;

    TgBOOL                                      m_bEnable_Depth_Of_Field;

    // Flags: Debug

    TgBOOL                                      m_bEnable_Clear_Colour;
    TgBOOL                                      m_bEnable_Debug_Text;
    TgBOOL                                      m_bEnable_Debug_Line;
    TgBOOL                                      m_bEnable_Debug_Geom;
    TgBOOL                                      m_bEnable_Frame_Stats;
    TgBOOL                                      m_bEnable_Debug_Material_Mode;

} STg2_RN_Cxt_Render_Settings;
TgTYPE_PREFIX(STg2_RN_Cxt_Render_Settings);

// Camera Parameter - This is the minimal representation for use by the render module.  It is assumed to be in the current render
// view as established in the rendering system (perspective or orthographic).
typedef struct // Camera
{
    TgCAMERA                                    m_sCamera;

                                                // Reference Frame of the Camera
    TgVEC_F32_04                                m_vCam_Forward; //« World space camera forward vector
    TgVEC_F32_04                                m_vCam_Up; //« World space camera up vector
    TgVEC_F32_04                                m_vCam_Right; //« World space camera right vector

                                                // Reference Frame Transformations
    TgMAT_F32_44                                m_xFrustum_W2C; //« World to Camera (View)
    TgMAT_F32_44                                m_xFrustum_C2S; //« Camera to Screen (Proj)
    TgMAT_F32_44                                m_xFrustum_W2S; //« World to Screen
    TgMAT_F32_44                                m_xFrustum_C2W; //« Camera to World (Inverse View)
    TgMAT_F32_44                                m_xFrustum_S2C; //« Screen to Camera (Inverse Proj)
    TgMAT_F32_44                                m_xFrustum_S2W; //« Screen to World

                                                // Frustum description
    TgVEC_F32_04                                m_vFrustum_Planes[ETgFRUSTUM_PLANE__MAX]; //« Non-Normalized Plane Equations
    TgVEC_F32_04                                m_vFrustum_Centroid; //« Centre of the frustum - used for a bounding sphere
    TgVEC_F32_04                                m_vFrustum_Min, m_vFrustum_Max; //« Frustum bounds - used for a bounding aabb
    TgFLOAT32                                   m_fFrustum_Radius_Squared; //« Centre to bounds - used for bounding sphere
} STg2_RN_Cxt_Camera;
TgTYPE_PREFIX(STg2_RN_Cxt_Camera);

typedef struct
{
    TgMAT_F32_34                                m_tmTX; //« Local transform - this will place the object in world space
    TgMAT_F32_34                                m_tmLast_TX;

    TgRN_MESH_ID                                m_tiMesh; //« Specific mesh to be rendered
    TgSINT32                                    m_uiBody_Skeleton; //« Body skeleton index used by this mesh, default is -1 (rigid)
    TgSINT32                                    m_uiFace_Skeleton; //« Face skeleton index used by this mesh, default is -1 (rigid)
    TgUINT32                                    m_uiMesh_Flag;

    TgVEC_F32_04                                m_vAmbient;
    TgVEC_F32_04                                m_vLM; //« Light map rect (texture space) definition.
    TgRN_TX_IMG_ID                              m_tiLM; //« Default is a black texture
    TgRN_MT_ID                                  m_tiMaterial;
    TgFLOAT32                                   m_fOpacity; //« Default is 1.0 - Used to for mesh specific override (alpha fade).
    TgUINT32                                    m_auiLight[ETgRN_CXT_MAX_LIGHT_PER_INSTANCE];
    TgUINT32                                    m_nuiLight;
} STg2_RN_Cxt_Mesh;
TgTYPE_PREFIX(STg2_RN_Cxt_Mesh);

typedef union // Light
{
    TgMAT_F32_44                                m_tmData0;
    struct
    {
        TgVEC_F32_04                                tvParam0; //« World Position, and UnBound Flag
        TgVEC_F32_04                                tvParam1; //« World Direction, and Inverse Range Squared
        TgVEC_F32_04                                tvParam2; //« Diffuse Colour and Spot Half Angle
        TgVEC_F32_04                                tvParam3; //« Specular Colour, and Length
    }                                           m;
} STg2_RN_Light;
TgTYPE_PREFIX(STg2_RN_Light);

typedef struct // Shadow
{
    TgMAT_F32_44                                m_xFrustum;
    TgVEC_F32_04                                m_vMin_BA;
    TgVEC_F32_04                                m_vMax_BA;
    TgFLOAT32                                   m_fNear, m_fFar;
    TgUINT32                                    m_tiLight; //« Index into the light list in the context
    TgUINT32                                    m_auiCaster_Index[ETgRN_CXT_MAX_MESH]; //« Index into the context mesh list
    TgUINT32                                    m_nuiCaster;
    TgUINT32                                    m_auiReceiver_Index[ETgRN_CXT_MAX_MESH]; //« Index into the context mesh list
    TgUINT32                                    m_nuiReceiver;
} STg2_RN_Cxt_Shadow;
TgTYPE_PREFIX(STg2_RN_Cxt_Shadow);

TgTYPE_DECLARE( struct STg2_RN_Cxt_Release_Set, STg2_RN_Cxt_Release_Set );
struct STg2_RN_Cxt_Release_Set
{
    TgRN_MESH_SET_ID                            m_atiMesh_Set[ETgRN_REL_MAX_MESH];
    TgSINT32                                    m_niMesh_Set;
    TgRN_MT_ID                                  m_atiMaterial[ETgRN_REL_MAX_MATERIAL];
    TgSINT32                                    m_niMaterial;
    TgRN_TX_IMG_ID                              m_atiTexture[ETgRN_REL_MAX_TEXTURE];
    TgSINT32                                    m_niTexture;

    P_STg1_MP_SM                                m_psLock; //« If NULL the structure is pool freed, else the lock will be released
    P_STg2_RN_Cxt_Release_Set                   m_psNext;

    TgSINT32                                    m_iMarker;
};


// -- System Data --------------------------------------------------------------------------------------------------------------- //

typedef struct
{
    TgUINT32                                    m_uiContext_Index; //« Index of the place holder mesh set in the context
    TgRN_MESH_ID                                m_tiMesh; //« Mesh ID if the particle is a mesh object
    TgRN_MT_ID                                  m_tiMaterial;
    TgUINT32                                    m_uiOffset; //« Offset into the particle buffer
    TgUINT32                                    m_nuiVertex; //« Number of vertices in the buffer section
    ETgRN_VERTEX                                m_enVertex; //« Vertex type stored in the buffer section
    ETgRN_PRIMITIVE_TYPE                        m_enPrimitive_Type;
} STg2_RN_Particle_Header;
TgTYPE_PREFIX(STg2_RN_Particle_Header);

typedef struct
{
    TgUINT32                                    m_uiDebug_Field;
    TgSINT32                                    m_iX, m_iY;
    TgCOLOUR32                                  m_sColour;
    TgSINT32                                    m_iStart_X;
} STg2_RN_Text_Header;
TgTYPE_PREFIX(STg2_RN_Text_Header);


#endif //  END  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////