From c021187db92a19287ba5481396312086ffdb7584 Mon Sep 17 00:00:00 2001 From: lanariel Date: Sun, 10 Nov 2013 03:19:46 +0100 Subject: [PATCH] Fixed OysterGraphics to compile. New baseline for engine. --- OysterGraphics/Core/Buffer.cpp | 10 +- OysterGraphics/Core/Buffer.h | 5 +- OysterGraphics/Core/Core.cpp | 15 +- OysterGraphics/Core/Core.h | 85 +++++ OysterGraphics/Core/CoreIncludes.h | 23 +- OysterGraphics/Core/ShaderManager.cpp | 351 ++++++++++++++++++ OysterGraphics/Engine.cpp | 72 ++-- OysterGraphics/EngineIncludes.h | 12 +- OysterGraphics/OysterGraphics.vcxproj | 6 +- OysterGraphics/OysterGraphics.vcxproj.filters | 22 +- OysterGraphics/Render/Camera.h | 2 +- OysterGraphics/Render/TextBox.cpp | 6 +- OysterGraphics/Resourses/Manager.cpp | 66 ++-- .../Resourses/PipelineResources.cpp | 34 +- OysterGraphics/Resourses/PipelineResources.h | 10 +- 15 files changed, 562 insertions(+), 157 deletions(-) create mode 100644 OysterGraphics/Core/ShaderManager.cpp diff --git a/OysterGraphics/Core/Buffer.cpp b/OysterGraphics/Core/Buffer.cpp index 50759848..d071ff10 100644 --- a/OysterGraphics/Core/Buffer.cpp +++ b/OysterGraphics/Core/Buffer.cpp @@ -1,8 +1,9 @@ #include "Buffer.h" #include "Core.h" + using namespace Oyster; -Buffer::Buffer() +Oyster::Buffer::Buffer() { mBuffer = NULL; } @@ -118,6 +119,11 @@ HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc) bufferDesc.Usage = D3D11_USAGE_DYNAMIC; bufferDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE; } + else if(mUsage == BUFFER_USAGE_IMMUTABLE) + { + bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; + bufferDesc.CPUAccessFlags = 0; + } //Desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferDesc.MiscFlags = 0; @@ -191,7 +197,7 @@ void Buffer::Unmap() Oyster::Core::DeviceContext->Unmap( mBuffer, 0 ); } -Buffer::operator ID3D11Buffer *() +Oyster::Buffer::operator ID3D11Buffer *() { return this->mBuffer; } diff --git a/OysterGraphics/Core/Buffer.h b/OysterGraphics/Core/Buffer.h index 712c7ac4..3a887a19 100644 --- a/OysterGraphics/Core/Buffer.h +++ b/OysterGraphics/Core/Buffer.h @@ -2,7 +2,7 @@ #ifndef CoreBuffer #define CoreBuffer -#include "Core.h" +#include "CoreIncludes.h" namespace Oyster { @@ -28,7 +28,8 @@ namespace Oyster BUFFER_CPU_WRITE, BUFFER_CPU_WRITE_DISCARD, BUFFER_CPU_READ, - BUFFER_USAGE_COUNT + BUFFER_USAGE_COUNT, + BUFFER_USAGE_IMMUTABLE }; struct BUFFER_INIT_DESC diff --git a/OysterGraphics/Core/Core.cpp b/OysterGraphics/Core/Core.cpp index feb7a65c..189b2573 100644 --- a/OysterGraphics/Core/Core.cpp +++ b/OysterGraphics/Core/Core.cpp @@ -1,5 +1,4 @@ #include "Core.h" -#include "..\Window\Window.h" using namespace Oyster; using std::string; @@ -29,10 +28,10 @@ bool Core::Init(bool SingleThreaded, bool Reference,bool ForceDX11) if(Reference) driverType = D3D_DRIVER_TYPE_REFERENCE; - /*#if defined(DEBUG) || defined(_DEBUG) + #if defined(DEBUG) || defined(_DEBUG) Log << "DirectX running in debug mode.\n"; createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; - #endif*/ + #endif D3D_FEATURE_LEVEL featureLevelsToTry[] = @@ -103,8 +102,14 @@ bool Core::CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED; desc.BufferDesc.RefreshRate.Denominator=1; desc.BufferDesc.RefreshRate.Numerator=60; - desc.BufferDesc.Height = Window::Size.bottom; - desc.BufferDesc.Width = Window::Size.left; + + RECT rc; + GetClientRect( Window, &rc ); + int screenWidth = rc.right - rc.left; + int screenHeight = rc.bottom - rc.top; + + desc.BufferDesc.Height = screenHeight; + desc.BufferDesc.Width = screenWidth; //Check and Set multiSampling if(MSAA_Quality) diff --git a/OysterGraphics/Core/Core.h b/OysterGraphics/Core/Core.h index 7cca37fb..3926a943 100644 --- a/OysterGraphics/Core/Core.h +++ b/OysterGraphics/Core/Core.h @@ -6,6 +6,7 @@ #include "CoreIncludes.h" #include +#include "Buffer.h" namespace Oyster { class Core @@ -23,6 +24,90 @@ namespace Oyster static bool Init(bool SingleThreaded,bool Reference,bool ForceDX11); static bool CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen); + + class ShaderManager + { + public: + struct ShaderEffect + { + struct + { + int Pixel,Vertex,Geometry,Compute,Hull,Domain; + }Shaders; + + struct IAStage_ + { + ID3D11InputLayout* Layout; + D3D11_PRIMITIVE_TOPOLOGY Topology; + }IAStage; + + struct RenderStates_ + { + ID3D11DepthStencilState *DepthStencil; + ID3D11RasterizerState *Rasterizer; + ID3D11SamplerState **SampleState; + int SampleCount; + ID3D11BlendState *BlendState; + }RenderStates; + + struct + { + std::vector Vertex; + std::vector Geometry; + std::vector Pixel; + }CBuffers; + + ShaderEffect() + { + RenderStates.BlendState=NULL; + RenderStates.DepthStencil=NULL; + RenderStates.Rasterizer=NULL; + RenderStates.SampleState=NULL; + RenderStates.SampleCount=0; + Shaders.Compute=-1; + Shaders.Domain=-1; + Shaders.Geometry=-1; + Shaders.Hull=-1; + Shaders.Pixel=-1; + Shaders.Vertex=-1; + } + }; + enum ShaderType + { + Vertex, + Hull, + Domain, + Geometry, + Pixel, + Compute + }; + + static void SetShaderEffect(ShaderEffect); + + static void CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout); + + static bool Init(std::wstring filename, ShaderType type, std::wstring name, bool Precompiled = true); + + struct Get + { + static int Pixel(std::wstring Name); + static int Vertex(std::wstring Name); + static int Geometry(std::wstring Name); + static int Compute(std::wstring Name); + static int Hull(std::wstring Name); + static int Domain(std::wstring Name); + }; + + struct Set + { + static void Pixel(int Index); + static void Vertex(int Index); + static void Geometry(int Index); + static void Compute(int Index); + static void Hull(int Index); + static void Domain(int Index); + }; + }; }; } diff --git a/OysterGraphics/Core/CoreIncludes.h b/OysterGraphics/Core/CoreIncludes.h index 68a0c683..3e1d9306 100644 --- a/OysterGraphics/Core/CoreIncludes.h +++ b/OysterGraphics/Core/CoreIncludes.h @@ -4,14 +4,14 @@ #define NOMINMAX // Because I hate Microsoft now. ~Angry Dan. // http://lolengine.net/blog/2011/3/4/fuck-you-microsoft-near-far-macros -#include #include #include -#include -#include -#include #include +#pragma comment(lib, "d3d11.lib") +#pragma comment(lib, "d3dcompiler.lib") + + #include #include #include @@ -22,19 +22,4 @@ #define SAFE_DELETE_ARRAY(x) if( x ) { delete[](x); (x) = NULL; } #define PI (3.14159265358979323846f) -#pragma comment(lib, "d3d11.lib") -#pragma comment(lib, "d3dcompiler.lib") -#pragma comment (lib,"dxerr.lib") - -#ifdef _DEBUG -#pragma comment(lib, "d3dx11d.lib") -#pragma comment(lib, "Effects11D.lib") -#pragma comment(lib, "d3dx10d.lib") -#else -#pragma comment(lib, "d3dx11.lib") -#pragma comment(lib, "Effects11.lib") -#pragma comment(lib, "d3dx10.lib") -#endif - - #endif \ No newline at end of file diff --git a/OysterGraphics/Core/ShaderManager.cpp b/OysterGraphics/Core/ShaderManager.cpp new file mode 100644 index 00000000..45124ebe --- /dev/null +++ b/OysterGraphics/Core/ShaderManager.cpp @@ -0,0 +1,351 @@ +#include "Core.h" +#include + +const char* ShaderFunction = "ShaderMain"; + +namespace Oyster +{ + bool LoadPrecompiled(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name); + bool LoadCompile(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name); + namespace + { + struct ShaderData + { + size_t size; + char* data; + }; + std::vector PS; + std::map PSMap; + + std::vector GS; + std::map GSMap; + + std::vector CS; + std::map CSMap; + + std::vector VS; + std::vector VData; + std::map VSMap; + } + +#pragma region Init + bool Core::ShaderManager::Init(std::wstring filename, ShaderType type, std::wstring name, bool Precompiled) + { + if(Precompiled) + { + return LoadPrecompiled(filename, type, name); + } + else + { + return LoadCompile(filename, type, name); + } + return true; + } + + bool LoadPrecompiled(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name) + { + + std::ifstream stream; + ShaderData sd; + + + //Create Vertex shader and Layout + stream.open(filename, std::ifstream::in | std::ifstream::binary); + if(stream.good()) + { + stream.seekg(0, std::ios::end); + sd.size = size_t(stream.tellg()); + sd.data = new char[sd.size]; + stream.seekg(0, std::ios::beg); + stream.read(&sd.data[0], sd.size); + stream.close(); + + + ID3D11VertexShader* vertex; + ID3D11GeometryShader* geometry; + ID3D11PixelShader* pixel; + ID3D11ComputeShader* compute; + + switch(type) + { + case Core::ShaderManager::ShaderType::Vertex: + + if(VSMap.count(name)) + return false; + + if(FAILED(Core::Device->CreateVertexShader(sd.data, sd.size, 0, &vertex))) + { + return false; + } + VSMap[name] = VS.size(); + VS.push_back(vertex); + VData.push_back(sd); + break; + + case Core::ShaderManager::ShaderType::Hull: + case Core::ShaderManager::ShaderType::Domain: + + return false; + + case Core::ShaderManager::ShaderType::Geometry: + + if(GSMap.count(name)) + return false; + if(FAILED(Core::Device->CreateGeometryShader(sd.data, sd.size, 0, &geometry))) + { + return false; + } + GSMap[name] = GS.size(); + GS.push_back(geometry); + break; + + case Core::ShaderManager::ShaderType::Pixel: + + if(PSMap.count(name)) + return false; + if(FAILED(Core::Device->CreatePixelShader(sd.data, sd.size, 0, &pixel))) + { + return false; + } + PSMap[name] = PS.size(); + PS.push_back(pixel); + break; + + case Core::ShaderManager::ShaderType::Compute: + + if(CSMap.count(name)) + return false; + if(FAILED(Core::Device->CreateComputeShader(sd.data, sd.size, 0, &compute))) + { + return false; + } + CSMap[name] = CS.size(); + CS.push_back(compute); + break; + } + } + else + { + return false; + } + return true; + } + + bool LoadCompile(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name) + { + /// \todo error reporting + ID3D10Blob *Shader,*Error; + switch(type) + { + case Core::ShaderManager::ShaderType::Pixel: + + ID3D11PixelShader* pixel; + + if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"ps_5_0",0,0,&Shader,&Error))) + { + std::string fel = (char*)Error->GetBufferPointer(); + Error->Release(); + return false; + } + if(FAILED(Oyster::Core::Device->CreatePixelShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&pixel))) + { + Error->Release(); + Shader->Release(); + return false; + } + Shader->Release(); + if(!PSMap.count(name)) + { + PSMap[name] = PS.size(); + PS.push_back(pixel); + } + else + { + PS[PSMap[name]] = pixel; + } + break; + + case Core::ShaderManager::ShaderType::Geometry: + + ID3D11GeometryShader* geometry; + + if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"gs_5_0",0,0,&Shader,&Error))) + { + std::string fel = (char*)Error->GetBufferPointer(); + Error->Release(); + return false; + } + if(FAILED(Oyster::Core::Device->CreateGeometryShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&geometry))) + { + Error->Release(); + Shader->Release(); + return false; + } + Shader->Release(); + if(!GSMap.count(name)) + { + GSMap[name] = GS.size(); + GS.push_back(geometry); + } + else + { + GS[GSMap[name]] = geometry; + } + break; + + case Core::ShaderManager::ShaderType::Vertex: + + ID3D11VertexShader* vertex; + + if(FAILED(D3DCompileFromFile(filename.c_str(),NULL,NULL,ShaderFunction,"vs_5_0",0,0,&Shader,&Error))) + { + std::string fel = (char*)Error->GetBufferPointer(); + Error->Release(); + return false; + } + if(FAILED(Oyster::Core::Device->CreateVertexShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&vertex))) + { + Error->Release(); + Shader->Release(); + return false; + } + if(!VSMap.count(name)) + { + VSMap[name] = VS.size(); + VS.push_back(vertex); + ShaderData sd; + sd.size = Shader->GetBufferSize(); + sd.data = new char[sd.size]; + memcpy(sd.data,Shader->GetBufferPointer(),sd.size); + VData.push_back(sd); + } + else + { + VS[VSMap[name]] = vertex; + delete[] VData[VSMap[name]].data; + VData[VSMap[name]].size = Shader->GetBufferSize(); + VData[VSMap[name]].data = new char[VData[VSMap[name]].size]; + memcpy(VData[VSMap[name]].data,Shader->GetBufferPointer(),VData[VSMap[name]].size); + } + + Shader->Release(); + break; + + } + return true; + } +#pragma endregion + + void Core::ShaderManager::CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout) + { + if(VertexIndex==-1) + { + Layout=0; + return; + } + Device->CreateInputLayout(desc,ElementCount,VData[VertexIndex].data,VData[VertexIndex].size,&Layout); + } + +#pragma region Get + int Core::ShaderManager::Get::Pixel(std::wstring Name) + { + if(PSMap.count(Name)) + return PSMap[Name]; + return -1; + } + + int Core::ShaderManager::Get::Vertex(std::wstring Name) + { + if(VSMap.count(Name)) + return VSMap[Name]; + return -1; + } + int Core::ShaderManager::Get::Geometry(std::wstring Name) + { + if(GSMap.count(Name)) + return GSMap[Name]; + return -1; + } + + int Core::ShaderManager::Get::Compute(std::wstring Name) + { + if(CSMap.count(Name)) + return CSMap[Name]; + return -1; + } + int Core::ShaderManager::Get::Hull(std::wstring Name) + { + return -1; + } + int Core::ShaderManager::Get::Domain(std::wstring Name) + { + return -1; + } +#pragma endregion + +#pragma region Set + /// \todo smart set + void Core::ShaderManager::Set::Pixel(int Index) + { + if(Index==-1) + DeviceContext->PSSetShader( NULL,NULL,0); + else + DeviceContext->PSSetShader( PS[Index],NULL,0); + } + void Core::ShaderManager::Set::Vertex(int Index) + { + if(Index==-1) + DeviceContext->VSSetShader( NULL,NULL,0); + else + DeviceContext->VSSetShader( VS[Index],NULL,0); + } + void Core::ShaderManager::Set::Geometry(int Index) + { + if(Index==-1) + DeviceContext->GSSetShader( NULL,NULL,0); + else + DeviceContext->GSSetShader( GS[Index],NULL,0); + } + void Core::ShaderManager::Set::Compute(int Index) + { + if(Index==-1) + DeviceContext->CSSetShader( NULL,NULL,0); + else + DeviceContext->CSSetShader( CS[Index],NULL,0); + } + /// \todo set Hull + void Core::ShaderManager::Set::Hull(int Index) + { + return; + } + /// \todo set Domain + void Core::ShaderManager::Set::Domain(int Index) + { + return; + } +#pragma endregion + + /// \todo smart Set ie. not resetting the shader + /// \todo research states + /// \todo smart buffer set + void Core::ShaderManager::SetShaderEffect(ShaderEffect se) + { + Set::Pixel(se.Shaders.Pixel); + Set::Vertex(se.Shaders.Vertex); + Set::Geometry(se.Shaders.Geometry); + Set::Compute(se.Shaders.Compute); + Oyster::Core::DeviceContext->IASetInputLayout(se.IAStage.Layout); + Oyster::Core::DeviceContext->IASetPrimitiveTopology(se.IAStage.Topology); + for(unsigned int i=0;iApply(i); + for(unsigned int i=0;iApply(i); + for(unsigned int i=0;iApply(i); + Oyster::Core::DeviceContext->RSSetState(se.RenderStates.Rasterizer); + Oyster::Core::DeviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState); + float test[4] = {0}; + Oyster::Core::DeviceContext->OMSetBlendState(se.RenderStates.BlendState,test,-1); + } + +} \ No newline at end of file diff --git a/OysterGraphics/Engine.cpp b/OysterGraphics/Engine.cpp index 4dd2aad0..bee1e63d 100644 --- a/OysterGraphics/Engine.cpp +++ b/OysterGraphics/Engine.cpp @@ -15,6 +15,7 @@ public: DXGI_SAMPLE_DESC sampleDesc; D3D11_VIEWPORT viewPort; oysterPrivates():instance(false),swapChained(false),depth(NULL),rtv(NULL), depthTexture(NULL){}; + int sizeX, sizeY; class State { public: @@ -55,13 +56,11 @@ bool Oyster::Engine::Init::HasSwapChain() bool Oyster::Engine::Init::CreateSwapChain(HWND Window,int NrofBuffers,bool MSAA_Quality,bool Fullscreen) { - if(Window==0) - { - if(Oyster::Window::Handle==0) - return false; - else - Window = Oyster::Window::Handle; - } + RECT rc; + GetClientRect( Window, &rc ); + instance.sizeX = rc.right - rc.left; + instance.sizeY = rc.bottom - rc.top; + if(!instance.swapChained) { if(Oyster::Core::CreateSwapChain(Window,NrofBuffers,MSAA_Quality,Fullscreen)) @@ -71,11 +70,6 @@ bool Oyster::Engine::Init::CreateSwapChain(HWND Window,int NrofBuffers,bool MSAA return instance.swapChained; } -bool Oyster::Engine::Init::InitializeWindow(const LPCSTR appName, const LPCSTR className,const HINSTANCE &hInstance, const int &nCmdShow, WNDPROC wProc, bool handleLoop ) -{ - return Oyster::Window::init(appName,className,hInstance,nCmdShow,wProc,handleLoop); -} - bool Oyster::Engine::Init::FullInit(const Setup& setup) { if(!Oyster::Engine::Init::Instance(setup.Common.SingleThreaded,setup.Common.Reference,setup.Common.ForceDX11)) @@ -104,7 +98,7 @@ bool Oyster::Engine::Init::FullInit(const Setup& setup) Oyster::Resources::Buffers::Init(); Oyster::Resources::ShaderEffects::Init(); - Oyster::Resources::PipeLineResourses::Init(); + Oyster::Resources::PipeLineResourses::Init(instance.sizeX, instance.sizeY); return true; } @@ -186,7 +180,7 @@ void Oyster::Engine::Render::Geometry(const Oyster::Render::Model* models,int co if(cBufferEveryObject) { void* data = cBufferEveryObject->Map(); - memcpy(data,&(models[i].World->getTranspose()),64); + memcpy(data,&(models[i].World->GetTranspose()),64); cBufferEveryObject->Unmap(); } Oyster::Core::DeviceContext->PSSetShaderResources(0,models[i].info->Material.size(),&(models[i].info->Material[0])); @@ -205,23 +199,23 @@ void Oyster::Engine::Render::Geometry(const Oyster::Render::Model* models,int co void Oyster::Engine::Render::Text(std::string text, Oyster::Math::Float2 size, Oyster::Math::Float3 Pos) { - Pos.x -= Oyster::Window::Size.left/2; + Pos.x -= instance.sizeX/2; Pos.x += size.x; - Pos.y -= Oyster::Window::Size.bottom/2; + Pos.y -= instance.sizeY/2; Pos.y += size.y; Matrix m; - Math::identityMatrix(m); - float width = (1.0f/(Window::Size.left/2.0f)); - float height = (1.0f/(Window::Size.bottom/2.0f)); + m = Math::Matrix::identity; + float width = (1.0f/(instance.sizeX/2.0f)); + float height = (1.0f/(instance.sizeY/2.0f)); m.m41=Pos.x * width; m.m42=-Pos.y * height; m.m43=Pos.z; m.m11=width*size.x; m.m22=height*size.y; void* dest = Resources::Buffers::CBufferGs.Map(); - memcpy(dest,&m.getTranspose(),64); + memcpy(dest,&m.GetTranspose(),64); Resources::Buffers::CBufferGs.Unmap(); Oyster::Render::Textbox::Update(text, size.x); Oyster::Engine::PrepareForRendering::Begin2DTextRender(); @@ -236,11 +230,11 @@ void Oyster::Engine::Render::ScreenQuad(ID3D11ShaderResourceView* srv, float ZPo Oyster::Core::DeviceContext->PSSetShaderResources(0,1,&srv); Matrix m; - Math::identityMatrix(m); + m = Math::Matrix::identity; m.m43=ZPos; void* dest = Resources::Buffers::CBufferGs.Map(); - memcpy(dest,&m.getTranspose(),64); + memcpy(dest,&m.GetTranspose(),64); Resources::Buffers::CBufferGs.Unmap(); Oyster::Core::DeviceContext->Draw(1,0); @@ -251,16 +245,16 @@ void Oyster::Engine::Render::Sprite(ID3D11ShaderResourceView* srv, Oyster::Math: Oyster::Core::DeviceContext->PSSetShaderResources(0,1,&srv); - Pos.x -= Oyster::Window::Size.left/2; + Pos.x -= instance.sizeX/2; Pos.x += size.x/2; - Pos.y -= Oyster::Window::Size.bottom/2; + Pos.y -= instance.sizeY/2; Pos.y += size.y/2; Matrix m; - Math::identityMatrix(m); - float width = (1.0f/(Window::Size.left/2.0f)); - float height = (1.0f/(Window::Size.bottom/2.0f)); + m = Math::Matrix::identity; + float width = (1.0f/(instance.sizeX/2.0f)); + float height = (1.0f/(instance.sizeY/2.0f)); m.m41=Pos.x * width; m.m42=-Pos.y * height; m.m43=Pos.z; @@ -268,7 +262,7 @@ void Oyster::Engine::Render::Sprite(ID3D11ShaderResourceView* srv, Oyster::Math: m.m22=height*size.y/2; void* dest = Resources::Buffers::CBufferGs.Map(); - memcpy(dest,&m.getTranspose(),64); + memcpy(dest,&m.GetTranspose(),64); Resources::Buffers::CBufferGs.Unmap(); Oyster::Core::DeviceContext->Draw(1,0); @@ -286,8 +280,8 @@ bool CreateDepthStencil(bool MSAA_Quality) desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; desc.CPUAccessFlags=0; desc.MiscFlags=0; - desc.Height = Oyster::Window::Size.bottom; - desc.Width = Oyster::Window::Size.left; + desc.Height = instance.sizeY; + desc.Width = instance.sizeX; //Check and Set multiSampling @@ -355,8 +349,8 @@ void SetViewPort() { instance.viewPort.TopLeftX = 0.0f; instance.viewPort.TopLeftY = 0.0f; - instance.viewPort.Width = (float)Oyster::Window::Size.left; - instance.viewPort.Height = (float)Oyster::Window::Size.bottom; + instance.viewPort.Width = (float)instance.sizeX; + instance.viewPort.Height = (float)instance.sizeY; instance.viewPort.MinDepth = 0.0f; instance.viewPort.MaxDepth = 1.0f; @@ -373,7 +367,7 @@ void Blur(int target) //dispatch blurr horizontal Oyster::Shader::Set::SetCompute(Oyster::Shader::Get::GetCompute("BlurHorizontal")); - Oyster::Core::DeviceContext->Dispatch(7,Oyster::Window::Size.bottom,1); + Oyster::Core::DeviceContext->Dispatch(7,instance.sizeX,1); //clean Pipeline Oyster::Core::DeviceContext->CSSetShaderResources(0,16,&Oyster::Resources::PipeLineResourses::SrvNulls[0]); @@ -385,7 +379,7 @@ void Blur(int target) //dispatch blurr vertical Oyster::Shader::Set::SetCompute(Oyster::Shader::Get::GetCompute("BlurVertical")); - Oyster::Core::DeviceContext->Dispatch(Oyster::Window::Size.left,5,1); + Oyster::Core::DeviceContext->Dispatch(instance.sizeY,5,1); //clean Pipeline Oyster::Core::DeviceContext->CSSetShaderResources(0,16,&Oyster::Resources::PipeLineResourses::SrvNulls[0]); @@ -419,24 +413,24 @@ void Oyster::Engine::Pipeline::Deffered_Lightning::NewFrame(const Float4& col, c Matrix V = Oyster::Math::Float4x4(View); Matrix VP = V*P; - Oyster::Resources::PipeLineResourses::LightData.projectionMatrix = P.getTranspose(); + Oyster::Resources::PipeLineResourses::LightData.projectionMatrix = P.GetTranspose(); Oyster::Resources::PipeLineResourses::LightData.viewMatrix = V; - Oyster::Collision::Frustrum( VP ).split(Oyster::Resources::PipeLineResourses::SubFrustrums, Oyster::Resources::PipeLineResourses::FrustrumDimensions.x, Oyster::Resources::PipeLineResourses::FrustrumDimensions.y, Oyster::Resources::PipeLineResourses::FrustrumDimensions.z ); + Oyster::Collision3D::Frustrum( VP ).Split(Oyster::Resources::PipeLineResourses::SubFrustrums, Oyster::Resources::PipeLineResourses::FrustrumDimensions.x, Oyster::Resources::PipeLineResourses::FrustrumDimensions.y, Oyster::Resources::PipeLineResourses::FrustrumDimensions.z ); void* dest = Oyster::Resources::ShaderEffects::ModelEffect.CBuffers.Vertex[0]->Map(); - memcpy(dest,&VP.getTranspose(),64); + memcpy(dest,&VP.GetTranspose(),64); Oyster::Resources::ShaderEffects::ModelEffect.CBuffers.Vertex[0]->Unmap(); dest= Oyster::Resources::ShaderEffects::ModelEffect.CBuffers.Vertex[1]->Map(); - memcpy(dest,&V.getTranspose(),64); + memcpy(dest,&V.GetTranspose(),64); Oyster::Resources::ShaderEffects::ModelEffect.CBuffers.Vertex[1]->Unmap(); dest = Oyster::Resources::PipeLineResourses::Resources[0]->Map(); unsigned int bytes=0; for(int i=0;iUnmap(); diff --git a/OysterGraphics/EngineIncludes.h b/OysterGraphics/EngineIncludes.h index e1a763db..f3a94bfb 100644 --- a/OysterGraphics/EngineIncludes.h +++ b/OysterGraphics/EngineIncludes.h @@ -13,22 +13,14 @@ #include "Shader\Shader.h" // Math -#include "Math\OysterMath.h" +#include "OysterMath.h" -// FileLoader -#include "FileLoader\ObjReader.h" -// Windows -#include "Window\Window.h" -// Input -#include "Input\InputController.h" // Collision -#include "Collision\Collision.h" +#include "Collision\Frustrum.h" -// Game Definitions -#include "Game\OysterGame.h" // Resources #include "Resourses\ShaderEffects.h" diff --git a/OysterGraphics/OysterGraphics.vcxproj b/OysterGraphics/OysterGraphics.vcxproj index 85802479..98523a93 100644 --- a/OysterGraphics/OysterGraphics.vcxproj +++ b/OysterGraphics/OysterGraphics.vcxproj @@ -140,16 +140,14 @@ + - - - @@ -158,7 +156,6 @@ - @@ -168,7 +165,6 @@ - diff --git a/OysterGraphics/OysterGraphics.vcxproj.filters b/OysterGraphics/OysterGraphics.vcxproj.filters index 46b792cc..ba4429f5 100644 --- a/OysterGraphics/OysterGraphics.vcxproj.filters +++ b/OysterGraphics/OysterGraphics.vcxproj.filters @@ -21,12 +21,6 @@ Source Files - - Source Files - - - Source Files - Source Files @@ -45,10 +39,10 @@ Source Files - + Source Files - + Source Files @@ -62,12 +56,6 @@ Header Files - - Header Files - - - Header Files - Header Files @@ -95,15 +83,15 @@ Header Files - - Header Files - Header Files Header Files + + Header Files + diff --git a/OysterGraphics/Render/Camera.h b/OysterGraphics/Render/Camera.h index cc558144..96725f5a 100644 --- a/OysterGraphics/Render/Camera.h +++ b/OysterGraphics/Render/Camera.h @@ -1,6 +1,6 @@ #pragma once -#include "..\Math\OysterMath.h" +#include "OysterMath.h" namespace Oyster { diff --git a/OysterGraphics/Render/TextBox.cpp b/OysterGraphics/Render/TextBox.cpp index 1cd162c6..e0a65d24 100644 --- a/OysterGraphics/Render/TextBox.cpp +++ b/OysterGraphics/Render/TextBox.cpp @@ -19,12 +19,14 @@ bool Textbox::Init() return true; //return true; } +/// \todo proper reading of texture bool Textbox::SetTexture(const char* _file) { - if(FAILED(D3DX11CreateShaderResourceViewFromFileA(Oyster::Core::Device, _file, NULL, NULL, &Texture, NULL))) + return false; + /*if(FAILED(D3DX11CreateShaderResourceViewFromFileA(Oyster::Core::Device, _file, NULL, NULL, &Texture, NULL))) { return false; - } + }*/ return true; } bool Textbox::UpdateTextField(std::string _str) diff --git a/OysterGraphics/Resourses/Manager.cpp b/OysterGraphics/Resourses/Manager.cpp index c4132fba..47aa5eaf 100644 --- a/OysterGraphics/Resourses/Manager.cpp +++ b/OysterGraphics/Resourses/Manager.cpp @@ -4,44 +4,44 @@ std::unordered_map< std::string, Oyster::Render::ModelInfo*> Oyster::Resources:: Oyster::Render::Model* Oyster::Resources::Manager::LoadModel(std::string Filename, Matrix Scale) { - //TODO: Add redundncy sheck, to ensure not recreating model + ////TODO: Add redundncy sheck, to ensure not recreating model - //Loop to find filename + ////Loop to find filename - //If found Return Model + ////If found Return Model - //else Create Model + ////else Create Model - Oyster::FileLoaders::ObjReader *reader = Oyster::FileLoaders::ObjReader::LoadFile(Filename, Scale); - Oyster::FileLoaders::ObjReader::Vertex** vertex = new Oyster::FileLoaders::ObjReader::Vertex*[1]; - int vcount; - std::map textures; - reader->GetVertexData( vertex, vcount, textures ); + //Oyster::FileLoaders::ObjReader *reader = Oyster::FileLoaders::ObjReader::LoadFile(Filename, Scale); + //Oyster::FileLoaders::ObjReader::Vertex** vertex = new Oyster::FileLoaders::ObjReader::Vertex*[1]; + //int vcount; + //std::map textures; + //reader->GetVertexData( vertex, vcount, textures ); - Oyster::Buffer::BUFFER_INIT_DESC desc; - desc.ElementSize=sizeof(Oyster::FileLoaders::ObjReader::Vertex); - desc.NumElements = vcount; - desc.InitData = *vertex; - desc.Type = Oyster::Buffer::VERTEX_BUFFER; - desc.Usage = Oyster::Buffer::BUFFER_DEFAULT; - - ID3D11ShaderResourceView *srv = textures["Diffuse"]; + //Oyster::Buffer::BUFFER_INIT_DESC desc; + //desc.ElementSize=sizeof(Oyster::FileLoaders::ObjReader::Vertex); + //desc.NumElements = vcount; + //desc.InitData = *vertex; + //desc.Type = Oyster::Buffer::VERTEX_BUFFER; + //desc.Usage = Oyster::Buffer::BUFFER_DEFAULT; + // + //ID3D11ShaderResourceView *srv = textures["Diffuse"]; - Oyster::Render::ModelInfo* m = new Oyster::Render::ModelInfo(); - - m->Vertices = *(Oyster::Engine::Init::Buffers::CreateBuffer(desc)); - m->VertexCount = vcount; - m->Material.push_back(srv); - srv = textures["Specular"]; - m->Material.push_back(srv); - srv = textures["Glow"]; - m->Material.push_back(srv); - m->Indexed=false; - - Oyster::Render::Model* model = new Oyster::Render::Model(); - model->info=m; - model->Visible = true; - model->World = &Oyster::Math::Float4x4(Oyster::Math::Float4x4::identity); - return model; + //Oyster::Render::ModelInfo* m = new Oyster::Render::ModelInfo(); + // + //m->Vertices = *(Oyster::Engine::Init::Buffers::CreateBuffer(desc)); + //m->VertexCount = vcount; + //m->Material.push_back(srv); + //srv = textures["Specular"]; + //m->Material.push_back(srv); + //srv = textures["Glow"]; + //m->Material.push_back(srv); + //m->Indexed=false; + // + //Oyster::Render::Model* model = new Oyster::Render::Model(); + //model->info=m; + //model->Visible = true; + //model->World = &Oyster::Math::Float4x4(Oyster::Math::Float4x4::identity); + return NULL; } diff --git a/OysterGraphics/Resourses/PipelineResources.cpp b/OysterGraphics/Resourses/PipelineResources.cpp index 291c3c7c..794fa57c 100644 --- a/OysterGraphics/Resourses/PipelineResources.cpp +++ b/OysterGraphics/Resourses/PipelineResources.cpp @@ -18,29 +18,29 @@ ID3D11RenderTargetView* PipeLineResourses::RtvNulls[16] = {0}; ID3D11ShaderResourceView* PipeLineResourses::SrvNulls[16] = {0}; ID3D11UnorderedAccessView* PipeLineResourses::uavNULL[16] = {0}; -Oyster::Collision::Frustrum* PipeLineResourses::SubFrustrums = 0; +Oyster::Collision3D::Frustrum* PipeLineResourses::SubFrustrums = 0; int PipeLineResourses::FrustrumSize = 0; LinearAlgebra::Vector3 PipeLineResourses::FrustrumDimensions = LinearAlgebra::Vector3(); Oyster::Resources::BufferDefinitions::LightStructureBuffer PipeLineResourses::LightData = Oyster::Resources::BufferDefinitions::LightStructureBuffer(); -void PipeLineResourses::Init() +void PipeLineResourses::Init(int sizeX, int sizeY) { - InitGeometry(); + InitGeometry(sizeX, sizeY); InitSSAOData(); - InitSubFrustrums(); + InitSubFrustrums(sizeX, sizeY); InitPointLights(); InitLightData(); - InitLighting(); + InitLighting(sizeX, sizeY); } -void PipeLineResourses::InitGeometry() +void PipeLineResourses::InitGeometry(int sizeX, int sizeY) { D3D11_TEXTURE2D_DESC Tdesc; - Tdesc.Width = Oyster::Window::Size.left; - Tdesc.Height = Oyster::Window::Size.bottom; + Tdesc.Width = sizeX; + Tdesc.Height = sizeY; Tdesc.MipLevels = Tdesc.ArraySize = 1; Tdesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; Tdesc.SampleDesc.Count = 1; @@ -86,7 +86,7 @@ void PipeLineResourses::InitSSAOData() (float)rand() / (RAND_MAX + 1) * (1 - -1) + -1, (float)rand() / (RAND_MAX + 1) * (1 - 0) + 0); } - kernel[i].normalize(); + kernel[i].Normalize(); float scale = float(i) / float(NrOfSamples); scale = (0.1f*(1 - scale * scale) + 1.0f *( scale * scale)); @@ -102,7 +102,7 @@ void PipeLineResourses::InitSSAOData() (float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, 0.0f); } - random[i].normalize(); + random[i].Normalize(); } } @@ -137,15 +137,15 @@ void PipeLineResourses::InitSSAOData() delete[] random; } -void PipeLineResourses::InitSubFrustrums() +void PipeLineResourses::InitSubFrustrums(int sizeX, int sizeY) { - FrustrumDimensions.x = (::Oyster::Window::Size.left + 15U) / 16U; - FrustrumDimensions.y = (::Oyster::Window::Size.bottom + 15U) / 16U; + FrustrumDimensions.x = (sizeX + 15U) / 16U; + FrustrumDimensions.y = (sizeY + 15U) / 16U; FrustrumDimensions.z = 1; FrustrumSize = FrustrumDimensions.x * FrustrumDimensions.y * FrustrumDimensions.z; if(SubFrustrums!=0) delete[] SubFrustrums; - SubFrustrums = new Frustrum[ FrustrumSize ]; + SubFrustrums = new Collision3D::Frustrum[ FrustrumSize ]; Oyster::Buffer::BUFFER_INIT_DESC desc; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; @@ -197,11 +197,11 @@ void PipeLineResourses::InitLightData() LightData.numDispatches = FrustrumDimensions; } -void PipeLineResourses::InitLighting() +void PipeLineResourses::InitLighting(int sizeX, int sizeY) { D3D11_TEXTURE2D_DESC Tdesc; - Tdesc.Width = Oyster::Window::Size.left; - Tdesc.Height = Oyster::Window::Size.bottom; + Tdesc.Width = sizeX; + Tdesc.Height = sizeY; Tdesc.MipLevels = Tdesc.ArraySize = 1; Tdesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; Tdesc.SampleDesc.Count = 1; diff --git a/OysterGraphics/Resourses/PipelineResources.h b/OysterGraphics/Resourses/PipelineResources.h index b7f4a858..22ccd9d6 100644 --- a/OysterGraphics/Resourses/PipelineResources.h +++ b/OysterGraphics/Resourses/PipelineResources.h @@ -43,22 +43,22 @@ namespace Oyster static ID3D11ShaderResourceView* SrvNulls[16]; static ID3D11UnorderedAccessView* uavNULL[16]; - static Oyster::Collision::Frustrum* SubFrustrums; + static Oyster::Collision3D::Frustrum* SubFrustrums; static int FrustrumSize; static LinearAlgebra::Vector3 FrustrumDimensions; static Oyster::Resources::BufferDefinitions::LightStructureBuffer LightData; - static void Init(); + static void Init(int sizeX, int sizeY); - static void InitGeometry(); + static void InitGeometry(int sizeX, int sizeY); static void InitSSAOData(); - static void InitSubFrustrums(); + static void InitSubFrustrums(int sizeX, int sizeY); static void InitPointLights(); static void InitLightData(); - static void InitLighting(); + static void InitLighting(int sizeX, int sizeY); }; } }