void TSRModel::LoadFromMesh( TSRModel* _pModel, TSRIndexedMesh* _pIndexedMesh, TSRBBox& _boundBox ) { _pModel->m_uiGeometriesCount = 1; _pModel->m_pGeometries = new TSRModelGeometry[ 1 ]; _pModel->m_BoundBox = _boundBox; TSRModelGeometry* pGeometry = _pModel->m_pGeometries; pGeometry->m_uiShaderFlags = _pIndexedMesh->m_pVertexDeclaration->CalculateShaderFlags(); pGeometry->m_pMesh = _pIndexedMesh; pGeometry->m_uiTriangleSetsCount = 1; pGeometry->m_pTriangleSets = new TSRModelGeometryTriangleSet[ 1 ]; pGeometry->m_Bounds = _boundBox; //pGeometry->m_uiRasterizerStateId = 1; TSRModelGeometryTriangleSet* pTriangleSet = pGeometry->m_pTriangleSets; pTriangleSet->m_uiStartIndex = 0; pTriangleSet->m_uiIndexCount = _pIndexedMesh->GetIndexCount(); if ( _pIndexedMesh->GetIndexCount() == 0 ) { pTriangleSet->m_uiIndexCount = _pIndexedMesh->GetVertexBuffer()->m_uiVertexCount; } pTriangleSet->m_renderMode = TWISTER_RENDERMODE_TRIANGLES; pTriangleSet->m_uiMaterialIndex = 0; _pModel->m_uiTexturesCount = 2; _pModel->m_ppTextures = new TSRTexture*[ 2 ]; _pModel->m_pModelTextures = new TSRModelTexture[ _pModel->m_uiTexturesCount ]; /// white and default normal are always first 2 textures.. _pModel->m_ppTextures[ 0 ] = TextureManager()->GetWhite(); _pModel->m_ppTextures[ 1 ] = TextureManager()->GetDefaultNormal(); _pModel->m_uiMaterialsCount = 1; _pModel->m_pMaterials = new TSRModelMaterial[ 1 ]; TSRModelMaterial* pModelMaterial = _pModel->m_pMaterials; pModelMaterial->m_fTransparency = 1.0f; _pModel->m_uiRenderNodesCount = 1; _pModel->m_pRenderNodes = new TSRModelRenderNode[ 1 ]; _pModel->m_pRenderNodes[ 0 ].m_WorldTransform.MakeIdent(); _pModel->m_pRenderNodes[ 0 ].m_uiGeometriesCount = 1; _pModel->m_pRenderNodes[ 0 ].m_pGeometriesIndices = new int[ 1 ]; _pModel->m_pRenderNodes[ 0 ].m_pGeometriesIndices[ 0 ] = 0; _pModel->m_RootNode.m_iRenderNodeIndex = 0; _pModel->m_RootNode.m_LocalTransform.MakeIdent(); _pModel->m_uiEffectsCount = 1; _pModel->m_ppEffects = new TSREffect*[ 1 ]; _pModel->m_ppEffects[ 0 ] = EffectManager()->Aquire( "supershader.fx" ); snprintf( _pModel->m_RootNode.m_Name, 32, "OBJ_RootNode" ); }
Manager::Manager( const char* name, int width, int height, Engine::WindowMode wm ): RTTI_CLASS_DEFINE( Manager ), m_engine( 0 ), m_game( 0 ), m_pushState( 0 ), m_progressState( 0 ), m_progressStateDefault( 0 ), m_popState( false ), m_changeState( false ), m_loading( false ), m_states( 0 ), m_scenes( 0 ), m_materials( 0 ), m_effects( 0 ), m_fonts( 0 ), m_textures( 0 ), m_canvases( 0 ), m_assets( 0 ), m_assetsLoading( 0 ), m_actors( 0 ), m_controls( 0 ), m_collisions( 0 ), m_audio( 0 ) { m_engine = xnew Engine(); m_engine->initiation( name, width, height, wm ); m_states = xnew Stack< IState >(); m_scenes = xnew SceneManager(); m_materials = xnew MaterialManager(); m_effects = xnew EffectManager(); m_fonts = xnew FontManager(); m_textures = xnew TextureManager(); m_canvases = xnew CanvasManager(); m_assets = xnew AssetManager(); m_assetsLoading = xnew AssetManager(); m_actors = xnew Stack< ActorManager >(); m_controls = xnew Stack< ControlManager >(); m_collisions = xnew Stack< CollisionManager >(); m_audio = xnew AudioManager(); Global::use().engine = m_engine; Global::use().scenes = m_scenes; Global::use().materials = m_materials; Global::use().effects = m_effects; Global::use().fonts = m_fonts; Global::use().textures = m_textures; Global::use().canvases = m_canvases; Global::use().assets = m_assets; Global::use().assetsLoading = m_assetsLoading; Global::use().actors = 0; Global::use().controls = 0; Global::use().collisions = 0; Global::use().audio = m_audio; }
KVOID AppFrame::CreateWidgets() { if (!OgreRoot::Initialized()) KNEW OgreRoot(); if (!DataManager::Initialized()) KNEW DataManager(); ////////////////////////////////////////////////////////////////////////// m_pSceneMgr = m_pRoot->createSceneManager("OctreeSceneManager");//Ogre::ST_EXTERIOR_CLOSE); // set shadow properties // m_pSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_NONE); // m_pSceneMgr->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5)); // m_pSceneMgr->setShadowTextureSize(1024); // m_pSceneMgr->setShadowTextureCount(1); ////////////////////////////////////////////////////////////////////////// Ogre::Camera* pCam = OgreRoot::GetSingletonPtr()->CreateCamera("$MainCamera"); if (pCam) { OgreRoot::GetSingletonPtr()->CreateViewports(pCam); } // splash Kylin::LoadingProgress* pLoading = KNEW Kylin::LoadingProgress(); pLoading->Initialize(); pLoading->SetVisible(true); ////////////////////////////////////////////////////////////////////////// Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); ////////////////////////////////////////////////////////////////////////// m_pInputMgr = KNEW InputManager(); m_pInputMgr->Initialize(); ////////////////////////////////////////////////////////////////////////// m_pGuiMgr = KNEW GuiManager(); m_pGuiMgr->Create(m_pWindow,m_pSceneMgr); m_pGuiMgr->RegisterGui(pLoading); ////////////////////////////////////////////////////////////////////////// m_pScriptVM = KNEW ScriptVM(); if(m_pScriptVM->Init()) { OpenScriptBinding(m_pScriptVM->GetLuaState()); m_pScriptVM->ExecuteScriptFile("./Data/script/startvm.lua"); } ////////////////////////////////////////////////////////////////////////// if (!EffectManager::Initialized()) KNEW EffectManager(); EffectManager::GetSingletonPtr()->Initialize(); OgreOggSound::OgreOggSoundManager::getSingletonPtr()->init(); ////////////////////////////////////////////////////////////////////////// if (!m_pRenderableMgr) m_pRenderableMgr = KNEW RenderableManager();
void CSprite::Init(CTexture* texture) { m_effect = EffectManager().LoadEffect("Assets/presetShader/sprite.fx"); static SShapeVertex_PT vertex[]{ { -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f }, { -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f }, { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f }, }; static unsigned short index[] = { 0,1,2,3 }; m_primitive.Create( CPrimitive::eTriangleStrip, 4, sizeof(SShapeVertex_PT), scShapeVertex_PT_Element, vertex, 4, eIndexFormat16, index ); m_texture = texture; m_size.x = s_cast<float>(m_texture->GetWidth()); m_size.y = s_cast<float>(m_texture->GetHeight()); }
#include "effect_manager.h" EffectManager EffectManager::instance = EffectManager(); EffectManager& EffectManager::getInstance() { return EffectManager::instance; } void EffectManager::beforeRender(Context& context) { context.setStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); context.setStencilFunc(GL_ALWAYS, 1, 0xFF); // passes stencil test always context.setStencilMask(0xFF); // enable writing to stencil buffer } void EffectManager::beforeOutline(Context& context) { context.setStencilFunc(GL_NOTEQUAL, 1, 0xFF); // passes stencil test if value is not equal to 1 context.setStencilMask(0x00); // disable writing to stencil buffer context.setDepthTest(false); } void EffectManager::afterOutline(Context& context) { context.setDepthTest(true); context.setStencilMask(0xFF); }
void TSRModel::LoadGeometry( TSRModelGeometry* _pGeometry, TSRFileStream* _pFptr ) { // read number of vertex components.. unsigned int uiShaderFlags = 0; fread( &uiShaderFlags, sizeof( unsigned int ), 1, _pFptr ); // compile the vertex declaration _pGeometry->m_uiShaderFlags = uiShaderFlags; TSRVertexDeclaration* pVertexDecl = EffectManager()->GetDeclaration( uiShaderFlags ); // read vertex count unsigned int uiVertexCount = 0; fread( &uiVertexCount, sizeof( unsigned int ), 1, _pFptr ); // the size of the vertex buffer... unsigned int uiVertexBufferSize = 0; fread( &uiVertexBufferSize, sizeof( unsigned int ), 1, _pFptr ); /// index data type.. eTSRDataType indexDataType = TWISTER_DATATYPE_UINT32; /// read index data type.. fread( &indexDataType, sizeof( eTSRDataType ), 1, _pFptr ); unsigned int uiIndexCount = 0; fread( &uiIndexCount, sizeof( unsigned int ), 1, _pFptr ); // now create the mesh... TSRIndexedMesh* pNewMesh = new TSRIndexedMesh( pVertexDecl, indexDataType ); unsigned int uiIndexDataSize = uiIndexCount * g_TwisterDataTypeSize[ indexDataType ]; /// never create buffers larger than the loading buffers if ( uiIndexDataSize > ModelManager()->s_uiLoadingIndexBufferSize ) { assert( "You Cannot Create Index buffers this large!" && 0 ); } /// never create buffers larger than the loading buffers if ( uiVertexBufferSize > ModelManager()->s_uiLoadingVertexBufferSize ) { assert( "You Cannot Create Vertex buffers this large!" && 0 ); } /// read the vertex and index in one go. if ( uiVertexCount ) { fread( ModelManager()->GetVertexLoadingBuffer(), uiVertexBufferSize, 1, _pFptr ); if ( uiIndexCount ) { fread( ModelManager()->GetIndexLoadingBuffer(), g_TwisterDataTypeSize[ indexDataType ], uiIndexCount, _pFptr ); } } if ( uiIndexCount > 0 ) { pNewMesh->FillRaw( ModelManager()->GetVertexLoadingBuffer(), uiVertexBufferSize, ModelManager()->GetIndexLoadingBuffer(), uiIndexDataSize, indexDataType ); } else { pNewMesh->TSRMesh::FillRaw( ModelManager()->GetVertexLoadingBuffer(), uiVertexBufferSize ); } unsigned int uiTriangleSetsCount = 0; fread( &uiTriangleSetsCount, sizeof( int ), 1, _pFptr ); _pGeometry->m_uiTriangleSetsCount = uiTriangleSetsCount; if ( uiTriangleSetsCount ) { _pGeometry->m_pTriangleSets = new TSRModelGeometryTriangleSet[ uiTriangleSetsCount ]; fread( _pGeometry->m_pTriangleSets, sizeof( TSRModelGeometryTriangleSet ), uiTriangleSetsCount, _pFptr ); } pNewMesh->m_RenderMode = TWISTER_RENDERMODE_TRIANGLES; #ifdef D3D11_RENDERER if ( uiShaderFlags & TWISTER_SHADER_FLAG_TESSELATION ) { pNewMesh->m_RenderMode = TWISTER_RENDERMODE_TRIPATCHLIST; for ( unsigned int i = 0; i < uiTriangleSetsCount; i++ ) { _pGeometry->m_pTriangleSets[ i ].m_renderMode = TWISTER_RENDERMODE_TRIPATCHLIST; } } #endif // geometry is ready for rendering ! _pGeometry->m_pMesh = pNewMesh; // read the bounds fread( &_pGeometry->m_Bounds, sizeof( TSRBBox ), 1, _pFptr ); // read the raster state fread( &_pGeometry->m_uiRasterizerStateId, sizeof( unsigned int ), 1, _pFptr ); }
void TSRModel::LoadModel( TSRModel* pModel, const char* _pFileName ) { /// new : if this is a .obj file, we create a dummy model around its mesh string strFilename = _pFileName; string strExtension = strFilename.substr( strlen( _pFileName ) - 3, strlen( _pFileName ) ); if ( strExtension == "obj" ) { LoadFromOBJ( pModel, _pFileName ); return; } TSRFileStream* fptr = TSRFileSystem::OpenFileStream( _pFileName, "rb" ); // first read the version unsigned int uiVersion = 0; fread( &uiVersion, sizeof( unsigned int ), 1, fptr ); // read geometries fread( &pModel->m_uiGeometriesCount, sizeof( unsigned int ), 1, fptr ); if ( pModel->m_uiGeometriesCount > 0 ) { pModel->m_pGeometries = new TSRModelGeometry[ pModel->m_uiGeometriesCount ]; } for ( unsigned int i = 0; i < pModel->m_uiGeometriesCount; i++ ) { LoadGeometry( pModel->m_pGeometries + i, fptr ); } /// read skinned geometries fread( &pModel->m_uiSkinnedGeometriesCount, sizeof( unsigned int ), 1, fptr ); if ( pModel->m_uiSkinnedGeometriesCount ) { pModel->m_pSkinnedGeometries = new TSRModelSkinnedGeometry[ pModel->m_uiSkinnedGeometriesCount ]; } for ( unsigned int i = 0; i < pModel->m_uiSkinnedGeometriesCount; i++ ) { LoadSkinnedGeometry( pModel->m_pSkinnedGeometries + i, fptr ); } /// read effects fread( &pModel->m_uiEffectsCount, sizeof( unsigned int ), 1, fptr ); if ( pModel->m_uiEffectsCount > 0 ) { pModel->m_ppEffects = new TSREffect* [ pModel->m_uiEffectsCount ]; for ( unsigned int i = 0; i < pModel->m_uiEffectsCount; i++ ) { char effectName[ 16 ]; fread( effectName, 16, 1, fptr ); pModel->m_ppEffects[ i ] = EffectManager()->Aquire( effectName ); } } /// read textures fread( &pModel->m_uiTexturesCount, sizeof( unsigned int ), 1, fptr ); pModel->m_uiTexturesCount += 2; pModel->m_pModelTextures = new TSRModelTexture[ pModel->m_uiTexturesCount ]; pModel->m_ppTextures = new TSRTexture*[ pModel->m_uiTexturesCount ]; if ( pModel->m_uiTexturesCount > 2 ) { fread( &pModel->m_pModelTextures[ 2 ], sizeof( TSRModelTexture ), pModel->m_uiTexturesCount - 2, fptr ); } /// read materials fread( &pModel->m_uiMaterialsCount, sizeof( unsigned int ), 1, fptr ); // always add one default material pModel->m_pMaterials = new TSRModelMaterial[ pModel->m_uiMaterialsCount ]; if ( pModel->m_uiMaterialsCount > 0 ) { fread( pModel->m_pMaterials, sizeof( TSRModelMaterial ), pModel->m_uiMaterialsCount, fptr ); } snprintf( pModel->m_RootNode.m_Name, 32, "RootNode" ); // read the root node transform fread( &pModel->m_RootNode.m_LocalTransform, sizeof( TSRMatrix4 ), 1, fptr ); // read number of nodes under root fread( &pModel->m_RootNode.m_uiChildrenCount, sizeof( unsigned int ), 1, fptr ); // allocate them pModel->m_RootNode.m_pChildren = new TSRModelNode[ pModel->m_RootNode.m_uiChildrenCount ]; for ( unsigned int i = 0; i < pModel->m_RootNode.m_uiChildrenCount; i++ ) { ReadModelNodesRec( pModel->m_RootNode.m_pChildren + i, fptr ); } // read the whole model aabb.. fread( &pModel->m_BoundBox, sizeof( TSRBBox ), 1, fptr ); // read number of render nodes. fread( &pModel->m_uiRenderNodesCount, sizeof( unsigned int ), 1, fptr ); if ( pModel->m_uiRenderNodesCount > 0 ) { pModel->m_pRenderNodes = new TSRModelRenderNode[ pModel->m_uiRenderNodesCount ]; } for ( unsigned int i = 0; i < pModel->m_uiRenderNodesCount; i++ ) { // allocate a new render node TSRModelRenderNode* pNewRenderNode = pModel->m_pRenderNodes + i ; // read it without the trailing pointer (world transform and the number of geometry instances) fread( pNewRenderNode, sizeof( TSRMatrix4 ) + sizeof( int ), 1, fptr ); // allocate geometry indices pNewRenderNode->m_pGeometriesIndices = new int[ pNewRenderNode->m_uiGeometriesCount ]; // read them fread( pNewRenderNode->m_pGeometriesIndices, pNewRenderNode->m_uiGeometriesCount * sizeof( int ), 1, fptr ); } /// read skinned nodes fread( &pModel->m_uiSkinnedNodesCount, sizeof( unsigned int ), 1, fptr ); if ( pModel->m_uiSkinnedNodesCount > 0 ) { pModel->m_pSkinnedNodes = new TSRModelRenderNode[ pModel->m_uiSkinnedNodesCount ]; } for ( unsigned int i = 0; i < pModel->m_uiSkinnedNodesCount; i++ ) { // allocate a new skinned node TSRModelRenderNode* pNewSkinnedNode = pModel->m_pSkinnedNodes + i ; // read it without the trailing pointer (world transform and the number of geometry instances) fread( pNewSkinnedNode, sizeof( TSRMatrix4 ) + sizeof( int ), 1, fptr ); // allocate geometry indices pNewSkinnedNode->m_pGeometriesIndices = new int[ pNewSkinnedNode->m_uiGeometriesCount ]; // read them fread( pNewSkinnedNode->m_pGeometriesIndices, pNewSkinnedNode->m_uiGeometriesCount * sizeof( int ), 1, fptr ); } // read the animations fread( &pModel->m_AnimationsCount, sizeof( unsigned int ), 1, fptr ); // allocate the animations if ( pModel->m_AnimationsCount > 0 ) { pModel->m_pAnimations = new TSRModelAnimation[ pModel->m_AnimationsCount ]; for ( unsigned int i = 0; i < pModel->m_AnimationsCount; i++ ) { LoadAnimation( pModel->m_pAnimations + i, fptr ); } } // read lights fread( &pModel->m_uiLightsCount, sizeof( unsigned int ), 1, fptr ); // allocate lights and read them in one go.. if ( pModel->m_uiLightsCount > 0 ) { pModel->m_pLights = new TSRModelLight[ pModel->m_uiLightsCount ]; fread( pModel->m_pLights, sizeof( TSRModelLight ), pModel->m_uiLightsCount, fptr ); } /// read number of light nodes fread( &pModel->m_uiLightNodesCount, sizeof( unsigned int ), 1, fptr ); if ( pModel->m_uiLightNodesCount > 0 ) { pModel->m_pLightNodesIndices = new unsigned int[ pModel->m_uiLightNodesCount ]; fread( pModel->m_pLightNodesIndices, sizeof( unsigned int ), pModel->m_uiLightNodesCount, fptr ); } /// read number of bones and create the skeleton matrix data fread( &pModel->m_uiBonesCount, sizeof( unsigned int ), 1, fptr ); fclose( fptr ); /// white and default normal are always first 2 textures.. pModel->m_ppTextures[ 0 ] = TextureManager()->GetWhite(); pModel->m_ppTextures[ 1 ] = TextureManager()->GetDefaultNormal(); // change the current working directory according to the file's path, so textures can be read properly string fullPath = _pFileName; int iSlashPosition = ( int ) fullPath.find_last_of( "/" ); string textureFileNameHeader = ""; if ( iSlashPosition == -1 ) { iSlashPosition = ( int ) fullPath.find_last_of( "\\" ); } if ( iSlashPosition > -1 ) { textureFileNameHeader = fullPath.substr( 0, iSlashPosition + 1 ); } string textureFileName; // change directory if needed before getting the textures.. for ( unsigned int i = 2; i < pModel->m_uiTexturesCount; i++ ) { textureFileName = textureFileNameHeader + pModel->m_pModelTextures[ i ].m_Name; pModel->m_ppTextures[ i ] = TextureManager()->Aquire( textureFileName.c_str() ); } }
void CMonochromeFilter::Create(const SGraphicsConfig& config) { m_effect = EffectManager().LoadEffect("Assets/presetShader/monochromeFilter.fx"); }
void CParticle::Init(CRandom& random, const CCamera& camera, const SParicleEmitParameter& param, const CVector3& emitPosition ) { float halfW = param.w * 0.5f; float halfH = param.h * 0.5f; TK_ASSERT(param.uvTableSize <= ARRAYSIZE(param.uvTable), "uvTable size over!!!"); CVector4 uv; if (param.uvTableSize > 0) { uv = param.uvTable[random.GetRandInt() % param.uvTableSize]; } else { uv = param.uvTable[0]; } SShapeVertex_PT vb[] = { { -halfW, halfH, 0.0f, 1.0f, uv.x, uv.y }, { halfW, halfH, 0.0f, 1.0f, uv.z, uv.y }, { -halfW, -halfH, 0.0f, 1.0f, uv.x, uv.w }, { halfW, -halfH, 0.0f, 1.0f, uv.z, uv.w }, }; short index[]{ 0,1,2,3 }; primitive.Create( CPrimitive::eTriangleStrip, 4, sizeof(SShapeVertex_PT), scShapeVertex_PT_Element, vb, 4, eIndexFormat16, index ); texture = ParticleResources().LoadTexture(param.texturePath); shaderEffect = EffectManager().LoadEffect("Assets/presetShader/ColorTexPrim.fx"); this->camera = &camera; this->random = &random; life = param.life; velocity = param.initVelocity; //初速度に乱数を加える。 velocity.x += (((float)random.GetRandDouble() - 0.5f) * 2.0f) * param.initVelocityVelocityRandomMargin.x; velocity.y += (((float)random.GetRandDouble() - 0.5f) * 2.0f) * param.initVelocityVelocityRandomMargin.y; velocity.z += (((float)random.GetRandDouble() - 0.5f) * 2.0f) * param.initVelocityVelocityRandomMargin.z; position = emitPosition; position.x += (((float)random.GetRandDouble() - 0.5f) * 2.0f) * param.initPositionRandomMargin.x; position.y += (((float)random.GetRandDouble() - 0.5f) * 2.0f) * param.initPositionRandomMargin.y; position.z += (((float)random.GetRandDouble() - 0.5f) * 2.0f) * param.initPositionRandomMargin.z; addVelocityRandomMargih = param.addVelocityRandomMargih; gravity = param.gravity; isFade = param.isFade; state = eStateRun; initAlpha = param.initAlpha; alpha = initAlpha; fadeTIme = param.fadeTime; isBillboard = param.isBillboard; brightness = param.brightness; alphaBlendMode = param.alphaBlendMode; mulColor = param.mulColor; rotateZ = CMath::PI * 2.0f * (float)random.GetRandDouble(); }