Ejemplo n.º 1
0
 void Effect::AddVariable(ID3DX11EffectVariable* var, const D3DX11_EFFECT_VARIABLE_DESC* varDesc, const D3DX11_EFFECT_TYPE_DESC* typeDesc) {
     _ASSERT(var && varDesc && typeDesc);
     switch (typeDesc->Class) {
         case D3D_SVC_SCALAR : {
             ID3DX11EffectScalarVariable* scalarVar = var->AsScalar();
             _ASSERT(scalarVar->IsValid());
             scalarVars[varDesc->Name] = scalarVar;
             break;
         }
         case D3D_SVC_VECTOR : {
             ID3DX11EffectVectorVariable* vectorVar = var->AsVector();
             _ASSERT(vectorVar->IsValid());
             vectorVars[varDesc->Name] = vectorVar;
             break;
         }
         case D3D_SVC_MATRIX_COLUMNS:
         case D3D_SVC_MATRIX_ROWS: {
             ID3DX11EffectMatrixVariable* matrixVar = var->AsMatrix();
             _ASSERT(matrixVar->IsValid());
             matrixVars[varDesc->Name] = matrixVar;
             break;
         }
         case D3D_SVC_STRUCT: structVars[varDesc->Name] = var;
             break;
         case D3D_SVC_OBJECT: {
             ID3DX11EffectShaderResourceVariable* resourceVar = var->AsShaderResource();
             if (resourceVar->IsValid()) {
                 resourceVars[varDesc->Name] = resourceVar;
             }
             break;
         }
         default:
             _ASSERT(false);
     }
 }
