14 const std::string& fileName,
17 ERROR(
"ShaderProgram",
"init",
"Device is null.");
20 if (fileName.empty()) {
21 ERROR(
"ShaderProgram",
"init",
"File name is empty.");
32 ERROR(
"ShaderProgram",
"init",
"Failed to create vertex shader.");
39 ERROR(
"ShaderProgram",
"init",
"Failed to create input layout.");
46 ERROR(
"ShaderProgram",
"init",
"Failed to create pixel shader.");
56 ERROR(
"ShaderProgram",
"CreateInputLayout",
"Vertex shader data is null.");
60 ERROR(
"ShaderProgram",
"CreateInputLayout",
"Device is null.");
68 auto& layout = layoutBuilder.
Get();
74 ERROR(
"ShaderProgram",
"CreateInputLayout",
"Failed to create input layout.");
84 ERROR(
"ShaderProgram",
"CreateShader",
"Device is null.");
88 ERROR(
"ShaderProgram",
"CreateShader",
"Shader file name is empty.");
93 ID3DBlob* shaderData =
nullptr;
105 ERROR(
"ShaderProgram",
"CreateShader",
113 shaderData->GetBufferSize(),
119 shaderData->GetBufferSize(),
125 ERROR(
"ShaderProgram",
"CreateShader",
126 "Failed to create shader object from compiled data.");
127 shaderData->Release();
147 const std::string& fileName) {
149 ERROR(
"ShaderProgram",
"init",
"Device is null.");
152 if (fileName.empty()) {
153 ERROR(
"ShaderProgram",
"init",
"File name is empty.");
161 ERROR(
"ShaderProgram",
"CreateShader",
172 LPCSTR szShaderModel,
173 ID3DBlob** ppBlobOut) {
176 DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
177#if defined( DEBUG ) || defined( _DEBUG )
182 dwShaderFlags |= D3DCOMPILE_DEBUG;
184 ID3DBlob* pErrorBlob;
185 hr = D3DX11CompileFromFile(szFileName,
199 ERROR(
"ShaderProgram",
"CompileShaderFromFile",
200 "Failed to compile shader from file: %s. Error: %s",
201 szFileName,
static_cast<const char*
>(pErrorBlob->GetBufferPointer()));
203 pErrorBlob->Release();
206 ERROR(
"ShaderProgram",
"CompileShaderFromFile",
207 "Failed to compile shader from file: %s. No error message available.",
221 ERROR(
"ShaderProgram",
"render",
"Shaders or InputLayout not initialized");
233 ERROR(
"RenderTargetView",
"render",
"DeviceContext is nullptr.");
Declara la API de DeviceContext dentro del subsistema Core.
Declara la API de Device dentro del subsistema Core.
Declara la API de LayoutBuilder dentro del subsistema Utilities.
#define ERROR(classObj, method, errorMSG)
Declara la API de ShaderProgram dentro del subsistema Core.
ID3D11DeviceContext * m_deviceContext
Puntero al contexto inmediato de Direct3D 11.
Encapsula un ID3D11Device y facilita la creación de recursos gráficos en Direct3D 11.
ID3D11Device * m_device
Puntero al dispositivo Direct3D 11.
HRESULT CreateVertexShader(const void *pShaderBytecode, unsigned int BytecodeLength, ID3D11ClassLinkage *pClassLinkage, ID3D11VertexShader **ppVertexShader)
Crea un Vertex Shader.
HRESULT CreatePixelShader(const void *pShaderBytecode, unsigned int BytecodeLength, ID3D11ClassLinkage *pClassLinkage, ID3D11PixelShader **ppPixelShader)
Crea un Pixel Shader.
const std::vector< D3D11_INPUT_ELEMENT_DESC > & Get() const
ID3D11VertexShader * m_VertexShader
Vertex Shader compilado y creado en GPU.
HRESULT CreateShader(Device &device, ShaderType type)
Crea un shader (Vertex o Pixel) a partir del archivo establecido en m_shaderFileName.
ID3D11PixelShader * m_PixelShader
Pixel Shader compilado y creado en GPU.
InputLayout m_inputLayout
Input Layout asociado al Vertex Shader.
ID3DBlob * m_vertexShaderData
Bytecode compilado del Vertex Shader.
void render(DeviceContext &deviceContext)
Aplica el Vertex Shader, Pixel Shader e Input Layout al pipeline.
ID3DBlob * m_pixelShaderData
Bytecode compilado del Pixel Shader.
HRESULT CompileShaderFromFile(char *szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob **ppBlobOut)
Compila un shader desde archivo.
HRESULT init(Device &device, const std::string &fileName, LayoutBuilder layoutBuilder)
Inicializa el programa de shaders desde un archivo HLSL.
std::string m_shaderFileName
Nombre del archivo HLSL asociado a este programa de shaders.
void destroy()
Libera todos los recursos asociados (shaders, blobs e input layout).
HRESULT CreateInputLayout(Device &device, LayoutBuilder)
Crea un Input Layout asociado al Vertex Shader.