[2270] | 1 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 2 | //
|
---|
| 3 | // ## ######
|
---|
| 4 | // ###### ###
|
---|
| 5 | // ## ############### Shark 3D Engine (www.shark3d.com)
|
---|
| 6 | // ########## # # #
|
---|
| 7 | // ######## Copyright (c) 1996-2006 Spinor GmbH.
|
---|
| 8 | // ######### # # # All rights reserved.
|
---|
| 9 | // ## ##########
|
---|
| 10 | // ##
|
---|
| 11 | //
|
---|
| 12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 13 |
|
---|
| 14 | //@cpp
|
---|
| 15 |
|
---|
| 16 | #include "eng_shader_special_worldmat.h"
|
---|
| 17 | #include "../../util/eng_util_gfxutil.h"
|
---|
| 18 | #include "../../util/eng_util_shaderutil.h"
|
---|
| 19 | #include "../../util/eng_util_mathutil.h"
|
---|
| 20 | #include "../../../drv/interf/drv_vartypes.h"
|
---|
| 21 | #include "../../../drv/util/drv_util_varutil.h"
|
---|
| 22 | #include "../../../util/snk/util_snk_extractutil.h"
|
---|
| 23 | #include "../../../util/math/util_geo_types.h"
|
---|
| 24 |
|
---|
| 25 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 26 | /*@{
|
---|
| 27 |
|
---|
| 28 | @declare{shadercomp.class}{eng_shader_special.worldmat}{}
|
---|
| 29 |
|
---|
| 30 | Provides a matrix which maps from view coordinates
|
---|
| 31 | in world coordinates.
|
---|
| 32 | @p
|
---|
| 33 |
|
---|
| 34 | Important warning!
|
---|
| 35 | Usually, if you need this matrix something is wrong!
|
---|
| 36 | See @ref{prog_man.shader.coord_systems}.
|
---|
| 37 | @p
|
---|
| 38 |
|
---|
| 39 | @}*/
|
---|
| 40 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 41 |
|
---|
| 42 | S3D_UTIL_RTTI_TABLE_DEFINE_BEGIN(s3d_CEngShaderSpecialWorldMat)
|
---|
| 43 | S3D_UTIL_RTTI_TABLE_DEFINE_BASE(s3d_CEngShader)
|
---|
| 44 | S3D_UTIL_RTTI_TABLE_DEFINE_BASE(s3d_CCompUtilUniqueBase)
|
---|
| 45 | S3D_UTIL_RTTI_TABLE_DEFINE_BASE(s3d_CCompSetup)
|
---|
| 46 | S3D_UTIL_RTTI_TABLE_DEFINE_END
|
---|
| 47 |
|
---|
| 48 | s3d_CEngShaderSpecialWorldMat::s3d_CEngShaderSpecialWorldMat()
|
---|
| 49 | {
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | void s3d_CEngShaderSpecialWorldMat::SetupInit(
|
---|
| 53 | s3d_CUtilMsgHandler *MsgHandler, s3d_CUtilStr_cr Info,
|
---|
| 54 | s3d_CCompSuppl *FetchSuppl, s3d_CUtilSnkChunk *Param)
|
---|
| 55 | {
|
---|
| 56 | m_Data = S3D_SYS_NEW s3d_CEngShaderSpecialWorldMatData;
|
---|
| 57 |
|
---|
| 58 | s3d_CUtilSnkExtract SnkExtract;
|
---|
| 59 | SnkExtract.Assign(MsgHandler, Param);
|
---|
| 60 | m_Data->m_Info = SnkExtract.GetInfo();
|
---|
| 61 |
|
---|
| 62 | /*@{ @declare{shadercomp.param}{eng_shader_special.worldmat.env}{$ [str]}
|
---|
| 63 | See @ident{comp}{eng_shader_std.group.env}.
|
---|
| 64 | @}*/
|
---|
| 65 | s3d_CUtilStr EnvIdent, EnvInfo;
|
---|
| 66 | SnkExtract.ExtractStr(EnvInfo, EnvIdent, "env", true);
|
---|
| 67 |
|
---|
| 68 | m_ShaderEnv = s3d_CompSupplObjT<s3d_CEngShaderEnv>(
|
---|
| 69 | MsgHandler, EnvInfo, FetchSuppl,
|
---|
| 70 | EnvIdent, S3D_GENERAL_INTEROP_INTERF);
|
---|
| 71 | if(!m_ShaderEnv)
|
---|
| 72 | return;
|
---|
| 73 |
|
---|
| 74 | /*@{ @declare{shadercomp.param}{eng_shader_special.worldmat.methods}
|
---|
| 75 | {$ [str] .. [str]}
|
---|
| 76 | See @ref{prog_man.shader.methods}.
|
---|
| 77 | @}*/
|
---|
| 78 | s3d_CUtilSnkExtractUtil::ExtractAtomSortedArray(
|
---|
| 79 | m_Data->m_MethodArray, m_ShaderEnv->m_AtomMgr,
|
---|
| 80 | SnkExtract, "methods", true);
|
---|
| 81 |
|
---|
| 82 | /*@{ @declare{shadercomp.param}
|
---|
| 83 | {eng_shader_special.worldmat.worldmat_var}{$ [str]}
|
---|
| 84 | The variable stores the resulting matrix.
|
---|
| 85 | The variable is of type mat4x4f.
|
---|
| 86 | @}*/
|
---|
| 87 | s3d_CUtilSnkExtractUtil::ExtractAtom(
|
---|
| 88 | m_Data->m_WorldMatVarInfo, m_Data->m_WorldMatVarAtom,
|
---|
| 89 | m_ShaderEnv->m_AtomMgr, SnkExtract, "worldmat_var", true);
|
---|
| 90 |
|
---|
| 91 | /*@{ @declare{shadercomp.param}
|
---|
| 92 | {eng_shader_special.worldmat.inverse}{$ [bool]}
|
---|
| 93 | Sets if the matrix should be inverted.
|
---|
| 94 | @}*/
|
---|
| 95 | m_Data->m_Inverse = SnkExtract.ExtractBool("inverse", true, false);
|
---|
| 96 | /*@{ @declare{shadercomp.param}
|
---|
| 97 | {eng_shader_special.worldmat.transpose}{$ [bool]}
|
---|
| 98 | Sets if the matrix should be transposed.
|
---|
| 99 | @}*/
|
---|
| 100 | m_Data->m_Transpose = SnkExtract.ExtractBool("transpose", true, false);
|
---|
| 101 |
|
---|
| 102 | SnkExtract.CheckForUnknown();
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | void s3d_CEngShaderSpecialWorldMat::SetupDone()
|
---|
| 106 | {
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | s3d_CUtilStr s3d_CEngShaderSpecialWorldMat::GetInfo()
|
---|
| 110 | {
|
---|
| 111 | return m_Data->m_Info;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | void s3d_CEngShaderSpecialWorldMat::RegisterNotif(s3d_CUtilNotifRecip *Recip)
|
---|
| 115 | {
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | s3d_CEngShaderGfxPtr s3d_CEngShaderSpecialWorldMat::FindShaderGfx(
|
---|
| 119 | s3d_CUtilNotifGather *NotifGather, s3d_CEngGfxCtx *GfxCtx)
|
---|
| 120 | {
|
---|
| 121 | if(!m_ShaderEnv)
|
---|
| 122 | return 0;
|
---|
| 123 |
|
---|
| 124 | s3d_CEngShaderSpecialWorldMatGfxPtr ShaderGfx;
|
---|
| 125 |
|
---|
| 126 | s3d_CEngShaderSpecialWorldMatGfxTree::CNode *Pos
|
---|
| 127 | = s3d_UtilTreeSortedGetStart(m_ShaderGfxTree, GfxCtx);
|
---|
| 128 | if(s3d_UtilTreeIsEqualAt(Pos, GfxCtx))
|
---|
| 129 | ShaderGfx = Pos->m_Data.m_Val;
|
---|
| 130 | else
|
---|
| 131 | {
|
---|
| 132 | ShaderGfx = S3D_SYS_NEW s3d_CEngShaderSpecialWorldMatGfx(
|
---|
| 133 | m_ShaderEnv, GfxCtx, m_Data);
|
---|
| 134 | s3d_CEngShaderSpecialWorldMatGfxTree::CNode *Node
|
---|
| 135 | = ShaderGfx->GetNode();
|
---|
| 136 | m_ShaderGfxTree.InsertBefore(Pos, Node);
|
---|
| 137 | }
|
---|
| 138 | return ShaderGfx.Get();
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 142 |
|
---|
| 143 | s3d_CEngShaderSpecialWorldMatGfx::s3d_CEngShaderSpecialWorldMatGfx(
|
---|
| 144 | s3d_CEngShaderEnv *ShaderEnv, s3d_CEngGfxCtx *GfxCtx,
|
---|
| 145 | s3d_CEngShaderSpecialWorldMatData *Data)
|
---|
| 146 | {
|
---|
| 147 | m_Node.m_Data.m_Key = GfxCtx;
|
---|
| 148 | m_Node.m_Data.m_Val = this;
|
---|
| 149 | m_ShaderEnv = ShaderEnv;
|
---|
| 150 | m_Data = Data;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | s3d_CEngShaderSpecialWorldMatGfxTree::CNode *
|
---|
| 154 | s3d_CEngShaderSpecialWorldMatGfx::GetNode()
|
---|
| 155 | {
|
---|
| 156 | return &m_Node;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | void s3d_CEngShaderSpecialWorldMatGfx::RegisterNotif(
|
---|
| 160 | s3d_CUtilNotifRecip *Recip)
|
---|
| 161 | {
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | void s3d_CEngShaderSpecialWorldMatGfx::ExtractGfx()
|
---|
| 165 | {
|
---|
| 166 | m_Node.Extract();
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | bool s3d_CEngShaderSpecialWorldMatGfx::IsValid()
|
---|
| 170 | {
|
---|
| 171 | return true;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | void s3d_CEngShaderSpecialWorldMatGfx::LinkCollect(
|
---|
| 175 | s3d_CUtilAtomSet &VarAtomSet)
|
---|
| 176 | {
|
---|
| 177 | s3d_CDrvUtilVarUtil::LinkCollect(
|
---|
| 178 | VarAtomSet, m_Data->m_WorldMatVarAtom);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | void s3d_CEngShaderSpecialWorldMatGfx::LinkAppoint(
|
---|
| 182 | s3d_CDrvVarDecl *VarDecl)
|
---|
| 183 | {
|
---|
| 184 | s3d_CDrvUtilVarUtil::LinkAppoint(
|
---|
| 185 | m_WorldMatVarSlot.m_Val,
|
---|
| 186 | VarDecl, m_Data->m_WorldMatVarAtom);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | s3d_CEngShaderInstPtr s3d_CEngShaderSpecialWorldMatGfx::CreateShaderInst(
|
---|
| 190 | s3d_CEngShaderHead *Head)
|
---|
| 191 | {
|
---|
| 192 | return S3D_SYS_NEW s3d_CEngShaderSpecialWorldMatInst(
|
---|
| 193 | m_ShaderEnv, this);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 197 |
|
---|
| 198 | s3d_CEngShaderSpecialWorldMatInst::s3d_CEngShaderSpecialWorldMatInst(
|
---|
| 199 | s3d_CEngShaderEnv *ShaderEnv,
|
---|
| 200 | s3d_CEngShaderSpecialWorldMatGfx *ShaderGfx)
|
---|
| 201 | {
|
---|
| 202 | m_ShaderEnv = ShaderEnv;
|
---|
| 203 | m_ShaderGfx = ShaderGfx;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | void s3d_CEngShaderSpecialWorldMatInst::RegisterNotif(
|
---|
| 207 | s3d_CUtilNotifRecip *Recip)
|
---|
| 208 | {
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | void s3d_CEngShaderSpecialWorldMatInst::SetShaderCtx(
|
---|
| 212 | s3d_CEngShaderCtx *ShaderCtx)
|
---|
| 213 | {
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | void s3d_CEngShaderSpecialWorldMatInst::SetGfxState(s3d_CEngGfxState *GfxState)
|
---|
| 217 | {
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | void s3d_CEngShaderSpecialWorldMatInst::SetPos(s3d_CEngPos *Pos)
|
---|
| 221 | {
|
---|
| 222 | m_Pos = Pos;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | void s3d_CEngShaderSpecialWorldMatInst::SetModel(s3d_CEngModel *Model)
|
---|
| 226 | {
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | void s3d_CEngShaderSpecialWorldMatInst::ArrangeCollect(
|
---|
| 230 | s3d_CUtilMemPool *MemPool,
|
---|
| 231 | s3d_CEngShaderScopeArray &ScopeArray)
|
---|
| 232 | {
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | void s3d_CEngShaderSpecialWorldMatInst::ArrangeInit(
|
---|
| 236 | s3d_CUtilMemPool *MemPool,
|
---|
| 237 | s3d_CEngShaderScopeArray_cr ScopeArray)
|
---|
| 238 | {
|
---|
| 239 | s3d_CSysIntps nScope = ScopeArray.GetCnt();
|
---|
| 240 | s3d_CSysIntps iScope;
|
---|
| 241 | for(iScope = 0; iScope < nScope; iScope++)
|
---|
| 242 | {
|
---|
| 243 | s3d_CEngShaderScope *Scope = ScopeArray.GetAt(iScope);
|
---|
| 244 | SetVars(MemPool, Scope);
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | void s3d_CEngShaderSpecialWorldMatInst::ArrangePerform(
|
---|
| 249 | s3d_CUtilMemPool *MemPool,
|
---|
| 250 | s3d_CEngShaderScopeArray_cr ScopeArray)
|
---|
| 251 | {
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | void s3d_CEngShaderSpecialWorldMatInst::ArrangeFeedback(
|
---|
| 255 | s3d_CUtilMemPool *MemPool,
|
---|
| 256 | s3d_CEngShaderScopeArray_cr ScopeArray)
|
---|
| 257 | {
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | void s3d_CEngShaderSpecialWorldMatInst::ArrangeGather(
|
---|
| 261 | s3d_CEngShaderExecArray &ExecArray)
|
---|
| 262 | {
|
---|
| 263 | s3d_CEngShaderSpecialWorldMatData *Data = m_ShaderGfx->m_Data;
|
---|
| 264 |
|
---|
| 265 | s3d_CEngUtilShaderUtil::ArrangeGather(
|
---|
| 266 | ExecArray, Data->m_MethodArray, this);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | void s3d_CEngShaderSpecialWorldMatInst::ShaderExecPerform(
|
---|
| 270 | s3d_CEngShaderScope *Scope,
|
---|
| 271 | s3d_CUtilAtom *Method,
|
---|
| 272 | s3d_CEngGfxTaskArray &TaskArray)
|
---|
| 273 | {
|
---|
| 274 | SetVars(m_ShaderEnv->m_MemPool, Scope);
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | void s3d_CEngShaderSpecialWorldMatInst::SetVars(
|
---|
| 278 | s3d_CUtilMemPool *MemPool, s3d_CEngShaderScope *Scope)
|
---|
| 279 | {
|
---|
| 280 | s3d_CEngShaderSpecialWorldMatGfx *ShaderGfx = m_ShaderGfx;
|
---|
| 281 | s3d_CEngShaderSpecialWorldMatData *Data = ShaderGfx->m_Data;
|
---|
| 282 |
|
---|
| 283 | s3d_CDrvVarSlot WorldMatVarSlot = ShaderGfx->m_WorldMatVarSlot;
|
---|
| 284 | if(WorldMatVarSlot >= 0)
|
---|
| 285 | {
|
---|
| 286 | s3d_CEngGfxPortion *Portion = Scope->m_Portion;
|
---|
| 287 | if(Portion)
|
---|
| 288 | {
|
---|
| 289 | s3d_CUtilMat4x4f WorldMat;
|
---|
| 290 | if(!Data->m_Inverse)
|
---|
| 291 | WorldMat = s3d_CUtilGeof::GetMapOfTransf3(Portion->m_Cam.m_Transf);
|
---|
| 292 | else
|
---|
| 293 | WorldMat = s3d_CUtilGeof::GetMapOfInvTransf3(Portion->m_Cam.m_Transf);
|
---|
| 294 |
|
---|
| 295 | if(Data->m_Transpose)
|
---|
| 296 | WorldMat = WorldMat.GetTransp();
|
---|
| 297 |
|
---|
| 298 | s3d_CDrvVarMat4x4f *WorldMatVar = new(MemPool) s3d_CDrvVarMat4x4f;
|
---|
| 299 | WorldMatVar->m_Val = WorldMat;
|
---|
| 300 | s3d_DrvVarSet(Scope->m_VarBlk, WorldMatVarSlot, WorldMatVar);
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 306 |
|
---|