From 7b31377be8ae1f81a6441f76558f643214d1735d Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 21 Nov 2013 13:50:43 +0100 Subject: [PATCH] Engine Sructured --- .../Definitions/GraphicalDefinition.h | 18 ++++ .../Render/Rendering/BasicRender.cpp | 34 ++++++-- Code/OysterGraphics/Render/Rendering/Render.h | 7 -- .../Render/Resources/Resources.cpp | 85 +++++++++++++++++++ .../Render/Resources/Resources.h | 28 ++++++ Code/OysterGraphics/Resources/Resources.cpp | 56 ------------ Code/OysterGraphics/Resources/Resources.h | 26 ------ .../HLSL/SimpleDebug/DebugCameraVertex.hlsl | 10 ++- 8 files changed, 165 insertions(+), 99 deletions(-) create mode 100644 Code/OysterGraphics/Definitions/GraphicalDefinition.h create mode 100644 Code/OysterGraphics/Render/Resources/Resources.cpp create mode 100644 Code/OysterGraphics/Render/Resources/Resources.h delete mode 100644 Code/OysterGraphics/Resources/Resources.cpp delete mode 100644 Code/OysterGraphics/Resources/Resources.h diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h new file mode 100644 index 00000000..22942e5e --- /dev/null +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -0,0 +1,18 @@ +#include "..\OysterGraphics\Core\CoreIncludes.h" +#include "OysterMath.h" + +namespace Oyster +{ + namespace Graphics + { + namespace Definitions + { + struct ObjVertex + { + Oyster::Math::Float3 pos; + Oyster::Math::Float2 uv; + Oyster::Math::Float3 normal; + }; + } + } +} \ No newline at end of file diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index 272a2a7c..ed64d08e 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -1,4 +1,5 @@ #include "Render.h" +#include "../Resources/Resources.h" namespace Oyster { @@ -8,24 +9,41 @@ namespace Oyster { namespace Rendering { - Core::ShaderManager::ShaderEffect Basic::Resources::se = Core::ShaderManager::ShaderEffect(); - - void Basic::Resources::Init() - { - se.Shaders.Vertex = Core::ShaderManager::Get::Vertex(L"DebugCamera"); - se.Shaders.Pixel = Core::ShaderManager::Get::Pixel(L"Debug"); - - } void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4 Projection) { Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,1)); + Core::ShaderManager::SetShaderEffect(Graphics::Render::Resources::obj); + Preparations::Basic::BindBackBufferRTV(); } void Basic::RenderScene(Model* models, int count) { + for(int i = 0; i < count; ++i) + { + if(models[i].Visible) + { + void* data = Resources::ModelData.Map(); + memcpy(data,&(models[i].World),64); + Resources::ModelData.Unmap(); + + //Set Materials :: NONE + + models[i].info->Vertices.Apply(); + if(models[i].info->Indexed) + { + models[i].info->Indecies.Apply(); + Oyster::Graphics::Core::deviceContext->DrawIndexed(models[i].info->VertexCount,0,0); + } + else + { + Oyster::Graphics::Core::deviceContext->Draw(models[i].info->VertexCount,0); + } + } + } } void Basic::EndFrame() { + Core::swapChain->Present(0,0); } } } diff --git a/Code/OysterGraphics/Render/Rendering/Render.h b/Code/OysterGraphics/Render/Rendering/Render.h index 3ba623e3..028bcc78 100644 --- a/Code/OysterGraphics/Render/Rendering/Render.h +++ b/Code/OysterGraphics/Render/Rendering/Render.h @@ -15,13 +15,6 @@ namespace Oyster class Basic { public: - class Resources - { - static Core::ShaderManager::ShaderEffect se; - - static void Init(); - }; - static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4 Projection); static void RenderScene(Model* models, int count); diff --git a/Code/OysterGraphics/Render/Resources/Resources.cpp b/Code/OysterGraphics/Render/Resources/Resources.cpp new file mode 100644 index 00000000..dc0a9656 --- /dev/null +++ b/Code/OysterGraphics/Render/Resources/Resources.cpp @@ -0,0 +1,85 @@ +#include "Resources.h" +#include "..\OysterGraphics\Definitions\GraphicalDefinition.h" + +const std::wstring PathFromExeToHlsl = L""; +const std::wstring VertexTransformDebug = L"TransformDebugVertex"; +const std::wstring VertexDebug = L"DebugVertex"; +const std::wstring PixelRed = L"DebugPixel"; + +typedef Oyster::Graphics::Core::ShaderManager::ShaderType ShaderType; +typedef Oyster::Graphics::Core::ShaderManager::Get GetShader; +typedef Oyster::Graphics::Core::ShaderManager Shader; + +namespace Oyster +{ + namespace Graphics + { + namespace Render + { + Core::Init::State Resources::Init() + { + +#pragma region LoadShaders + +#ifdef _DEBUG + + /** Load Vertex Shader for d3dcompile*/ + Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugCameraVertex",ShaderType::Vertex, VertexTransformDebug, false); + Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugVertex",ShaderType::Vertex, VertexDebug, false); + + /** Load Pixel Shader for d3dcompile */ + Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" + L"DebugPixel", ShaderType::Pixel, PixelRed, false); + +#else + /** Load Vertex Shader with Precompiled */ +#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 */ +#pragma endregion + +#pragma region Setup Views + /** @todo Create Views */ +#pragma endregion + +#pragma region Create Shader Effects + /** @todo Create ShaderEffects */ + obj.Shaders.Pixel = GetShader::Pixel(PixelRed); + obj.Shaders.Vertex = GetShader::Vertex(VertexTransformDebug); + + 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 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + + }; + + Shader::CreateInputLayout(indesc,3,GetShader::Vertex(VertexTransformDebug),obj.IAStage.Layout); + obj.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + obj.CBuffers.Vertex.push_back(&VPData); + +#pragma endregion + + return Core::Init::Sucsess; + } + } + } +} \ No newline at end of file diff --git a/Code/OysterGraphics/Render/Resources/Resources.h b/Code/OysterGraphics/Render/Resources/Resources.h new file mode 100644 index 00000000..dc10c8e8 --- /dev/null +++ b/Code/OysterGraphics/Render/Resources/Resources.h @@ -0,0 +1,28 @@ +#pragma once + +#ifndef Reources_h +#define Reources_h + +#include +#include "../OysterGraphics/Core/Core.h" + +namespace Oyster +{ + namespace Graphics + { + namespace Render + { + class Resources + { + public: + static Core::ShaderManager::ShaderEffect obj; + static Buffer ModelData; + static Buffer VPData; + + static Core::Init::State Init(); + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/OysterGraphics/Resources/Resources.cpp b/Code/OysterGraphics/Resources/Resources.cpp deleted file mode 100644 index 606191f2..00000000 --- a/Code/OysterGraphics/Resources/Resources.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "Resources.h" - -const std::wstring PathFromExeToHlsl = L""; -const std::wstring VertexTransformDebug = L"TransformDebugVertex"; -const std::wstring VertexDebug = L"DebugVertex"; -const std::wstring PixelRed = L"DebugPixel"; - -typedef Oyster::Graphics::Core::ShaderManager::ShaderType Shader; - -namespace Oyster -{ - namespace Graphics - { - namespace Render - { - Core::Init::State Resources::Init() - { - -#pragma region LoadShaders - -#ifdef _DEBUG - - /** Load Vertex Shader for d3dcompile*/ - Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugCameraVertex",Shader::Vertex, VertexTransformDebug, false); - Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugVertex",Shader::Vertex, VertexDebug, false); - - /** Load Pixel Shader for d3dcompile */ - Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" + L"DebugPixel", Shader::Pixel, PixelRed, false); - -#else - /** Load Vertex Shader with Precompiled */ -#endif - -#pragma endregion - -#pragma region CreateBuffers - /** @todo Create Buffers */ -#pragma endregion - -#pragma region Setup Render States - /** @todo Create DX States */ -#pragma endregion - -#pragma region Setup Views - /** @todo Create Views */ -#pragma endregion - -#pragma region Create Shader Effects - /** @todo Create ShaderEffects */ -#pragma endregion - - return Core::Init::Sucsess; - } - } - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/Resources/Resources.h b/Code/OysterGraphics/Resources/Resources.h deleted file mode 100644 index 75653480..00000000 --- a/Code/OysterGraphics/Resources/Resources.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#ifndef Reources_h -#define Reources_h - -#include -#include "..\Core\Core.h" - -namespace Oyster -{ - namespace Graphics - { - namespace Render - { - class Resources - { - const Core::ShaderManager::ShaderEffect basic; - const Buffer ModelData; - - Core::Init::State Init(); - }; - } - } -} - -#endif \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl index fa3b224f..d71aa352 100644 --- a/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/SimpleDebug/DebugCameraVertex.hlsl @@ -9,10 +9,16 @@ cbuffer PerModel : register(b1) matrix World; } +struct VertexIn +{ + float3 pos : POSITION; + float2 UV : TEXCOORD; + float3 normal : NORMAL; +}; -float4 main( float4 pos : POSITION ) : SV_POSITION +float4 main( VertexIn input ) : SV_POSITION { matrix VP = mul(View, Projection); matrix WVP = mul(World, VP); - return mul(WVP, pos); + return mul(WVP, float4(input.pos,1)); } \ No newline at end of file