port from perforce
This commit is contained in:
61
aiwaz/Aiwaz/Resources/Shader/InternalShader.cpp
Normal file
61
aiwaz/Aiwaz/Resources/Shader/InternalShader.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "stdafx.h"
|
||||
#include "InternalShader.h"
|
||||
#include "IResourceFactory.h"
|
||||
|
||||
|
||||
InternalShader::InternalShader(const IEngine& argEngine)
|
||||
: m_Engine(argEngine)
|
||||
, m_Effect(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InternalShader::~InternalShader()
|
||||
{
|
||||
m_Engine.get_ResourceFactory().DeleteInternalShader(*const_cast<InternalShader*>(this), true);
|
||||
}
|
||||
|
||||
|
||||
void InternalShader::LoadFromFile(const string16& argFileName)
|
||||
{
|
||||
if (m_Effect != NULL)
|
||||
this->Uninitialize();
|
||||
|
||||
HRESULT result = E_FAIL;
|
||||
|
||||
IFile* shaderFile = m_Engine.get_FileSystem().Open(argFileName);
|
||||
if (shaderFile == NULL)
|
||||
throw L"Unable to open shader file.";
|
||||
|
||||
ID3D10Blob* error = NULL;
|
||||
result = ::D3DX10CreateEffectFromMemory(shaderFile->get_Buffer(), shaderFile->get_BufferLength(), std::to_string8(argFileName).c_str(), NULL, NULL, "fx_4_0",
|
||||
#ifdef _DEBUG
|
||||
D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_DEBUG,
|
||||
#else
|
||||
D3D10_SHADER_ENABLE_STRICTNESS,
|
||||
#endif
|
||||
0, &m_Engine.get_DX10Device(), NULL, NULL, &m_Effect, &error, NULL);
|
||||
|
||||
if (result != S_OK)
|
||||
std::cout << std::red << "Unable to load shader file from memory. " << std::white << std::endl;
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
string8 errorText = static_cast<char*>(error->GetBufferPointer());
|
||||
std::cout << std::red << errorText << std::white << std::endl;
|
||||
::OutputDebugString(errorText.c_str());
|
||||
throw errorText;
|
||||
}
|
||||
if (error != NULL)
|
||||
error->Release();
|
||||
|
||||
delete shaderFile;
|
||||
}
|
||||
|
||||
|
||||
void InternalShader::Uninitialize()
|
||||
{
|
||||
if (m_Effect != NULL)
|
||||
m_Effect->Release();
|
||||
m_Effect = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user