Engine Sructured

This commit is contained in:
lanariel 2013-11-21 13:50:43 +01:00
parent a94429fd9d
commit 7b31377be8
8 changed files with 165 additions and 99 deletions

View File

@ -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;
};
}
}
}

View File

@ -1,4 +1,5 @@
#include "Render.h" #include "Render.h"
#include "../Resources/Resources.h"
namespace Oyster namespace Oyster
{ {
@ -8,24 +9,41 @@ namespace Oyster
{ {
namespace Rendering 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) void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4 Projection)
{ {
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,1)); 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) 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() void Basic::EndFrame()
{ {
Core::swapChain->Present(0,0);
} }
} }
} }

View File

@ -15,13 +15,6 @@ namespace Oyster
class Basic class Basic
{ {
public: public:
class Resources
{
static Core::ShaderManager::ShaderEffect se;
static void Init();
};
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4 Projection); static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4 Projection);
static void RenderScene(Model* models, int count); static void RenderScene(Model* models, int count);

View File

@ -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;
}
}
}
}

View File

@ -0,0 +1,28 @@
#pragma once
#ifndef Reources_h
#define Reources_h
#include <map>
#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

View File

@ -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;
}
}
}
}

View File

@ -1,26 +0,0 @@
#pragma once
#ifndef Reources_h
#define Reources_h
#include <map>
#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

View File

@ -9,10 +9,16 @@ cbuffer PerModel : register(b1)
matrix World; 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 VP = mul(View, Projection);
matrix WVP = mul(World, VP); matrix WVP = mul(World, VP);
return mul(WVP, pos); return mul(WVP, float4(input.pos,1));
} }