2013-11-21 13:50:43 +01:00
|
|
|
#include "Resources.h"
|
|
|
|
#include "..\OysterGraphics\Definitions\GraphicalDefinition.h"
|
|
|
|
|
2013-11-22 14:09:47 +01:00
|
|
|
// /Bin/Executable/Tester ->
|
|
|
|
// /Code/OysterGraphics/Shader/HLSL
|
2013-12-04 09:36:43 +01:00
|
|
|
const std::wstring PathFromExeToCso = L"..\\Content\\Shaders\\";
|
|
|
|
const std::wstring PathFromExeToHlsl = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\";
|
2013-11-21 13:50:43 +01:00
|
|
|
const std::wstring VertexTransformDebug = L"TransformDebugVertex";
|
|
|
|
const std::wstring VertexDebug = L"DebugVertex";
|
|
|
|
const std::wstring PixelRed = L"DebugPixel";
|
2013-11-27 15:26:29 +01:00
|
|
|
const std::wstring PixelTexture = L"Texture";
|
2013-11-21 13:50:43 +01:00
|
|
|
|
|
|
|
typedef Oyster::Graphics::Core::ShaderManager::ShaderType ShaderType;
|
|
|
|
typedef Oyster::Graphics::Core::ShaderManager::Get GetShader;
|
|
|
|
typedef Oyster::Graphics::Core::ShaderManager Shader;
|
2013-11-26 09:09:35 +01:00
|
|
|
typedef Oyster::Graphics::Core::Buffer Buffer;
|
2013-11-21 13:50:43 +01:00
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Graphics
|
|
|
|
{
|
|
|
|
namespace Render
|
|
|
|
{
|
2013-11-27 15:26:29 +01:00
|
|
|
Shader::ShaderEffect Resources::obj;// = Shader::ShaderEffect();;
|
2013-11-21 18:31:16 +01:00
|
|
|
Buffer Resources::ModelData = Buffer();
|
|
|
|
Buffer Resources::VPData = Buffer();
|
|
|
|
|
2013-11-21 13:50:43 +01:00
|
|
|
Core::Init::State Resources::Init()
|
|
|
|
{
|
|
|
|
|
|
|
|
#pragma region LoadShaders
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|
|
|
/** Load Vertex Shader for d3dcompile*/
|
2013-11-29 10:25:27 +01:00
|
|
|
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugCameraVertex.hlsl",ShaderType::Vertex, VertexTransformDebug);
|
|
|
|
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugVertex.hlsl",ShaderType::Vertex, VertexDebug);
|
2013-11-21 13:50:43 +01:00
|
|
|
|
|
|
|
/** Load Pixel Shader for d3dcompile */
|
2013-11-29 10:25:27 +01:00
|
|
|
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" + L"DebugPixel.hlsl", ShaderType::Pixel, PixelRed);
|
|
|
|
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" + L"TextureDebug.hlsl", ShaderType::Pixel, PixelTexture);
|
2013-11-27 15:26:29 +01:00
|
|
|
|
2013-11-21 13:50:43 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
/** Load Vertex Shader with Precompiled */
|
2013-12-04 09:36:43 +01:00
|
|
|
Core::ShaderManager::Init(PathFromExeToCso + L"DebugCameraVertex.cso",ShaderType::Vertex, VertexTransformDebug);
|
|
|
|
Core::ShaderManager::Init(PathFromExeToCso + L"DebugVertex.cso",ShaderType::Vertex, VertexDebug);
|
|
|
|
|
|
|
|
/** Load Pixel Shader with Precompiled */
|
|
|
|
Core::ShaderManager::Init(PathFromExeToCso + L"DebugPixel.cso",ShaderType::Pixel, PixelRed);
|
|
|
|
Core::ShaderManager::Init(PathFromExeToCso + L"TextureDebug.cso",ShaderType::Pixel, PixelTexture);
|
2013-11-21 13:50:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region CreateBuffers
|
|
|
|
Buffer::BUFFER_INIT_DESC desc;
|
|
|
|
desc.ElementSize = sizeof(Oyster::Math::Matrix);
|
|
|
|
desc.NumElements = 1;
|
|
|
|
desc.InitData = NULL;
|
|
|
|
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
|
|
|
|
desc.Usage = Buffer::BUFFER_USAGE::BUFFER_CPU_WRITE_DISCARD;
|
|
|
|
|
|
|
|
ModelData.Init(desc);
|
|
|
|
|
|
|
|
desc.NumElements = 2;
|
|
|
|
VPData.Init(desc);
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region Setup Render States
|
|
|
|
/** @todo Create DX States */
|
2013-11-21 18:31:16 +01:00
|
|
|
|
|
|
|
D3D11_RASTERIZER_DESC rdesc;
|
2013-11-28 14:34:52 +01:00
|
|
|
rdesc.CullMode = D3D11_CULL_BACK;
|
2013-11-21 18:31:16 +01:00
|
|
|
rdesc.FillMode = D3D11_FILL_SOLID;
|
2013-11-28 14:34:52 +01:00
|
|
|
rdesc.FrontCounterClockwise = true;
|
2013-11-21 18:31:16 +01:00
|
|
|
rdesc.DepthBias = 0;
|
|
|
|
rdesc.DepthBiasClamp = 0;
|
2013-11-21 23:54:12 +01:00
|
|
|
rdesc.DepthClipEnable = true;
|
2013-11-21 18:31:16 +01:00
|
|
|
rdesc.SlopeScaledDepthBias = 0;
|
2013-11-21 23:54:12 +01:00
|
|
|
rdesc.ScissorEnable = false;
|
2013-11-21 18:31:16 +01:00
|
|
|
rdesc.MultisampleEnable = false;
|
|
|
|
rdesc.AntialiasedLineEnable = false;
|
|
|
|
|
|
|
|
ID3D11RasterizerState* rs = NULL;
|
|
|
|
Oyster::Graphics::Core::device->CreateRasterizerState(&rdesc,&rs);
|
2013-11-27 15:26:29 +01:00
|
|
|
|
|
|
|
D3D11_SAMPLER_DESC sdesc;
|
|
|
|
sdesc.Filter = D3D11_FILTER_ANISOTROPIC;
|
|
|
|
/// @todo parata med fredrik om wraping
|
2013-11-28 14:34:52 +01:00
|
|
|
sdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
|
|
sdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
|
|
sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
2013-11-27 15:26:29 +01:00
|
|
|
sdesc.MipLODBias = 0;
|
|
|
|
sdesc.MaxAnisotropy =4;
|
2013-11-28 14:34:52 +01:00
|
|
|
sdesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
|
|
|
|
*sdesc.BorderColor = *Oyster::Math::Float4(1,1,1,1).element;
|
2013-11-27 15:26:29 +01:00
|
|
|
sdesc.MinLOD = 0;
|
|
|
|
sdesc.MaxLOD = D3D11_FLOAT32_MAX;
|
|
|
|
|
|
|
|
ID3D11SamplerState** ss = new ID3D11SamplerState*[1];
|
|
|
|
Oyster::Graphics::Core::device->CreateSamplerState(&sdesc,ss);
|
|
|
|
|
2013-11-28 14:34:52 +01:00
|
|
|
D3D11_DEPTH_STENCIL_DESC ddesc;
|
|
|
|
ddesc.DepthEnable = true;
|
|
|
|
ddesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
|
|
|
ddesc.DepthFunc = D3D11_COMPARISON_LESS;
|
|
|
|
|
|
|
|
ddesc.StencilEnable = true;
|
|
|
|
ddesc.StencilReadMask = 0xFF;
|
|
|
|
ddesc.StencilWriteMask = 0xFF;
|
|
|
|
|
|
|
|
ddesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
|
ddesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
|
|
|
|
ddesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
|
|
ddesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
|
|
|
|
|
ddesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
|
|
ddesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
|
|
|
|
ddesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
|
|
ddesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
|
|
|
|
|
|
ID3D11DepthStencilState* dsState;
|
|
|
|
Core::device->CreateDepthStencilState(&ddesc,&dsState);
|
|
|
|
|
2013-11-21 13:50:43 +01:00
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region Setup Views
|
|
|
|
/** @todo Create Views */
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region Create Shader Effects
|
|
|
|
/** @todo Create ShaderEffects */
|
2013-11-28 14:34:52 +01:00
|
|
|
obj.Shaders.Pixel = GetShader::Pixel(PixelTexture);
|
|
|
|
obj.Shaders.Vertex = GetShader::Vertex(VertexTransformDebug);
|
2013-11-21 13:50:43 +01:00
|
|
|
|
|
|
|
D3D11_INPUT_ELEMENT_DESC indesc[] =
|
|
|
|
{
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
2013-11-21 18:31:16 +01:00
|
|
|
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }
|
2013-11-21 13:50:43 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Shader::CreateInputLayout(indesc,3,GetShader::Vertex(VertexTransformDebug),obj.IAStage.Layout);
|
|
|
|
obj.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
|
|
|
obj.CBuffers.Vertex.push_back(&VPData);
|
2013-11-21 18:31:16 +01:00
|
|
|
obj.RenderStates.Rasterizer = rs;
|
2013-11-27 15:26:29 +01:00
|
|
|
obj.RenderStates.SampleCount = 1;
|
|
|
|
obj.RenderStates.SampleState = ss;
|
2013-11-28 14:34:52 +01:00
|
|
|
obj.RenderStates.DepthStencil = dsState;
|
2013-11-21 13:50:43 +01:00
|
|
|
|
2013-11-26 13:44:58 +01:00
|
|
|
ModelData.Apply(1);
|
2013-11-21 13:50:43 +01:00
|
|
|
#pragma endregion
|
|
|
|
return Core::Init::Sucsess;
|
|
|
|
}
|
2013-11-29 10:25:27 +01:00
|
|
|
|
|
|
|
void Resources::Clean()
|
|
|
|
{
|
|
|
|
Resources::ModelData.~Buffer();
|
|
|
|
Resources::VPData.~Buffer();
|
|
|
|
for(int i = 0; i < obj.CBuffers.Vertex.size(); ++i)
|
|
|
|
{
|
|
|
|
//SAFE_RELEASE(obj.CBuffers.Vertex[i]);
|
|
|
|
}
|
|
|
|
for(int i = 0; i < obj.CBuffers.Pixel.size(); ++i)
|
|
|
|
{
|
|
|
|
SAFE_DELETE(obj.CBuffers.Pixel[i]);
|
|
|
|
}
|
|
|
|
for(int i = 0; i < obj.CBuffers.Geometry.size(); ++i)
|
|
|
|
{
|
|
|
|
SAFE_DELETE(obj.CBuffers.Geometry[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SAFE_RELEASE(obj.IAStage.Layout);
|
|
|
|
|
|
|
|
SAFE_RELEASE(obj.RenderStates.BlendState);
|
|
|
|
|
|
|
|
SAFE_RELEASE(obj.RenderStates.DepthStencil);
|
|
|
|
|
|
|
|
SAFE_RELEASE(obj.RenderStates.Rasterizer);
|
|
|
|
|
|
|
|
for(int i = 0; i < obj.RenderStates.SampleCount; ++i)
|
|
|
|
{
|
|
|
|
SAFE_RELEASE(obj.RenderStates.SampleState[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SAFE_DELETE_ARRAY(obj.RenderStates.SampleState);
|
|
|
|
}
|
2013-11-21 13:50:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|