void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrame /* = 0 */ ) { Assert( !IsSnapshotting() ); if ( sampler2 == -1 ) { GetShaderSystem()->BindTexture( sampler1, pTexture, nFrame ); } else { GetShaderSystem()->BindTexture( sampler1, sampler2, pTexture, nFrame ); } }
ShadersQ3API( ShadersDependencies& dependencies ){ g_shadersExtension = "shader"; g_shadersDirectory = "scripts/"; g_bitmapModule = dependencies.getBitmapModule().getTable(); Shaders_Construct(); m_shadersq3 = &GetShaderSystem(); }
/* * Return the light falloff texture (Z dimension). */ TexturePtr CShader::lightFalloffImage() { // Construct the texture if necessary if (!_texLightFalloff) { // Create image. If there is no falloff image defined, use the // default. if (_template->getLightFalloff()) { // create the image _texLightFalloff = GetTextureManager().getBinding(_template->getLightFalloff()); } else { // Find the default light shader in the ShaderSystem and query its // falloff texture name. std::string defLight = game::current::getValue<std::string>(DEFAULT_LIGHT_PATH); MaterialPtr defLightShader = GetShaderSystem()->getMaterialForName(defLight); // Cast to a CShader so we can call getFalloffName(). CShaderPtr cshaderPtr = std::static_pointer_cast<CShader>(defLightShader); // create the image _texLightFalloff = GetTextureManager().getBinding(cshaderPtr->_template->getLightFalloff()); } } // Return the texture return _texLightFalloff; }
/* Parses through the shader file and processes the tokens delivered by * DefTokeniser. */ void ShaderFileLoader::parseShaderFile(std::istream& inStr, const std::string& filename) { // Parse the file with a blocktokeniser, the actual block contents // will be parsed separately. parser::BasicDefBlockTokeniser<std::istream> tokeniser(inStr); while (tokeniser.hasMoreBlocks()) { // Get the next block parser::BlockTokeniser::Block block = tokeniser.nextBlock(); // Skip tables if (block.name.substr(0, 5) == "table") { std::string tableName = block.name.substr(6); if (tableName.empty()) { rError() << "[shaders] " << filename << ": Missing table name." << std::endl; continue; } TableDefinitionPtr table(new TableDefinition(tableName, block.contents)); if (!GetShaderSystem()->addTableDefinition(table)) { rError() << "[shaders] " << filename << ": table " << tableName << " already defined." << std::endl; } continue; } else if (block.name.substr(0, 5) == "skin ") { continue; // skip skin definition } else if (block.name.substr(0, 9) == "particle ") { continue; // skip particle definition } boost::algorithm::replace_all(block.name, "\\", "/"); // use forward slashes ShaderTemplatePtr shaderTemplate(new ShaderTemplate(block.name, block.contents)); // Construct the ShaderDefinition wrapper class ShaderDefinition def(shaderTemplate, filename); // Insert into the definitions map, if not already present if (!GetShaderLibrary().addDefinition(block.name, def)) { rError() << "[shaders] " << filename << ": shader " << block.name << " already defined." << std::endl; } } }
void CBaseShader::BindVertexTexture( VertexTextureSampler_t vtSampler, int nTextureVar, int nFrame /* = 0 */) { Assert( !IsSnapshotting() ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; if ( !pTextureVar ) return; GetShaderSystem()->BindVertexTexture( vtSampler, pTextureVar->GetTextureValue() ); }
//----------------------------------------------------------------------------- // Draws a snapshot //----------------------------------------------------------------------------- void CBaseShader::Draw( ) { if ( IsSnapshotting() ) { // Turn off transparency if we're asked to.... if (g_pConfig->bNoTransparency && ((s_ppParams[FLAGS]->GetIntValue() & MATERIAL_VAR_NO_DEBUG_OVERRIDE) == 0)) { s_pShaderShadow->EnableDepthWrites( true ); s_pShaderShadow->EnableBlending( false ); } GetShaderSystem()->TakeSnapshot(); } else { GetShaderSystem()->DrawSnapshot(); } }
ShaderAPITextureHandle_t CBaseShader::GetShaderAPITextureBindHandle( int nTextureVar, int nFrameVar, int nTextureChannel ) { Assert( !IsSnapshotting() ); Assert( nTextureVar != -1 ); Assert ( s_ppParams ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; return GetShaderSystem()->GetShaderAPITextureBindHandle( pTextureVar->GetTextureValue(), nFrame, nTextureChannel ); }
void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, int nTextureVar, int nFrameVar /* = -1 */ ) { Assert( !IsSnapshotting() ); Assert( nTextureVar != -1 ); Assert ( s_ppParams ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; if (pTextureVar) { int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; if ( sampler2 == -1 ) { GetShaderSystem()->BindTexture( sampler1, pTextureVar->GetTextureValue(), nFrame ); } else { GetShaderSystem()->BindTexture( sampler1, sampler2, pTextureVar->GetTextureValue(), nFrame ); } } }
//----------------------------------------------------------------------------- // Draws a snapshot //----------------------------------------------------------------------------- void CBaseShader::Draw( bool bMakeActualDrawCall ) { // You forgot to call PI_EndCommandBuffer Assert( !s_bBuildingInstanceCommandBuffer ); if ( IsSnapshotting() ) { // Turn off transparency if we're asked to.... if (g_pConfig->bNoTransparency && ((s_ppParams[FLAGS]->GetIntValue() & MATERIAL_VAR_NO_DEBUG_OVERRIDE) == 0)) { s_pShaderShadow->EnableDepthWrites( true ); s_pShaderShadow->EnableBlending( false ); } GetShaderSystem()->TakeSnapshot(); // Automagically add skinning + vertex lighting if ( !s_pInstanceDataPtr[s_nPassCount] ) { bool bIsSkinning = CShader_IsFlag2Set( s_ppParams, MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); bool bIsVertexLit = CShader_IsFlag2Set( s_ppParams, MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); if ( bIsSkinning || bIsVertexLit ) { PI_BeginCommandBuffer(); // NOTE: EndCommandBuffer will insert the appropriate commands PI_EndCommandBuffer(); } } } else { GetShaderSystem()->DrawSnapshot( s_pInstanceDataPtr[s_nPassCount] ? s_pInstanceDataPtr[s_nPassCount]->m_pCommandBuffer : NULL, bMakeActualDrawCall ); } ++s_nPassCount; }
//----------------------------------------------------------------------------- // Binds a texture //----------------------------------------------------------------------------- void CBaseShader::BindTexture( TextureStage_t stage, int nTextureVar, int nFrameVar ) { Assert( !IsSnapshotting() ); Assert( nTextureVar != -1 ); Assert ( s_ppParams ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; if (pTextureVar) { int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; GetShaderSystem()->BindTexture( stage, pTextureVar->GetTextureValue(), nFrame ); } }
ShaderAPITextureHandle_t CBaseShader::GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel ) { return GetShaderSystem()->GetShaderAPITextureBindHandle( pTexture, nFrame, nTextureChannel ); }
//----------------------------------------------------------------------------- // Are we using graphics? //----------------------------------------------------------------------------- bool CBaseShader::CanUseEditorMaterials() const { return GetShaderSystem()->CanUseEditorMaterials(); }
void CBaseShader::BindTexture( TextureStage_t stage, ITexture *pTexture, int nFrame ) { Assert( !IsSnapshotting() ); GetShaderSystem()->BindTexture( stage, pTexture, nFrame ); }
shaders::ShaderLibrary& GetShaderLibrary() { return GetShaderSystem()->getLibrary(); }
//----------------------------------------------------------------------------- // Are we using graphics? //----------------------------------------------------------------------------- bool CBaseShader::IsUsingGraphics() { return GetShaderSystem()->IsUsingGraphics(); }
shaders::GLTextureManager& GetTextureManager() { return GetShaderSystem()->getTextureManager(); }
void CShader::SetInUse(bool bInUse) { m_bInUse = bInUse; GetShaderSystem()->activeShadersChangedNotify(); }