Ejemplo n.º 2
0
bool Prism::Surface::SetTexture(const std::string& aResourceName, Texture* aTexture)
{
	DL_ASSERT_EXP(aTexture != nullptr
		, CU::Concatenate("Shader resource ( %s ) tried to use invalid texture", aResourceName.c_str()));

	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();
	if (shaderVar->IsValid() == false)
	{
		//DL_MESSAGE_BOX("Failed to get ShaderResource", "Surface Error", MB_ICONWARNING);
		RESOURCE_LOG("Failed to get ShaderResource");
		return false;
	}

	if (aResourceName == "EmissiveTexture")
	{
		myEmissive = true;
	}

	myTextures.Add(aTexture);
	myShaderResources.Add(aTexture->GetShaderView());
	myShaderResourceViews.Add(shaderVar);
	myShaderResourceNames.Add(aResourceName);

	return true;
}
Ejemplo n.º 3
0
bool Prism::Surface::SetTexture(const std::string& aResourceName, const std::string& aFileName, bool aUseSRGB)
{
	aUseSRGB;

	DL_ASSERT_EXP(aFileName != ""
		, CU::Concatenate("Shader resource ( %s ) tried to use invalid filePath", aResourceName.c_str()));

	Texture* tex = Engine::GetInstance()->GetTextureContainer()->GetTexture(aFileName);
	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();

	if (shaderVar->IsValid() == false)
	{
		std::string errorMsg = "Failed to get ShaderResource: " + aResourceName;
		//DL_MESSAGE_BOX(errorMsg.c_str(), "Surface Error", MB_ICONWARNING);
		RESOURCE_LOG(errorMsg.c_str());
		return false;
	}

	if (aResourceName == "EmissiveTexture")
	{
		myEmissive = true;
	}

	myTextures.Add(tex);
	myShaderResources.Add(tex->GetShaderView());
	myShaderResourceViews.Add(shaderVar);
	myFilePaths.Add(aFileName);
	myShaderResourceNames.Add(aResourceName);

	return true;
}
Ejemplo n.º 4
0
bool CD3DEffect::SetResources(LPCSTR handle, ID3D11ShaderResourceView** ppSRViews, size_t count)
{
  if (m_effect)
  {
    ID3DX11EffectShaderResourceVariable* var = m_effect->GetVariableByName(handle)->AsShaderResource();
    if (var->IsValid())
      return SUCCEEDED(var->SetResourceArray(ppSRViews, 0, count));
  }
  return false;
}
Ejemplo n.º 5
0
bool CD3DEffect::SetTexture(LPCSTR handle, CD3DTexture &texture)
{
  if (m_effect)
  {
    ID3DX11EffectShaderResourceVariable* var = m_effect->GetVariableByName(handle)->AsShaderResource();
    if (var->IsValid())
      return SUCCEEDED(var->SetResource(texture.GetShaderResource()));
  }
  return false;
}
Ejemplo n.º 6
0
void DX11Shader::setTextureArray(const char* strName, Texture texture, UINT uTexture)
{
    ID3DX11EffectShaderResourceVariable*  pTextureVariable;

    pTextureVariable = m_pEffect->pEffect->GetVariableByName(strName)->AsShaderResource();
    if (pTextureVariable->IsValid()) {
        pTextureVariable->SetResourceArray(&texture.getData()->m_pShaderResource, uTexture, 1);
    }
    else {
        EventManager::Instance().postMessage("Unknown shaderresource variable: %s in shader: %s", strName, m_pEffect->strName);
    }
}
Ejemplo n.º 7
0
bool Prism::Surface::SetTexture(const std::string& aResourceName, ID3D11ShaderResourceView* aResource)
{
	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();
	if (shaderVar->IsValid() == false)
	{
		//DL_MESSAGE_BOX("Failed to get ShaderResource", "Surface Error", MB_ICONWARNING);
		RESOURCE_LOG("Failed to get ShaderResource");
		return false;
	}

	myShaderResources.Add(aResource);
	myShaderResourceViews.Add(shaderVar);
	myShaderResourceNames.Add(aResourceName);
	return true;
}
Ejemplo n.º 8
0
bool Surface::SetTexture(const std::string& aResourceName, const std::string& aFileName, const bool aUseSRGB)
{
	aUseSRGB;

	Texture* tex = Engine::GetInstance()->GetTextureContainer().GetTexture(aFileName);
	ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(aResourceName.c_str())->AsShaderResource();

	if (shaderVar->IsValid() == false)
	{
		DL_MESSAGE_BOX("Failed to get ShaderResource", "Surface Error", MB_ICONWARNING);
		return false;
	}

	myTextures.Add(tex);
	myShaderViews.Add(shaderVar);

	return true;
}
Ejemplo n.º 9
0
void EffectSystemD3D11::UpdateTexture2D(int effectID, const char *name, const char *path)
{
	ASSERT_EFFECT(effectID);
	std::string key(path);
	// 检查是否已创建
	if (mTexture2Ds.find(key) == mTexture2Ds.end())
	{
		CreateTexture2D(key);
	}
	// set resource
	ID3D11ShaderResourceView *resource = mTexture2Ds[key];
	ID3DX11EffectShaderResourceVariable *resourceVariable = mEffects[effectID]->GetVariableByName(name)->AsShaderResource();
	if (resourceVariable->IsValid())
	{
		resourceVariable->SetResource(resource);
	}
	else
	{
		LogSystem::GetInstance().Log("effect shader resource「%s」非法", name);
		return;
	}
}
Ejemplo n.º 10
0
void Prism::Surface::ReloadSurface()
{
	myTextures.RemoveAll();
	myShaderResourceViews.RemoveAll();
	myShaderResources.RemoveAll();

	for (int i = 0; i < myFilePaths.Size(); ++i)
	{
		Texture* tex = Engine::GetInstance()->GetTextureContainer()->GetTexture(myFilePaths[i]);
		ID3DX11EffectShaderResourceVariable* shaderVar = myEffect->GetEffect()->GetVariableByName(myShaderResourceNames[i].c_str())->AsShaderResource();

		if (shaderVar->IsValid() == false)
		{
			std::string errorMsg = "Failed to get ShaderResource: " + myShaderResourceNames[i];
			//DL_MESSAGE_BOX(errorMsg.c_str(), "Surface Error", MB_ICONWARNING);
			RESOURCE_LOG(errorMsg.c_str());
		}

		myTextures.Add(tex);
		myShaderResources.Add(tex->GetShaderView());
		myShaderResourceViews.Add(shaderVar);
	}
}