merge with graphics
This commit is contained in:
commit
229741e707
|
@ -1,9 +1,9 @@
|
|||
#include "Buffer.h"
|
||||
#include "Core.h"
|
||||
|
||||
using namespace Oyster;
|
||||
using namespace Oyster::Graphics;
|
||||
|
||||
Oyster::Buffer::Buffer()
|
||||
Buffer::Buffer()
|
||||
{
|
||||
mBuffer = NULL;
|
||||
}
|
||||
|
@ -23,32 +23,32 @@ HRESULT Buffer::Apply(UINT32 misc) const
|
|||
{
|
||||
UINT32 vertexSize = mElementSize;
|
||||
UINT32 offset = 0;
|
||||
Oyster::Core::DeviceContext->IASetVertexBuffers(misc, 1, &mBuffer, &vertexSize, &offset );
|
||||
Core::deviceContext->IASetVertexBuffers(misc, 1, &mBuffer, &vertexSize, &offset );
|
||||
}
|
||||
break;
|
||||
case INDEX_BUFFER:
|
||||
{
|
||||
Oyster::Core::DeviceContext->IASetIndexBuffer(mBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
Core::deviceContext->IASetIndexBuffer(mBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
}
|
||||
break;
|
||||
case CONSTANT_BUFFER_VS:
|
||||
{
|
||||
Oyster::Core::DeviceContext->VSSetConstantBuffers(misc, 1, &mBuffer);
|
||||
Core::deviceContext->VSSetConstantBuffers(misc, 1, &mBuffer);
|
||||
}
|
||||
break;
|
||||
case CONSTANT_BUFFER_GS:
|
||||
{
|
||||
Oyster::Core::DeviceContext->GSSetConstantBuffers(misc, 1, &mBuffer);
|
||||
Core::deviceContext->GSSetConstantBuffers(misc, 1, &mBuffer);
|
||||
}
|
||||
break;
|
||||
case CONSTANT_BUFFER_PS:
|
||||
{
|
||||
Oyster::Core::DeviceContext->PSSetConstantBuffers(misc, 1, &mBuffer);
|
||||
Core::deviceContext->PSSetConstantBuffers(misc, 1, &mBuffer);
|
||||
}
|
||||
break;
|
||||
case CONSTANT_BUFFER_CS:
|
||||
{
|
||||
Oyster::Core::DeviceContext->CSSetConstantBuffers(misc,1,&mBuffer);
|
||||
Core::deviceContext->CSSetConstantBuffers(misc,1,&mBuffer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -145,11 +145,11 @@ HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc)
|
|||
data.pSysMem = initDesc.InitData;
|
||||
data.SysMemPitch=0;
|
||||
data.SysMemSlicePitch = 0;
|
||||
hr = Oyster::Core::Device->CreateBuffer(&bufferDesc, &data, &mBuffer);
|
||||
hr = Core::device->CreateBuffer(&bufferDesc, &data, &mBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = Oyster::Core::Device->CreateBuffer(&bufferDesc, NULL, &mBuffer);
|
||||
hr = Core::device->CreateBuffer(&bufferDesc, NULL, &mBuffer);
|
||||
}
|
||||
|
||||
if(FAILED(hr))
|
||||
|
@ -173,7 +173,7 @@ void* Buffer::Map()
|
|||
else if(mUsage == BUFFER_CPU_WRITE_DISCARD) mapType = D3D11_MAP_WRITE_DISCARD;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
if(FAILED(hr = Oyster::Core::DeviceContext->Map(
|
||||
if(FAILED(hr = Core::deviceContext->Map(
|
||||
mBuffer,
|
||||
0,
|
||||
(D3D11_MAP)mapType,
|
||||
|
@ -194,10 +194,10 @@ void* Buffer::Map()
|
|||
|
||||
void Buffer::Unmap()
|
||||
{
|
||||
Oyster::Core::DeviceContext->Unmap( mBuffer, 0 );
|
||||
Core::deviceContext->Unmap( mBuffer, 0 );
|
||||
}
|
||||
|
||||
Oyster::Buffer::operator ID3D11Buffer *()
|
||||
Buffer::operator ID3D11Buffer *()
|
||||
{
|
||||
return this->mBuffer;
|
||||
}
|
||||
|
|
|
@ -6,72 +6,74 @@
|
|||
|
||||
namespace Oyster
|
||||
{
|
||||
class Buffer
|
||||
namespace Graphics
|
||||
{
|
||||
public:
|
||||
enum BUFFER_TYPE
|
||||
class Buffer
|
||||
{
|
||||
VERTEX_BUFFER,
|
||||
INDEX_BUFFER,
|
||||
CONSTANT_BUFFER_VS,
|
||||
CONSTANT_BUFFER_GS,
|
||||
CONSTANT_BUFFER_PS,
|
||||
CONSTANT_BUFFER_CS,
|
||||
STRUCTURED_BUFFER,
|
||||
BUFFER_TYPE_COUNT
|
||||
};
|
||||
|
||||
enum BUFFER_USAGE
|
||||
{
|
||||
BUFFER_DEFAULT,
|
||||
BUFFER_STREAM_OUT_TARGET,
|
||||
BUFFER_CPU_WRITE,
|
||||
BUFFER_CPU_WRITE_DISCARD,
|
||||
BUFFER_CPU_READ,
|
||||
BUFFER_USAGE_COUNT,
|
||||
BUFFER_USAGE_IMMUTABLE
|
||||
};
|
||||
|
||||
struct BUFFER_INIT_DESC
|
||||
{
|
||||
BUFFER_TYPE Type;
|
||||
UINT32 NumElements;
|
||||
UINT32 ElementSize;
|
||||
BUFFER_USAGE Usage;
|
||||
void* InitData;
|
||||
|
||||
BUFFER_INIT_DESC()
|
||||
public:
|
||||
enum BUFFER_TYPE
|
||||
{
|
||||
InitData = NULL;
|
||||
Usage = BUFFER_DEFAULT;
|
||||
}
|
||||
VERTEX_BUFFER,
|
||||
INDEX_BUFFER,
|
||||
CONSTANT_BUFFER_VS,
|
||||
CONSTANT_BUFFER_GS,
|
||||
CONSTANT_BUFFER_PS,
|
||||
CONSTANT_BUFFER_CS,
|
||||
STRUCTURED_BUFFER,
|
||||
BUFFER_TYPE_COUNT
|
||||
};
|
||||
|
||||
enum BUFFER_USAGE
|
||||
{
|
||||
BUFFER_DEFAULT,
|
||||
BUFFER_STREAM_OUT_TARGET,
|
||||
BUFFER_CPU_WRITE,
|
||||
BUFFER_CPU_WRITE_DISCARD,
|
||||
BUFFER_CPU_READ,
|
||||
BUFFER_USAGE_COUNT,
|
||||
BUFFER_USAGE_IMMUTABLE
|
||||
};
|
||||
|
||||
struct BUFFER_INIT_DESC
|
||||
{
|
||||
BUFFER_TYPE Type;
|
||||
UINT32 NumElements;
|
||||
UINT32 ElementSize;
|
||||
BUFFER_USAGE Usage;
|
||||
void* InitData;
|
||||
|
||||
BUFFER_INIT_DESC()
|
||||
{
|
||||
InitData = NULL;
|
||||
Usage = BUFFER_DEFAULT;
|
||||
}
|
||||
};
|
||||
protected:
|
||||
ID3D11Buffer* mBuffer;
|
||||
BUFFER_TYPE mType;
|
||||
BUFFER_USAGE mUsage;
|
||||
|
||||
UINT32 mElementSize;
|
||||
UINT32 mElementCount;
|
||||
public:
|
||||
Buffer();
|
||||
virtual ~Buffer();
|
||||
|
||||
HRESULT Init(const BUFFER_INIT_DESC& initDesc);
|
||||
|
||||
void* Map();
|
||||
void Unmap();
|
||||
|
||||
operator ID3D11Buffer*();
|
||||
operator const ID3D11Buffer*() const;
|
||||
|
||||
HRESULT Apply(UINT32 misc = 0) const;
|
||||
|
||||
ID3D11Buffer* GetBufferPointer();
|
||||
UINT32 GetVertexSize();
|
||||
UINT32 GetElementCount();
|
||||
};
|
||||
protected:
|
||||
ID3D11Buffer* mBuffer;
|
||||
BUFFER_TYPE mType;
|
||||
BUFFER_USAGE mUsage;
|
||||
|
||||
UINT32 mElementSize;
|
||||
UINT32 mElementCount;
|
||||
public:
|
||||
Buffer();
|
||||
virtual ~Buffer();
|
||||
|
||||
HRESULT Init(const BUFFER_INIT_DESC& initDesc);
|
||||
|
||||
void* Map();
|
||||
void Unmap();
|
||||
|
||||
operator ID3D11Buffer*();
|
||||
operator const ID3D11Buffer*() const;
|
||||
|
||||
HRESULT Apply(UINT32 misc = 0) const;
|
||||
|
||||
ID3D11Buffer* GetBufferPointer();
|
||||
UINT32 GetVertexSize();
|
||||
UINT32 GetElementCount();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,169 +1,25 @@
|
|||
#include "Core.h"
|
||||
|
||||
using namespace Oyster;
|
||||
using namespace Oyster::Graphics;
|
||||
using std::string;
|
||||
|
||||
//GPU
|
||||
ID3D11Device *Core::Device = NULL;
|
||||
ID3D11Device *Core::device = NULL;
|
||||
|
||||
//API
|
||||
ID3D11DeviceContext *Core::DeviceContext = NULL;
|
||||
ID3D11DeviceContext *Core::deviceContext = NULL;
|
||||
|
||||
//SwapChain
|
||||
IDXGISwapChain* Core::SwapChain = NULL;
|
||||
IDXGISwapChain* Core::swapChain = NULL;
|
||||
|
||||
std::stringstream Log;
|
||||
std::stringstream Core::log;
|
||||
|
||||
inline std::stringstream* AccesLog(){return &Log;}
|
||||
ID3D11RenderTargetView* Core::backBufferRTV = NULL;
|
||||
|
||||
bool Core::Init(bool SingleThreaded, bool Reference,bool ForceDX11)
|
||||
{
|
||||
UINT createDeviceFlags = 0;
|
||||
ID3D11UnorderedAccessView* Core::backBufferUAV = NULL;
|
||||
|
||||
if( SingleThreaded )
|
||||
createDeviceFlags = ::D3D11_CREATE_DEVICE_SINGLETHREADED;
|
||||
ID3D11DepthStencilView* Core::depthStencil = NULL;
|
||||
|
||||
::D3D_DRIVER_TYPE driverType = ::D3D_DRIVER_TYPE_HARDWARE;
|
||||
D3D11_VIEWPORT* Core::viewPort = NULL;
|
||||
|
||||
if(Reference)
|
||||
driverType = D3D_DRIVER_TYPE_REFERENCE;
|
||||
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
Log << "DirectX running in debug mode.\n";
|
||||
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
||||
|
||||
D3D_FEATURE_LEVEL featureLevelsToTry[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0
|
||||
};
|
||||
D3D_FEATURE_LEVEL initiatedFeatureLevel;
|
||||
|
||||
if( FAILED( ::D3D11CreateDevice( NULL, // default adapter
|
||||
driverType,
|
||||
NULL, // no software device
|
||||
createDeviceFlags,
|
||||
featureLevelsToTry, 3, // default feature level array. DX11 support assumed
|
||||
D3D11_SDK_VERSION,
|
||||
&Device, // device
|
||||
&initiatedFeatureLevel,
|
||||
&DeviceContext ) ) ) // context
|
||||
{ // if failed
|
||||
if( DeviceContext ) { DeviceContext->Release(); DeviceContext = NULL; } // safe cleanup
|
||||
if( Device ) { Device->Release(); Device = NULL; } // safe cleanup
|
||||
}
|
||||
|
||||
if( driverType == ::D3D_DRIVER_TYPE_HARDWARE )
|
||||
Log << "D3D_DRIVER_TYPE_HARDWARE support discovered.\n";
|
||||
else
|
||||
Log << "D3D_DRIVER_TYPE_REFERENCE support discovered.\n";
|
||||
|
||||
if( initiatedFeatureLevel == ::D3D_FEATURE_LEVEL_11_0 )
|
||||
{
|
||||
Log << "DirectX Featurelevel 11.0 supported.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ForceDX11)
|
||||
return false;
|
||||
if( initiatedFeatureLevel == ::D3D_FEATURE_LEVEL_10_1 )
|
||||
{
|
||||
Log << "DirectX Featurelevel 10.1 supported.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if( initiatedFeatureLevel == ::D3D_FEATURE_LEVEL_10_0 )
|
||||
{
|
||||
Log << "DirectX Featurelevel 10.0 supported.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Device)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Core::CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen)
|
||||
{
|
||||
//generate static Swapchain Desc
|
||||
DXGI_SWAP_CHAIN_DESC desc;
|
||||
desc.OutputWindow=Window;
|
||||
desc.BufferCount=NrofBuffers;
|
||||
desc.Windowed=!Fullscreen;
|
||||
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS;
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
desc.Flags=0;
|
||||
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
||||
desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
|
||||
desc.BufferDesc.RefreshRate.Denominator=1;
|
||||
desc.BufferDesc.RefreshRate.Numerator=60;
|
||||
|
||||
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)
|
||||
{
|
||||
if(FAILED(Device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM,4,&desc.SampleDesc.Quality)))
|
||||
{
|
||||
Log<< "Failed to check multisample quality levels (MSAAQuality).\n";
|
||||
return false;
|
||||
}
|
||||
desc.SampleDesc.Count=4;
|
||||
--desc.SampleDesc.Quality;
|
||||
Log << "Supported multisample quality levels (MSAAQuality): " << desc.SampleDesc.Quality+1 << "x\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.SampleDesc.Count=1;
|
||||
desc.SampleDesc.Quality=0;
|
||||
}
|
||||
|
||||
//Get Device Factory
|
||||
::IDXGIDevice *dxgiDevice = NULL;
|
||||
if( FAILED( Device->QueryInterface( __uuidof( IDXGIDevice ), (void**)&dxgiDevice ) ) )
|
||||
{
|
||||
Log << "Failed to Query for the GPU's dxgiDevice.\nFailed to create swapChain for the GPU.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
::IDXGIAdapter *dxgiAdapter = NULL;
|
||||
if( FAILED( dxgiDevice->GetParent( __uuidof( IDXGIAdapter ), (void**)&dxgiAdapter ) ) )
|
||||
{
|
||||
dxgiDevice->Release();
|
||||
Log << "Failed to get GPU's parent dxgiAdapter.\nFailed to create swapChain for the GPU.\n";
|
||||
return false;
|
||||
}
|
||||
dxgiDevice->Release();
|
||||
|
||||
::IDXGIFactory *dxgiFactory = NULL;
|
||||
if( FAILED( dxgiAdapter->GetParent( __uuidof( IDXGIFactory ), (void**)&dxgiFactory ) ) )
|
||||
{
|
||||
dxgiAdapter->Release();
|
||||
Log << "Failed to get GPU's parent dxgiFactory.\nFailed to create swapChain for the GPU.\n";
|
||||
return false;
|
||||
}
|
||||
dxgiAdapter->Release();
|
||||
|
||||
//Create SwapChain
|
||||
if( FAILED( dxgiFactory->CreateSwapChain( Device, &desc, &SwapChain ) ) )
|
||||
{
|
||||
dxgiFactory->Release();
|
||||
Log << "Failed to create swapChain for the GPU.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
dxgiFactory->Release();
|
||||
|
||||
return true;
|
||||
}
|
||||
Oyster::Math::Float2 Core::resolution = Oyster::Math::Float2::null;
|
|
@ -7,108 +7,146 @@
|
|||
#include "CoreIncludes.h"
|
||||
#include <sstream>
|
||||
#include "Buffer.h"
|
||||
#include "OysterMath.h";
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
class Core
|
||||
namespace Graphics
|
||||
{
|
||||
public:
|
||||
|
||||
static ID3D11Device* Device;
|
||||
|
||||
static ID3D11DeviceContext* DeviceContext;
|
||||
|
||||
static IDXGISwapChain* SwapChain;
|
||||
|
||||
static std::stringstream* AccesLog();
|
||||
|
||||
static bool Init(bool SingleThreaded,bool Reference,bool ForceDX11);
|
||||
|
||||
static bool CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen);
|
||||
|
||||
class ShaderManager
|
||||
class Core
|
||||
{
|
||||
public:
|
||||
struct ShaderEffect
|
||||
|
||||
static ID3D11Device* device;
|
||||
|
||||
static ID3D11DeviceContext* deviceContext;
|
||||
|
||||
static IDXGISwapChain* swapChain;
|
||||
|
||||
static std::stringstream log;
|
||||
|
||||
//BackBufferRTV
|
||||
static ID3D11RenderTargetView* backBufferRTV;
|
||||
//BackBufferUAV
|
||||
static ID3D11UnorderedAccessView* backBufferUAV;
|
||||
//DepthStencil
|
||||
static ID3D11DepthStencilView* depthStencil;
|
||||
//ViewPort
|
||||
static D3D11_VIEWPORT* viewPort;
|
||||
|
||||
static Oyster::Math::Float2 resolution;
|
||||
|
||||
|
||||
class ShaderManager
|
||||
{
|
||||
struct
|
||||
public:
|
||||
struct ShaderEffect
|
||||
{
|
||||
int Pixel,Vertex,Geometry,Compute,Hull,Domain;
|
||||
}Shaders;
|
||||
struct
|
||||
{
|
||||
int Pixel,Vertex,Geometry,Compute,Hull,Domain;
|
||||
}Shaders;
|
||||
|
||||
struct IAStage_
|
||||
{
|
||||
ID3D11InputLayout* Layout;
|
||||
D3D11_PRIMITIVE_TOPOLOGY Topology;
|
||||
}IAStage;
|
||||
struct IAStage_
|
||||
{
|
||||
ID3D11InputLayout* Layout;
|
||||
D3D11_PRIMITIVE_TOPOLOGY Topology;
|
||||
}IAStage;
|
||||
|
||||
struct RenderStates_
|
||||
{
|
||||
ID3D11DepthStencilState *DepthStencil;
|
||||
ID3D11RasterizerState *Rasterizer;
|
||||
ID3D11SamplerState **SampleState;
|
||||
int SampleCount;
|
||||
ID3D11BlendState *BlendState;
|
||||
}RenderStates;
|
||||
struct RenderStates_
|
||||
{
|
||||
ID3D11DepthStencilState *DepthStencil;
|
||||
ID3D11RasterizerState *Rasterizer;
|
||||
ID3D11SamplerState **SampleState;
|
||||
int SampleCount;
|
||||
ID3D11BlendState *BlendState;
|
||||
}RenderStates;
|
||||
|
||||
struct
|
||||
{
|
||||
std::vector<Oyster::Buffer*> Vertex;
|
||||
std::vector<Oyster::Buffer*> Geometry;
|
||||
std::vector<Oyster::Buffer*> Pixel;
|
||||
}CBuffers;
|
||||
struct
|
||||
{
|
||||
std::vector<Buffer*> Vertex;
|
||||
std::vector<Buffer*> Geometry;
|
||||
std::vector<Buffer*> Pixel;
|
||||
}CBuffers;
|
||||
|
||||
ShaderEffect()
|
||||
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
|
||||
{
|
||||
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
|
||||
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);
|
||||
};
|
||||
};
|
||||
|
||||
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
|
||||
//Set resulotion Before Calling Full Init
|
||||
class Init
|
||||
{
|
||||
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);
|
||||
};
|
||||
public:
|
||||
enum State
|
||||
{
|
||||
Sucsess,
|
||||
Fail
|
||||
};
|
||||
|
||||
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);
|
||||
static State CreateDeviceAndDeviceContext(bool SingleThreaded = true, bool Reference = false, bool ForceDX11 = true);
|
||||
|
||||
static State CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen, Oyster::Math::Float2 Size);
|
||||
|
||||
static State CreateDepthStencil(bool MSAA_Quality, Oyster::Math::Float2 Size);
|
||||
|
||||
static State CreateBackBufferViews();
|
||||
|
||||
static State CreateViewPort(Oyster::Math::Float2 Origin, Oyster::Math::Float2 Size);
|
||||
|
||||
static State FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen);
|
||||
|
||||
static State ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen);
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// http://lolengine.net/blog/2011/3/4/fuck-you-microsoft-near-far-macros
|
||||
#include <windows.h>
|
||||
#include <D3D11.h>
|
||||
#include <d3dCompiler.h>
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
#pragma comment(lib, "d3d11.lib")
|
||||
#pragma comment(lib, "d3dcompiler.lib")
|
||||
|
|
|
@ -0,0 +1,337 @@
|
|||
#include "Core.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
Core::Init::State Core::Init::CreateDeviceAndDeviceContext(bool SingleThreaded,bool Reference,bool ForceDX11)
|
||||
{
|
||||
UINT createDeviceFlags = 0;
|
||||
|
||||
if(Core::deviceContext)
|
||||
{
|
||||
Core::deviceContext->Release();
|
||||
delete Core::deviceContext;
|
||||
}
|
||||
if(Core::device)
|
||||
{
|
||||
Core::device->Release();
|
||||
delete Core::device;
|
||||
}
|
||||
|
||||
|
||||
if( SingleThreaded )
|
||||
createDeviceFlags = ::D3D11_CREATE_DEVICE_SINGLETHREADED;
|
||||
|
||||
::D3D_DRIVER_TYPE driverType = ::D3D_DRIVER_TYPE_HARDWARE;
|
||||
|
||||
if(Reference)
|
||||
driverType = D3D_DRIVER_TYPE_REFERENCE;
|
||||
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
log << "DirectX running in debug mode.\n";
|
||||
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
||||
|
||||
D3D_FEATURE_LEVEL featureLevelsToTry[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0
|
||||
};
|
||||
D3D_FEATURE_LEVEL initiatedFeatureLevel;
|
||||
|
||||
if( FAILED( ::D3D11CreateDevice( NULL, // default adapter
|
||||
driverType,
|
||||
NULL, // no software device
|
||||
createDeviceFlags,
|
||||
featureLevelsToTry, 3, // default feature level array. DX11 support assumed
|
||||
D3D11_SDK_VERSION,
|
||||
&Core::device, // device
|
||||
&initiatedFeatureLevel,
|
||||
&Core::deviceContext ) ) ) // context
|
||||
{ // if failed
|
||||
if( Core::deviceContext ) { Core::deviceContext->Release(); Core::deviceContext = NULL; } // safe cleanup
|
||||
if( Core::device ) { Core::device->Release(); Core::device = NULL; } // safe cleanup
|
||||
}
|
||||
|
||||
if( driverType == ::D3D_DRIVER_TYPE_HARDWARE )
|
||||
log << "D3D_DRIVER_TYPE_HARDWARE support discovered.\n";
|
||||
else
|
||||
log << "D3D_DRIVER_TYPE_REFERENCE support discovered.\n";
|
||||
|
||||
if( initiatedFeatureLevel == ::D3D_FEATURE_LEVEL_11_0 )
|
||||
{
|
||||
log << "DirectX Featurelevel 11.0 supported.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ForceDX11)
|
||||
return Init::Fail;
|
||||
if( initiatedFeatureLevel == ::D3D_FEATURE_LEVEL_10_1 )
|
||||
{
|
||||
log << "DirectX Featurelevel 10.1 supported.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if( initiatedFeatureLevel == ::D3D_FEATURE_LEVEL_10_0 )
|
||||
{
|
||||
log << "DirectX Featurelevel 10.0 supported.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Core::device)
|
||||
return Init::Sucsess;
|
||||
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
Core::Init::State Core::Init::CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen, Oyster::Math::Float2 Size)
|
||||
{
|
||||
//generate static Swapchain Desc
|
||||
DXGI_SWAP_CHAIN_DESC desc;
|
||||
desc.OutputWindow=Window;
|
||||
desc.BufferCount=NrofBuffers;
|
||||
desc.Windowed=!Fullscreen;
|
||||
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS;
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
desc.Flags=0;
|
||||
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
||||
desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
|
||||
desc.BufferDesc.RefreshRate.Denominator=1;
|
||||
desc.BufferDesc.RefreshRate.Numerator=60;
|
||||
|
||||
desc.BufferDesc.Height = Size.y;
|
||||
desc.BufferDesc.Width = Size.x;
|
||||
|
||||
if(Core::swapChain)
|
||||
{
|
||||
Core::swapChain->Release();
|
||||
delete Core::swapChain;
|
||||
}
|
||||
|
||||
|
||||
//Check and Set multiSampling
|
||||
if(MSAA_Quality)
|
||||
{
|
||||
if(FAILED(Core::device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM,4,&desc.SampleDesc.Quality)))
|
||||
{
|
||||
log<< "Failed to check multisample quality levels (MSAAQuality).\n";
|
||||
return Init::Fail;
|
||||
}
|
||||
desc.SampleDesc.Count=4;
|
||||
--desc.SampleDesc.Quality;
|
||||
log << "Supported multisample quality levels (MSAAQuality): " << desc.SampleDesc.Quality+1 << "x\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.SampleDesc.Count=1;
|
||||
desc.SampleDesc.Quality=0;
|
||||
}
|
||||
|
||||
//Get Device Factory
|
||||
::IDXGIDevice *dxgiDevice = NULL;
|
||||
if( FAILED( Core::device->QueryInterface( __uuidof( IDXGIDevice ), (void**)&dxgiDevice ) ) )
|
||||
{
|
||||
log << "Failed to Query for the GPU's dxgiDevice.\nFailed to create swapChain for the GPU.\n";
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
::IDXGIAdapter *dxgiAdapter = NULL;
|
||||
if( FAILED( dxgiDevice->GetParent( __uuidof( IDXGIAdapter ), (void**)&dxgiAdapter ) ) )
|
||||
{
|
||||
dxgiDevice->Release();
|
||||
log << "Failed to get GPU's parent dxgiAdapter.\nFailed to create swapChain for the GPU.\n";
|
||||
return Init::Fail;
|
||||
}
|
||||
dxgiDevice->Release();
|
||||
|
||||
::IDXGIFactory *dxgiFactory = NULL;
|
||||
if( FAILED( dxgiAdapter->GetParent( __uuidof( IDXGIFactory ), (void**)&dxgiFactory ) ) )
|
||||
{
|
||||
dxgiAdapter->Release();
|
||||
log << "Failed to get GPU's parent dxgiFactory.\nFailed to create swapChain for the GPU.\n";
|
||||
return Init::Fail;
|
||||
}
|
||||
dxgiAdapter->Release();
|
||||
|
||||
//Create SwapChain
|
||||
if( FAILED( dxgiFactory->CreateSwapChain( Core::device, &desc, &Core::swapChain ) ) )
|
||||
{
|
||||
dxgiFactory->Release();
|
||||
log << "Failed to create swapChain for the GPU.\n";
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
dxgiFactory->Release();
|
||||
|
||||
return Init::Sucsess;
|
||||
}
|
||||
|
||||
Core::Init::State Core::Init::CreateDepthStencil(bool MSAA_Quality, Oyster::Math::Float2 Size)
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.MipLevels=1;
|
||||
desc.ArraySize=1;
|
||||
desc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
desc.CPUAccessFlags=0;
|
||||
desc.MiscFlags=0;
|
||||
desc.Height = Size.y;
|
||||
desc.Width = Size.x;
|
||||
|
||||
if(Core::depthStencil)
|
||||
{
|
||||
Core::depthStencil->Release();
|
||||
delete Core::depthStencil;
|
||||
}
|
||||
|
||||
//Check and Set multiSampling
|
||||
if(MSAA_Quality)
|
||||
{
|
||||
if(FAILED(Core::device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM,4,&desc.SampleDesc.Quality)))
|
||||
{
|
||||
log<< "Failed to check multisample quality levels (MSAAQuality).\n";
|
||||
return Init::Fail;
|
||||
}
|
||||
desc.SampleDesc.Count=4;
|
||||
--desc.SampleDesc.Quality;
|
||||
log << "Supported multisample quality levels (MSAAQuality): " << desc.SampleDesc.Quality+1 << "x\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
desc.SampleDesc.Count=1;
|
||||
desc.SampleDesc.Quality=0;
|
||||
}
|
||||
|
||||
ID3D11Texture2D* depthstencil;
|
||||
|
||||
if(FAILED(Core::device->CreateTexture2D(&desc,0,&depthstencil)))
|
||||
return Init::Fail;
|
||||
if(FAILED(Core::device->CreateDepthStencilView(depthstencil,0,&Core::depthStencil)))
|
||||
{
|
||||
depthstencil->Release();
|
||||
return Init::Fail;
|
||||
}
|
||||
depthstencil->Release();
|
||||
|
||||
return Init::Sucsess;
|
||||
}
|
||||
|
||||
Core::Init::State Core::Init::CreateBackBufferViews()
|
||||
{
|
||||
D3D11_UNORDERED_ACCESS_VIEW_DESC descView;
|
||||
ZeroMemory( &descView, sizeof(descView) );
|
||||
descView.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
|
||||
descView.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
descView.Texture2D.MipSlice=0;
|
||||
|
||||
ID3D11Texture2D* backBuffer;
|
||||
if(FAILED(Core::swapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),reinterpret_cast<void**>(&backBuffer))))
|
||||
{
|
||||
log << "Failed to get BackBuffer from Swapchain";
|
||||
return Init::Fail;
|
||||
}
|
||||
if(Core::backBufferRTV)
|
||||
{
|
||||
Core::backBufferRTV->Release();
|
||||
delete Core::backBufferRTV;
|
||||
}
|
||||
if(FAILED(Core::device->CreateRenderTargetView(backBuffer,0,&Core::backBufferRTV)))
|
||||
{
|
||||
log << "Failed to create RTV for BackBuffer";
|
||||
backBuffer->Release();
|
||||
return Init::Fail;
|
||||
}
|
||||
if(Core::backBufferUAV)
|
||||
{
|
||||
Core::backBufferUAV->Release();
|
||||
delete Core::backBufferUAV;
|
||||
}
|
||||
if(FAILED(Core::device->CreateUnorderedAccessView(backBuffer,0,&Core::backBufferUAV)))
|
||||
{
|
||||
log << "Failed to create UAV for BackBuffer";
|
||||
backBuffer->Release();
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
backBuffer->Release();
|
||||
|
||||
return Init::Sucsess;
|
||||
}
|
||||
|
||||
Core::Init::State Core::Init::CreateViewPort(Oyster::Math::Float2 Origin, Oyster::Math::Float2 Size)
|
||||
{
|
||||
if(Core::viewPort)
|
||||
delete Core::viewPort;
|
||||
Core::viewPort = new D3D11_VIEWPORT;
|
||||
|
||||
Core::viewPort->TopLeftX = Origin.x;
|
||||
Core::viewPort->TopLeftY = Origin.y;
|
||||
Core::viewPort->Width = Size.x;
|
||||
Core::viewPort->Height = Size.y;
|
||||
Core::viewPort->MinDepth = 0.0f;
|
||||
Core::viewPort->MaxDepth = 1.0f;
|
||||
|
||||
return Init::Sucsess;
|
||||
}
|
||||
|
||||
Core::Init::State Core::Init::FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen)
|
||||
{
|
||||
if(Init::CreateDeviceAndDeviceContext() == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateSwapChain(Window, 1, MSAA_Quality, Fullscreen, Core::resolution) == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateDepthStencil(MSAA_Quality, Core::resolution) == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateBackBufferViews() == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateViewPort(Oyster::Math::Float2::null, Core::resolution) == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
return Init::Sucsess;
|
||||
}
|
||||
|
||||
Core::Init::State Core::Init::ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen)
|
||||
{
|
||||
if(Init::CreateSwapChain(Window, 1, MSAA_Quality, Fullscreen, Core::resolution) == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateDepthStencil(MSAA_Quality, Core::resolution) == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateBackBufferViews() == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
if(Init::CreateViewPort(Oyster::Math::Float2::null, Core::resolution) == Init::Fail)
|
||||
{
|
||||
return Init::Fail;
|
||||
}
|
||||
|
||||
return Init::Sucsess;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,345 +5,346 @@ const char* ShaderFunction = "main";
|
|||
|
||||
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
|
||||
namespace Graphics
|
||||
{
|
||||
struct ShaderData
|
||||
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
|
||||
{
|
||||
size_t size;
|
||||
char* data;
|
||||
};
|
||||
std::vector<ID3D11PixelShader*> PS;
|
||||
std::map<std::wstring,int> PSMap;
|
||||
struct ShaderData
|
||||
{
|
||||
size_t size;
|
||||
char* data;
|
||||
};
|
||||
std::vector<ID3D11PixelShader*> PS;
|
||||
std::map<std::wstring,int> PSMap;
|
||||
|
||||
std::vector<ID3D11GeometryShader*> GS;
|
||||
std::map<std::wstring,int> GSMap;
|
||||
std::vector<ID3D11GeometryShader*> GS;
|
||||
std::map<std::wstring,int> GSMap;
|
||||
|
||||
std::vector<ID3D11ComputeShader*> CS;
|
||||
std::map<std::wstring,int> CSMap;
|
||||
std::vector<ID3D11ComputeShader*> CS;
|
||||
std::map<std::wstring,int> CSMap;
|
||||
|
||||
std::vector<ID3D11VertexShader*> VS;
|
||||
std::vector<ShaderData> VData;
|
||||
std::map<std::wstring,int> 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);
|
||||
std::vector<ID3D11VertexShader*> VS;
|
||||
std::vector<ShaderData> VData;
|
||||
std::map<std::wstring,int> VSMap;
|
||||
}
|
||||
else
|
||||
|
||||
#pragma region Init
|
||||
bool Core::ShaderManager::Init(std::wstring filename, ShaderType type, std::wstring name, bool Precompiled)
|
||||
{
|
||||
return LoadCompile(filename, type, name);
|
||||
if(Precompiled)
|
||||
{
|
||||
return LoadPrecompiled(filename, type, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return LoadCompile(filename, type, name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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())
|
||||
bool LoadPrecompiled(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name)
|
||||
{
|
||||
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();
|
||||
|
||||
std::ifstream stream;
|
||||
ShaderData sd;
|
||||
|
||||
|
||||
ID3D11VertexShader* vertex;
|
||||
ID3D11GeometryShader* geometry;
|
||||
ID3D11PixelShader* pixel;
|
||||
ID3D11ComputeShader* compute;
|
||||
//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::Vertex:
|
||||
case Core::ShaderManager::ShaderType::Pixel:
|
||||
|
||||
if(VSMap.count(name))
|
||||
return false;
|
||||
ID3D11PixelShader* pixel;
|
||||
|
||||
if(FAILED(Core::Device->CreateVertexShader(sd.data, sd.size, 0, &vertex)))
|
||||
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;
|
||||
}
|
||||
VSMap[name] = VS.size();
|
||||
VS.push_back(vertex);
|
||||
VData.push_back(sd);
|
||||
if(FAILED(Core::device->CreatePixelShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&pixel)))
|
||||
{
|
||||
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::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)))
|
||||
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;
|
||||
}
|
||||
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)))
|
||||
if(FAILED(Core::device->CreateGeometryShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&geometry)))
|
||||
{
|
||||
Shader->Release();
|
||||
return false;
|
||||
}
|
||||
PSMap[name] = PS.size();
|
||||
PS.push_back(pixel);
|
||||
Shader->Release();
|
||||
if(!GSMap.count(name))
|
||||
{
|
||||
GSMap[name] = GS.size();
|
||||
GS.push_back(geometry);
|
||||
}
|
||||
else
|
||||
{
|
||||
GS[GSMap[name]] = geometry;
|
||||
}
|
||||
break;
|
||||
|
||||
case Core::ShaderManager::ShaderType::Compute:
|
||||
case Core::ShaderManager::ShaderType::Vertex:
|
||||
|
||||
if(CSMap.count(name))
|
||||
return false;
|
||||
if(FAILED(Core::Device->CreateComputeShader(sd.data, sd.size, 0, &compute)))
|
||||
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;
|
||||
}
|
||||
CSMap[name] = CS.size();
|
||||
CS.push_back(compute);
|
||||
if(FAILED(Core::device->CreateVertexShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&vertex)))
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
#pragma endregion
|
||||
|
||||
void Core::ShaderManager::CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout)
|
||||
{
|
||||
return false;
|
||||
if(VertexIndex==-1)
|
||||
{
|
||||
Layout=0;
|
||||
return;
|
||||
}
|
||||
Core::device->CreateInputLayout(desc,ElementCount,VData[VertexIndex].data,VData[VertexIndex].size,&Layout);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadCompile(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name)
|
||||
{
|
||||
/// \todo error reporting
|
||||
ID3D10Blob *Shader,*Error;
|
||||
switch(type)
|
||||
#pragma region Get
|
||||
int Core::ShaderManager::Get::Pixel(std::wstring Name)
|
||||
{
|
||||
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)))
|
||||
{
|
||||
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)))
|
||||
{
|
||||
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;
|
||||
|
||||
if(PSMap.count(Name))
|
||||
return PSMap[Name];
|
||||
return -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
void Core::ShaderManager::CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout)
|
||||
{
|
||||
if(VertexIndex==-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)
|
||||
Core::deviceContext->PSSetShader( NULL,NULL,0);
|
||||
else
|
||||
Core::deviceContext->PSSetShader( PS[Index],NULL,0);
|
||||
}
|
||||
void Core::ShaderManager::Set::Vertex(int Index)
|
||||
{
|
||||
if(Index==-1)
|
||||
Core::deviceContext->VSSetShader( NULL,NULL,0);
|
||||
else
|
||||
Core::deviceContext->VSSetShader( VS[Index],NULL,0);
|
||||
}
|
||||
void Core::ShaderManager::Set::Geometry(int Index)
|
||||
{
|
||||
if(Index==-1)
|
||||
Core::deviceContext->GSSetShader( NULL,NULL,0);
|
||||
else
|
||||
Core::deviceContext->GSSetShader( GS[Index],NULL,0);
|
||||
}
|
||||
void Core::ShaderManager::Set::Compute(int Index)
|
||||
{
|
||||
if(Index==-1)
|
||||
Core::deviceContext->CSSetShader( NULL,NULL,0);
|
||||
else
|
||||
Core::deviceContext->CSSetShader( CS[Index],NULL,0);
|
||||
}
|
||||
/// \todo set Hull
|
||||
void Core::ShaderManager::Set::Hull(int Index)
|
||||
{
|
||||
Layout=0;
|
||||
return;
|
||||
}
|
||||
Device->CreateInputLayout(desc,ElementCount,VData[VertexIndex].data,VData[VertexIndex].size,&Layout);
|
||||
}
|
||||
/// \todo set Domain
|
||||
void Core::ShaderManager::Set::Domain(int Index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Get
|
||||
int Core::ShaderManager::Get::Pixel(std::wstring Name)
|
||||
{
|
||||
if(PSMap.count(Name))
|
||||
return PSMap[Name];
|
||||
return -1;
|
||||
/// \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);
|
||||
Core::deviceContext->IASetInputLayout(se.IAStage.Layout);
|
||||
Core::deviceContext->IASetPrimitiveTopology(se.IAStage.Topology);
|
||||
for(unsigned int i=0;i<se.CBuffers.Vertex.size();++i)
|
||||
se.CBuffers.Vertex[i]->Apply(i);
|
||||
for(unsigned int i=0;i<se.CBuffers.Geometry.size();++i)
|
||||
se.CBuffers.Geometry[i]->Apply(i);
|
||||
for(unsigned int i=0;i<se.CBuffers.Pixel.size();++i)
|
||||
se.CBuffers.Pixel[i]->Apply(i);
|
||||
Core::deviceContext->RSSetState(se.RenderStates.Rasterizer);
|
||||
Core::deviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState);
|
||||
float test[4] = {0};
|
||||
Core::deviceContext->OMSetBlendState(se.RenderStates.BlendState,test,-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;i<se.CBuffers.Vertex.size();++i)
|
||||
se.CBuffers.Vertex[i]->Apply(i);
|
||||
for(unsigned int i=0;i<se.CBuffers.Geometry.size();++i)
|
||||
se.CBuffers.Geometry[i]->Apply(i);
|
||||
for(unsigned int i=0;i<se.CBuffers.Pixel.size();++i)
|
||||
se.CBuffers.Pixel[i]->Apply(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);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,157 +9,160 @@
|
|||
|
||||
namespace Oyster
|
||||
{
|
||||
class Engine
|
||||
namespace Graphics
|
||||
{
|
||||
private:
|
||||
Engine();
|
||||
~Engine();
|
||||
|
||||
public:
|
||||
class Init
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
struct Setup
|
||||
{
|
||||
int NrOfBuffers;
|
||||
bool MSAA_Quality;
|
||||
bool Fullscreen;
|
||||
bool SingleThreaded;
|
||||
bool Reference;
|
||||
bool ForceDX11;
|
||||
bool GenerateDepthStencil;
|
||||
bool BindDefault;
|
||||
HWND window;
|
||||
//all but Window params have Default Values
|
||||
Setup()
|
||||
{
|
||||
NrOfBuffers=1;
|
||||
MSAA_Quality = false;
|
||||
Fullscreen = true;
|
||||
SingleThreaded = true;
|
||||
Reference = false;
|
||||
ForceDX11 = false;
|
||||
GenerateDepthStencil = true;
|
||||
BindDefault = true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static bool IsInstanced();
|
||||
|
||||
//Creates Device and DeviceContext, if not Initialized
|
||||
static bool Instance(bool SingleThreaded=true,bool Reference=false,bool ForceDX11=false);
|
||||
static bool HasSwapChain();
|
||||
|
||||
//Creates Swapchain, if not Aready Created
|
||||
static bool CreateSwapChain(HWND Window, int NrofBuffers=1,bool MSAA_Quality=false,bool Fullscreen=true);
|
||||
|
||||
//CreateWindow, if Not Already Created
|
||||
static bool InitializeWindow(const LPCSTR appName, const LPCSTR className,const HINSTANCE &hInstance, const int &nCmdShow, WNDPROC wProc, bool HandleLoop = false );
|
||||
|
||||
//Performs a full initialization of a rendering pipeline, including a Window
|
||||
static bool FullInit(const Setup& setup);
|
||||
struct Buffers
|
||||
{
|
||||
static Buffer* CreateBuffer(const Buffer::BUFFER_INIT_DESC BufferDesc);
|
||||
};
|
||||
private:
|
||||
Init();
|
||||
~Init();
|
||||
};
|
||||
Engine();
|
||||
~Engine();
|
||||
|
||||
class States
|
||||
{
|
||||
public:
|
||||
//SSAO Quality
|
||||
static void SetNrOfSSAOSamples(int);
|
||||
static int GetNrOfSSAOSamples();
|
||||
|
||||
//SSAO Frequency
|
||||
static void SetSSAOSampleSpread(int);
|
||||
static int GetSSAOSampleSpread();
|
||||
|
||||
//PointLights
|
||||
static void SetMaxPointlights(int);
|
||||
static int GetMaxPointlights();
|
||||
|
||||
|
||||
private:
|
||||
States();
|
||||
~States();
|
||||
};
|
||||
|
||||
class Render
|
||||
{
|
||||
public:
|
||||
/// Render a number of models, setting the Per model data to the included cBuffer
|
||||
/// specify NULL if no such data exists
|
||||
static void Geometry(const Oyster::Render::Model* models,int count,Oyster::Buffer* cBufferEveryObject, int slot);
|
||||
static void Text(std::string text, Oyster::Math::Float2 size, Oyster::Math::Float3 Pos);
|
||||
//static void TextBox(const Oyster::Render::
|
||||
|
||||
//ensure that a compatible 2D shadereffect is applied
|
||||
static void ScreenQuad(ID3D11ShaderResourceView* srv, float ZPos=1);
|
||||
|
||||
//ensure that a compatible 2D shadereffect is applied and that pos.z is between 0 and 1
|
||||
static void Sprite(ID3D11ShaderResourceView* srv, Oyster::Math::Float2 size, Oyster::Math::Float3 Pos);
|
||||
|
||||
static void PresentScene();
|
||||
|
||||
private:
|
||||
Render();
|
||||
~Render();
|
||||
};
|
||||
|
||||
class PrepareForRendering
|
||||
{
|
||||
public:
|
||||
//Binds several rendertargets and a depthstencil
|
||||
static void BindRenderTargets(ID3D11RenderTargetView** RenderTargets,int NrOfTargets,ID3D11DepthStencilView* depth);
|
||||
|
||||
//Binds several Rendertargest and a default depthstencil
|
||||
static void BindRenderTargets(ID3D11RenderTargetView** RenderTargets,int NrOfTargets);
|
||||
|
||||
//Binds the backbuffer and a depthstencil
|
||||
static void BindBackBuffer(ID3D11DepthStencilView* depth);
|
||||
|
||||
//Binds the backbuffer and a default depthstencil
|
||||
static void BindBackBuffer();
|
||||
|
||||
//Binds the backbuffer to the compute shader
|
||||
static void BindBackBufferAsUAV();
|
||||
|
||||
//binds several UAV to the computeshader
|
||||
static void BindUAV(ID3D11UnorderedAccessView** uav, int NrOfUavs);
|
||||
|
||||
//Clears the backbuffer and default depthstencil
|
||||
static void ClearBackBuffer(Math::Float4 color);
|
||||
|
||||
static void Begin2DRender();
|
||||
|
||||
static void Begin2DTextRender();
|
||||
};
|
||||
|
||||
class Pipeline
|
||||
{
|
||||
public:
|
||||
class Deffered_Lightning
|
||||
/*class Init
|
||||
{
|
||||
public:
|
||||
//Basic Setup
|
||||
static void NewFrame(const Float4& Color, const Matrix& View, const Matrix& Projection);
|
||||
struct Setup
|
||||
{
|
||||
int NrOfBuffers;
|
||||
bool MSAA_Quality;
|
||||
bool Fullscreen;
|
||||
bool SingleThreaded;
|
||||
bool Reference;
|
||||
bool ForceDX11;
|
||||
bool GenerateDepthStencil;
|
||||
bool BindDefault;
|
||||
HWND window;
|
||||
//all but Window params have Default Values
|
||||
Setup()
|
||||
{
|
||||
NrOfBuffers=1;
|
||||
MSAA_Quality = false;
|
||||
Fullscreen = true;
|
||||
SingleThreaded = true;
|
||||
Reference = false;
|
||||
ForceDX11 = false;
|
||||
GenerateDepthStencil = true;
|
||||
BindDefault = true;
|
||||
}
|
||||
|
||||
//Geometry Pass
|
||||
static void BeginRenderGeometry();
|
||||
static void RenderGeometry(const Oyster::Render::Model* models,int count);
|
||||
static void EndRenderGeometry();
|
||||
};
|
||||
|
||||
//Lightning Pass
|
||||
static void InputPointLights(Oyster::Resources::BufferDefinitions::PointLightDescription *p, int NrOfPointlights );
|
||||
static void RenderLightning();
|
||||
static bool IsInstanced();
|
||||
|
||||
//Creates Device and DeviceContext, if not Initialized
|
||||
static bool Instance(bool SingleThreaded=true,bool Reference=false,bool ForceDX11=false);
|
||||
static bool HasSwapChain();
|
||||
|
||||
//Creates Swapchain, if not Aready Created
|
||||
static bool CreateSwapChain(HWND Window, int NrofBuffers=1,bool MSAA_Quality=false,bool Fullscreen=true);
|
||||
|
||||
//CreateWindow, if Not Already Created
|
||||
static bool InitializeWindow(const LPCSTR appName, const LPCSTR className,const HINSTANCE &hInstance, const int &nCmdShow, WNDPROC wProc, bool HandleLoop = false );
|
||||
|
||||
//Performs a full initialization of a rendering pipeline, including a Window
|
||||
static bool FullInit(const Setup& setup);
|
||||
struct Buffers
|
||||
{
|
||||
static Buffer* CreateBuffer(const Buffer::BUFFER_INIT_DESC BufferDesc);
|
||||
};
|
||||
private:
|
||||
Init();
|
||||
~Init();
|
||||
};*/
|
||||
|
||||
class States
|
||||
{
|
||||
public:
|
||||
//SSAO Quality
|
||||
static void SetNrOfSSAOSamples(int);
|
||||
static int GetNrOfSSAOSamples();
|
||||
|
||||
//SSAO Frequency
|
||||
static void SetSSAOSampleSpread(int);
|
||||
static int GetSSAOSampleSpread();
|
||||
|
||||
//PointLights
|
||||
static void SetMaxPointlights(int);
|
||||
static int GetMaxPointlights();
|
||||
|
||||
|
||||
private:
|
||||
States();
|
||||
~States();
|
||||
};
|
||||
|
||||
class Render
|
||||
{
|
||||
public:
|
||||
/// Render a number of models, setting the Per model data to the included cBuffer
|
||||
/// specify NULL if no such data exists
|
||||
//static void Geometry(const Oyster::Graphics::Render::Model* models,int count,Buffer* cBufferEveryObject, int slot);
|
||||
static void Text(std::string text, Oyster::Math::Float2 size, Oyster::Math::Float3 Pos);
|
||||
//static void TextBox(const Oyster::Render::
|
||||
|
||||
//ensure that a compatible 2D shadereffect is applied
|
||||
static void ScreenQuad(ID3D11ShaderResourceView* srv, float ZPos=1);
|
||||
|
||||
//ensure that a compatible 2D shadereffect is applied and that pos.z is between 0 and 1
|
||||
static void Sprite(ID3D11ShaderResourceView* srv, Oyster::Math::Float2 size, Oyster::Math::Float3 Pos);
|
||||
|
||||
static void PresentScene();
|
||||
|
||||
private:
|
||||
Render();
|
||||
~Render();
|
||||
};
|
||||
|
||||
class PrepareForRendering
|
||||
{
|
||||
public:
|
||||
//Binds several rendertargets and a depthstencil
|
||||
static void BindRenderTargets(ID3D11RenderTargetView** RenderTargets,int NrOfTargets,ID3D11DepthStencilView* depth);
|
||||
|
||||
//Binds several Rendertargest and a default depthstencil
|
||||
static void BindRenderTargets(ID3D11RenderTargetView** RenderTargets,int NrOfTargets);
|
||||
|
||||
//Binds the backbuffer and a depthstencil
|
||||
static void BindBackBuffer(ID3D11DepthStencilView* depth);
|
||||
|
||||
//Binds the backbuffer and a default depthstencil
|
||||
static void BindBackBuffer();
|
||||
|
||||
//Binds the backbuffer to the compute shader
|
||||
static void BindBackBufferAsUAV();
|
||||
|
||||
//binds several UAV to the computeshader
|
||||
static void BindUAV(ID3D11UnorderedAccessView** uav, int NrOfUavs);
|
||||
|
||||
//Clears the backbuffer and default depthstencil
|
||||
static void ClearBackBuffer(Math::Float4 color);
|
||||
|
||||
static void Begin2DRender();
|
||||
|
||||
static void Begin2DTextRender();
|
||||
};
|
||||
|
||||
class Pipeline
|
||||
{
|
||||
public:
|
||||
class Deffered_Lightning
|
||||
{
|
||||
public:
|
||||
//Basic Setup
|
||||
//static void NewFrame(const Float4& Color, const Matrix& View, const Matrix& Projection);
|
||||
|
||||
//Geometry Pass
|
||||
static void BeginRenderGeometry();
|
||||
//static void RenderGeometry(const Oyster::Graphics::Render::Model* models,int count);
|
||||
static void EndRenderGeometry();
|
||||
|
||||
//Lightning Pass
|
||||
//static void InputPointLights(Oyster::Resources::BufferDefinitions::PointLightDescription *p, int NrOfPointlights );
|
||||
static void RenderLightning();
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,9 +1,9 @@
|
|||
//Oyster
|
||||
|
||||
// Render
|
||||
#include "Render\Model.h"
|
||||
#include "Render\Camera.h"
|
||||
#include "Render\TextBox.h"
|
||||
//#include "Render\Model.h"
|
||||
//#include "Render\Camera.h"
|
||||
//#include "Render\TextBox.h"
|
||||
|
||||
// Core
|
||||
#include "Core\Core.h"
|
||||
|
@ -16,8 +16,8 @@
|
|||
#include "OysterMath.h"
|
||||
|
||||
// Resources
|
||||
#include "Resourses\ShaderEffects.h"
|
||||
#include "Resourses\Buffers.h"
|
||||
#include "Resourses\PipelineResources.h"
|
||||
#include "Resourses\GraphicsDefinitions.h"
|
||||
#include "Resourses\Manager.h"
|
||||
//#include "Resourses\ShaderEffects.h"
|
||||
//#include "Resourses\Buffers.h"
|
||||
//#include "Resourses\PipelineResources.h"
|
||||
//#include "Resourses\GraphicsDefinitions.h"
|
||||
//#include "Resourses\Manager.h"
|
|
@ -1,268 +1,122 @@
|
|||
#include "ObjReader.h"
|
||||
#include "Utilities.h"
|
||||
#include "..\Core\Core.h"
|
||||
#include "OBJReader.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
using namespace Oyster::FileLoaders;
|
||||
using namespace Oyster;
|
||||
using namespace Oyster::Math;
|
||||
|
||||
ObjReader *ObjReader::LoadFile(std::string fileName, Oyster::Math::Float4x4 transform)
|
||||
OBJReader::OBJReader()
|
||||
{
|
||||
static std::map<std::string, ObjReader *> cache;
|
||||
|
||||
ObjReader *reader = NULL;
|
||||
|
||||
if (cache.count(fileName))
|
||||
{
|
||||
reader = cache[fileName];
|
||||
}
|
||||
else
|
||||
{
|
||||
reader = new ObjReader();
|
||||
reader->ParseFile(fileName, transform);
|
||||
|
||||
cache[fileName] = reader;
|
||||
}
|
||||
|
||||
return reader;
|
||||
_mPos = 0;
|
||||
_mNormal = 0;
|
||||
_mTexel = 0;
|
||||
}
|
||||
|
||||
ObjReader::ObjReader(void)
|
||||
OBJReader::~OBJReader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
ObjReader::~ObjReader(void)
|
||||
void OBJReader::readOBJFile( wstring fileName )
|
||||
{
|
||||
}
|
||||
fstream inStream;
|
||||
string typeOfData = " ";
|
||||
float vertexData;
|
||||
string face1, face2, face3;
|
||||
|
||||
void ObjReader::ParseFile(std::string fileName, Float4x4 transform)
|
||||
{
|
||||
ifstream input;
|
||||
input.open(fileName.c_str());
|
||||
inStream.open( fileName, fstream::in );
|
||||
|
||||
if(!input.is_open())
|
||||
if( inStream.is_open() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string path;
|
||||
Utility::String::extractDirPath(path,fileName,'\\');
|
||||
|
||||
std::vector<Vertex> VertexList;
|
||||
std::vector<Float3> vList;
|
||||
std::vector<Float3> nList;
|
||||
std::vector<Float2> uvList;
|
||||
Vertex vertex1, vertex2, vertex3;
|
||||
Float3 face[3];
|
||||
Float3 position, normal;
|
||||
Float2 uv;
|
||||
string s;
|
||||
|
||||
while(!input.eof())
|
||||
{
|
||||
getline(input,s);
|
||||
int offset = (int)s.find(' ');
|
||||
|
||||
if(offset!=-1)
|
||||
while( !inStream.eof() )
|
||||
{
|
||||
string c = s.substr(0,offset);
|
||||
inStream >> typeOfData;
|
||||
|
||||
if(c=="v")
|
||||
if( typeOfData == "v" )
|
||||
{
|
||||
position = readVertex(offset,s);
|
||||
vList.push_back(position);
|
||||
Oyster::Math::Float3 position;
|
||||
|
||||
inStream >> vertexData;
|
||||
position.x = vertexData;
|
||||
|
||||
inStream >> vertexData;
|
||||
position.y = vertexData;
|
||||
|
||||
inStream >> vertexData;
|
||||
position.z = vertexData;
|
||||
|
||||
_mVertexCoord.push_back( position );
|
||||
|
||||
}
|
||||
else if(c=="vt")
|
||||
else if( typeOfData == "vt" )
|
||||
{
|
||||
uv = readUV(offset,s);
|
||||
uvList.push_back(uv);
|
||||
Oyster::Math::Float2 texel;
|
||||
inStream >> vertexData;
|
||||
texel.x = vertexData;
|
||||
|
||||
inStream >> vertexData;
|
||||
texel.y = 1 - vertexData;
|
||||
|
||||
_mVertexTexture.push_back( texel );
|
||||
}
|
||||
else if(c=="vn")
|
||||
else if( typeOfData == "vn" )
|
||||
{
|
||||
normal = readNormal(offset,s);
|
||||
nList.push_back(normal);
|
||||
Oyster::Math::Float3 normal;
|
||||
inStream >> vertexData;
|
||||
normal.x = vertexData;
|
||||
|
||||
inStream >> vertexData;
|
||||
normal.y = vertexData;
|
||||
|
||||
inStream >> vertexData;
|
||||
normal.z = vertexData;
|
||||
|
||||
_mVertexNormal.push_back( normal );
|
||||
}
|
||||
else if(c=="f")
|
||||
else if( typeOfData == "f" )
|
||||
{
|
||||
readFace(offset, s, face);
|
||||
inStream >> face1;
|
||||
stringSplit( face1 );
|
||||
|
||||
vertex1.Position = vList[(int)face[0].x];
|
||||
vertex1.UV = uvList[(int)face[0].y];
|
||||
vertex1.Normal = nList[(int)face[0].z];
|
||||
addToOBJarray();
|
||||
|
||||
vertex2.Position = vList[(int)face[1].x];
|
||||
vertex2.UV = uvList[(int)face[1].y];
|
||||
vertex2.Normal = nList[(int)face[1].z];
|
||||
inStream >> face2;
|
||||
stringSplit( face2 );
|
||||
|
||||
vertex3.Position = vList[(int)face[2].x];
|
||||
vertex3.UV = uvList[(int)face[2].y];
|
||||
vertex3.Normal = nList[(int)face[2].z];
|
||||
addToOBJarray();
|
||||
|
||||
VertexList.push_back(vertex1);
|
||||
VertexList.push_back(vertex3);
|
||||
VertexList.push_back(vertex2);
|
||||
}
|
||||
else if(c=="mtllib")
|
||||
{
|
||||
this->materials = GetMaterials(path+s.substr(offset+1));
|
||||
inStream >> face3;
|
||||
stringSplit( face3 );
|
||||
|
||||
addToOBJarray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input.close();
|
||||
|
||||
this->numVertices = VertexList.size();
|
||||
this->vertices = new Vertex[this->numVertices];
|
||||
|
||||
for(size_t i=0;i<this->numVertices;++i)
|
||||
{
|
||||
vertices[i].Position=Math::transformVector(Math::Float4(VertexList[i].Position,1),transform);
|
||||
vertices[i].Normal=Math::transformVector(Math::Float4(VertexList[i].Normal,0),transform);
|
||||
vertices[i].UV = VertexList[i].UV;
|
||||
}
|
||||
inStream.close();
|
||||
}
|
||||
|
||||
void ObjReader::GetVertexData(Vertex **vertex,int &numVertex, std::map<std::string, ID3D11ShaderResourceView *> &Textures)
|
||||
//Private functions
|
||||
void OBJReader::stringSplit( string strToSplit )
|
||||
{
|
||||
numVertex=(int)this->numVertices;
|
||||
(*vertex)=this->vertices;
|
||||
Textures = this->materials;
|
||||
char delim = '/';
|
||||
string vPos, vNormal, vTexel;
|
||||
stringstream aStream(strToSplit);
|
||||
getline( aStream, vPos, delim );
|
||||
getline( aStream, vTexel, delim );
|
||||
getline( aStream, vNormal );
|
||||
|
||||
_mPos = atoi( vPos.c_str() );
|
||||
_mNormal = atoi( vNormal.c_str() );
|
||||
_mTexel = atoi( vTexel.c_str() );
|
||||
|
||||
}
|
||||
|
||||
Float3 ObjReader::extract(std::string d)
|
||||
void OBJReader::addToOBJarray()
|
||||
{
|
||||
Float3 data;
|
||||
int offset=(int)d.find('/');
|
||||
data.x=(float)atoi(d.substr(1,offset).c_str())-1;
|
||||
OBJFormat temp;
|
||||
|
||||
int newOffset = (int)d.find('/',offset+1);
|
||||
string d2=d.substr(offset+1,newOffset-offset-1);
|
||||
data.y=(float)atoi(d2.c_str())-1;
|
||||
offset=newOffset;
|
||||
temp._d3VertexCoord = _mVertexCoord.at( _mPos - 1 );
|
||||
temp._d3VertexNormal = _mVertexNormal.at( _mNormal - 1 );
|
||||
temp._d3VertexTexture = _mVertexTexture.at( _mTexel - 1 );
|
||||
|
||||
newOffset = (int)d.find('/',offset+1);
|
||||
string d3=d.substr(offset+1,newOffset-offset-1);
|
||||
data.z=(float)atoi(d3.c_str())-1;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Float3 ObjReader::readVertex(int offset,string s)
|
||||
{
|
||||
int newOffset = (int)s.find(' ',offset+1);
|
||||
Float3 vertex;
|
||||
string d = s.substr(offset,newOffset-offset);
|
||||
vertex.x = (float)atof(d.c_str());
|
||||
offset=newOffset;
|
||||
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
vertex.y = (float)atof(s.substr(offset,newOffset-offset).c_str());
|
||||
offset=newOffset;
|
||||
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
vertex.z = (float)-atof(s.substr(offset,newOffset-offset).c_str());
|
||||
|
||||
return vertex;
|
||||
}
|
||||
|
||||
Float2 ObjReader::readUV(int offset,string s)
|
||||
{
|
||||
int newOffset = (int)s.find(' ',offset+1);
|
||||
Float2 uv;
|
||||
string d = s.substr(offset,newOffset-offset);
|
||||
uv.x =(float)atof(d.c_str());
|
||||
offset=newOffset;
|
||||
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
d = s.substr(offset,newOffset-offset);
|
||||
uv.y =1- (float)atof(d.c_str());
|
||||
offset=newOffset;
|
||||
|
||||
return uv;
|
||||
}
|
||||
|
||||
Float3 ObjReader::readNormal(int offset,string s)
|
||||
{
|
||||
int newOffset = (int)s.find(' ',offset+1);
|
||||
Float3 vertex;
|
||||
string d = s.substr(offset,newOffset-offset);
|
||||
vertex.x = (float)atof(d.c_str());
|
||||
offset=newOffset;
|
||||
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
vertex.y = (float)atof(s.substr(offset,newOffset-offset).c_str());
|
||||
offset=newOffset;
|
||||
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
vertex.z = (float)-atof(s.substr(offset,newOffset-offset).c_str());
|
||||
|
||||
return vertex;
|
||||
}
|
||||
|
||||
void ObjReader::readFace(int offset,string s, Oyster::Math::Float3 face[3])
|
||||
{
|
||||
int newOffset = (int)s.find(' ',offset+1);
|
||||
string point1 = s.substr(offset,newOffset-offset);
|
||||
|
||||
offset = newOffset;
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
string point2 = s.substr(offset,newOffset-offset);
|
||||
|
||||
offset = newOffset;
|
||||
newOffset = (int)s.find(' ',offset+1);
|
||||
string point3 = s.substr(offset,newOffset-offset);
|
||||
|
||||
face[0] = extract(point1);
|
||||
face[1] = extract(point2);
|
||||
face[2] = extract(point3);
|
||||
}
|
||||
|
||||
std::map<std::string, ID3D11ShaderResourceView *> ObjReader::GetMaterials(std::string fileName)
|
||||
{
|
||||
ifstream input;
|
||||
input.open(fileName.c_str());
|
||||
|
||||
std::map<std::string, ID3D11ShaderResourceView *> materials;
|
||||
ID3D11ShaderResourceView *srv;
|
||||
string texture;
|
||||
string s;
|
||||
string path;
|
||||
Utility::String::extractDirPath(path,fileName,'\\');
|
||||
if(!input.is_open())
|
||||
return materials;
|
||||
|
||||
while(!input.eof())
|
||||
{
|
||||
getline(input,s);
|
||||
int offset = (int)s.find(' ');
|
||||
if(offset!=-1)
|
||||
{
|
||||
string c = s.substr(0,offset);
|
||||
if(c=="map_Kd")
|
||||
{
|
||||
texture = path+s.substr(offset+1);
|
||||
D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
|
||||
materials["Diffuse"] = srv;
|
||||
}
|
||||
if(c=="map_G")
|
||||
{
|
||||
texture = path+s.substr(offset+1);
|
||||
D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
|
||||
materials["Glow"] = srv;
|
||||
}
|
||||
if(c=="map_Ks")
|
||||
{
|
||||
texture = path+s.substr(offset+1);
|
||||
D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
|
||||
materials["Specular"] = srv;
|
||||
}
|
||||
}
|
||||
}
|
||||
input.close();
|
||||
|
||||
return materials;
|
||||
_myOBJ.push_back( temp );
|
||||
}
|
|
@ -1,42 +1,53 @@
|
|||
#pragma once
|
||||
#include "..\Core\CoreIncludes.h"
|
||||
#include "..\Math\OysterMath.h"
|
||||
#ifndef OBJREADER_H
|
||||
#define OBJREADER_H
|
||||
#include "..\..\Misc\Utilities.h"
|
||||
#include "..\..\OysterMath\OysterMath.h"
|
||||
|
||||
namespace Oyster
|
||||
//#include <fstream>
|
||||
|
||||
|
||||
|
||||
class OBJReader
|
||||
{
|
||||
namespace FileLoaders
|
||||
{
|
||||
class ObjReader
|
||||
public:
|
||||
struct OBJFormat
|
||||
{
|
||||
public:
|
||||
struct Vertex
|
||||
{
|
||||
Oyster::Math::Float3 Position;
|
||||
Oyster::Math::Float3 Normal;
|
||||
Oyster::Math::Float2 UV;
|
||||
};
|
||||
|
||||
static ObjReader *LoadFile(std::string fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
|
||||
|
||||
ObjReader(void);
|
||||
~ObjReader(void);
|
||||
|
||||
void GetVertexData(Vertex **vertex,int &numVertex, std::map<std::string, ID3D11ShaderResourceView *> &textures);
|
||||
|
||||
private:
|
||||
Vertex *vertices;
|
||||
size_t numVertices;
|
||||
std::map<std::string, ID3D11ShaderResourceView *> materials;
|
||||
|
||||
void ParseFile(std::string fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
|
||||
|
||||
Oyster::Math::Float3 extract(std::string d);
|
||||
Oyster::Math::Float3 readVertex(int offset,std::string s);
|
||||
Oyster::Math::Float2 readUV(int offset,std::string s);
|
||||
Oyster::Math::Float3 readNormal(int offset,std::string s);
|
||||
void readFace(int offset,std::string s, Oyster::Math::Float3 face[3]);
|
||||
|
||||
std::map<std::string, ID3D11ShaderResourceView *> GetMaterials(std::string fileName);
|
||||
Oyster::Math::Float3 _d3VertexCoord;
|
||||
Oyster::Math::Float2 _d3VertexTexture;
|
||||
Oyster::Math::Float3 _d3VertexNormal;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
struct OBJMaterialData
|
||||
{
|
||||
string _name;
|
||||
string _mapKd;
|
||||
float _kd[3];
|
||||
float _ka[3];
|
||||
float _tf[3];
|
||||
float _ni;
|
||||
|
||||
OBJMaterialData()
|
||||
{
|
||||
_name = " ";
|
||||
_mapKd = " ";
|
||||
}
|
||||
};
|
||||
std::vector<OBJFormat> _myOBJ;
|
||||
private:
|
||||
|
||||
vector<Oyster::Math::Float3> _mVertexCoord, _mVertexNormal;
|
||||
vector<Oyster::Math::Float2> _mVertexTexture;
|
||||
|
||||
int _mNrOfCoords, _mNrOfNormals, _mNrOfTexels, _mNrOfFaces;
|
||||
int _mPos, _mNormal, _mTexel;
|
||||
void stringSplit( string strToSplit );
|
||||
void addToOBJarray();
|
||||
|
||||
public:
|
||||
OBJReader();
|
||||
~OBJReader();
|
||||
|
||||
void readOBJFile( wstring fileName);
|
||||
|
||||
};
|
||||
#endif
|
|
@ -15,16 +15,17 @@ using namespace Oyster::Math;
|
|||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Render
|
||||
namespace Graphics
|
||||
{
|
||||
|
||||
struct Model
|
||||
namespace Render
|
||||
{
|
||||
ModelInfo* info;
|
||||
Float4x4 *World;
|
||||
bool Visible;
|
||||
};
|
||||
|
||||
struct Model
|
||||
{
|
||||
ModelInfo* info;
|
||||
Float4x4 *World;
|
||||
bool Visible;
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
};
|
|
@ -14,16 +14,19 @@ using namespace Oyster::Math;
|
|||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Render
|
||||
namespace Graphics
|
||||
{
|
||||
struct ModelInfo
|
||||
namespace Render
|
||||
{
|
||||
std::vector<ID3D11ShaderResourceView*> Material;
|
||||
Oyster::Buffer Vertices,Indecies;
|
||||
bool Indexed;
|
||||
int VertexCount;
|
||||
};
|
||||
};
|
||||
struct ModelInfo
|
||||
{
|
||||
std::vector<ID3D11ShaderResourceView*> Material;
|
||||
Buffer Vertices,Indecies;
|
||||
bool Indexed;
|
||||
int VertexCount;
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,70 @@
|
|||
#pragma once
|
||||
|
||||
#include "..\Engine.h"
|
||||
const int MAX_LETTER_COUNT=60;
|
||||
const int TEXT_NR_LETTERS=95;
|
||||
const float TEXT_SIZE=2.5;
|
||||
struct Text2D
|
||||
{
|
||||
Oyster::Math::Float Pos;
|
||||
int offset;
|
||||
float coff;
|
||||
};
|
||||
/*struct TextInstanceData
|
||||
{
|
||||
Oyster::Buffer InstanceBuffer;
|
||||
bool Visible;
|
||||
int NumLetters;
|
||||
Oyster::Math::Float4x4 World;
|
||||
};*/
|
||||
/*struct TextData
|
||||
{
|
||||
Oyster::Math::Float3 pos;
|
||||
Oyster::Math::Float2 uv;
|
||||
};
|
||||
|
||||
struct PerCharData
|
||||
{
|
||||
float data;
|
||||
Oyster::Math::Float3 charOffset;
|
||||
};
|
||||
struct TextInstanceData
|
||||
{
|
||||
Oyster::Buffer InstanceBuffer;
|
||||
bool Visible;
|
||||
int NumLetters;
|
||||
Oyster::Math::Float4x4 World;
|
||||
};*/
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
class Textbox
|
||||
{
|
||||
private:
|
||||
static float getCharID(char _in);
|
||||
static HRESULT CreateVertexBuffer();
|
||||
static HRESULT CreateTextfield(int _id);
|
||||
public:
|
||||
//static Oyster::Buffer TextBuffer;
|
||||
//static int NumVertices;
|
||||
//static std::vector<TextInstanceData> TextInstances;
|
||||
static Buffer TextBuffer;
|
||||
static int NumLetters;
|
||||
static ID3D11ShaderResourceView* Texture;
|
||||
|
||||
static bool Init();
|
||||
static bool UpdateTextField(std::string _str);
|
||||
static bool SetTexture(const char* _file);
|
||||
//Updates a textbox with the certain id
|
||||
static void Update(std::string _str, float _scale);
|
||||
//Removes all old instances and recreates it with the input data
|
||||
static HRESULT Reset(int _count, std::string* _str, Float3* _pos);
|
||||
static void Apply(int _id);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,11 +90,14 @@
|
|||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)OysterMath;$(SolutionDir)Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<ProjectReference>
|
||||
<LinkLibraryDependencies>true</LinkLibraryDependencies>
|
||||
</ProjectReference>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
|
@ -140,31 +143,22 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="Core\Buffer.cpp" />
|
||||
<ClCompile Include="Core\Core.cpp" />
|
||||
<ClCompile Include="Core\Init.cpp" />
|
||||
<ClCompile Include="Core\ShaderManager.cpp" />
|
||||
<ClCompile Include="Engine.cpp" />
|
||||
<ClCompile Include="Render\Model.cpp" />
|
||||
<ClCompile Include="Render\TextBox.cpp" />
|
||||
<ClCompile Include="Resourses\Buffers.cpp" />
|
||||
<ClCompile Include="Resourses\Manager.cpp" />
|
||||
<ClCompile Include="Resourses\PipelineResources.cpp" />
|
||||
<ClCompile Include="Resourses\ShaderEffects.cpp" />
|
||||
<ClCompile Include="Render\Preparations\Basic.cpp" />
|
||||
<ClCompile Include="Render\Rendering\Basic.cpp" />
|
||||
<ClCompile Include="Resources\Resources.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Core\Buffer.h" />
|
||||
<ClInclude Include="Core\Core.h" />
|
||||
<ClInclude Include="Core\CoreIncludes.h" />
|
||||
<ClInclude Include="Engine.h" />
|
||||
<ClInclude Include="EngineIncludes.h" />
|
||||
<ClInclude Include="FileLoader\ObjReader.h" />
|
||||
<ClInclude Include="Render\Lights.h" />
|
||||
<ClInclude Include="Render\Model.h" />
|
||||
<ClInclude Include="Render\ModelInfo.h" />
|
||||
<ClInclude Include="Render\TextBox.h" />
|
||||
<ClInclude Include="Resourses\Buffers.h" />
|
||||
<ClInclude Include="Resourses\GraphicsDefinitions.h" />
|
||||
<ClInclude Include="Resourses\Manager.h" />
|
||||
<ClInclude Include="Resourses\PipelineResources.h" />
|
||||
<ClInclude Include="Resourses\ShaderEffects.h" />
|
||||
<ClInclude Include="Model\Model.h" />
|
||||
<ClInclude Include="Model\ModelInfo.h" />
|
||||
<ClInclude Include="Render\Preparations\Preparations.h" />
|
||||
<ClInclude Include="Render\Rendering\Render.h" />
|
||||
<ClInclude Include="Resources\Resources.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Misc\Misc.vcxproj">
|
||||
|
@ -175,6 +169,12 @@
|
|||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugCameraVertex.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugPixel.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
|
||||
|
@ -192,6 +192,8 @@
|
|||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
|
||||
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">main</EntryPointName>
|
||||
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
</AssemblerOutput>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -21,30 +21,21 @@
|
|||
<ClCompile Include="Core\Core.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render\Model.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render\TextBox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\Buffers.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\Manager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\PipelineResources.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\ShaderEffects.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Engine.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Core\ShaderManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Core\Init.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render\Preparations\Basic.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render\Rendering\Basic.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resources\Resources.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Core\Buffer.h">
|
||||
|
@ -56,45 +47,28 @@
|
|||
<ClInclude Include="Core\CoreIncludes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\Lights.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\Model.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\ModelInfo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\TextBox.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\Buffers.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\GraphicsDefinitions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\Manager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\PipelineResources.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\ShaderEffects.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Engine.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EngineIncludes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FileLoader\ObjReader.h">
|
||||
<ClInclude Include="Render\Preparations\Preparations.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\Rendering\Render.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Model\ModelInfo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Model\Model.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resources\Resources.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugVertex.hlsl" />
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugPixel.hlsl" />
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugCameraVertex.hlsl" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,84 @@
|
|||
#include "Preparations.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
namespace Preparations
|
||||
{
|
||||
void Basic::BindBackBufferRTV(bool DepthStencil)
|
||||
{
|
||||
if(DepthStencil)
|
||||
{
|
||||
Core::deviceContext->OMSetRenderTargets(1,&Core::backBufferRTV,Core::depthStencil);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::deviceContext->OMSetRenderTargets(1,&Core::backBufferRTV,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void Basic::BindBackBufferRTV(ID3D11DepthStencilView& depthStencil)
|
||||
{
|
||||
Core::deviceContext->OMSetRenderTargets(1,&Core::backBufferRTV,&depthStencil);
|
||||
}
|
||||
|
||||
void Basic::BindBackBufferUAV()
|
||||
{
|
||||
Core::deviceContext->CSSetUnorderedAccessViews(0,1,&Core::backBufferUAV,0);
|
||||
}
|
||||
|
||||
void Basic::BindRTV(ID3D11RenderTargetView* RTVs[], int size, bool UseDepthStencil)
|
||||
{
|
||||
if(UseDepthStencil)
|
||||
{
|
||||
BindRTV(RTVs, size, Core::depthStencil);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core::deviceContext->OMSetRenderTargets(size,RTVs,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void Basic::BindRTV(ID3D11RenderTargetView* RTVs[], int size,ID3D11DepthStencilView& depthStencil)
|
||||
{
|
||||
Core::deviceContext->OMSetRenderTargets(size,RTVs,&depthStencil);
|
||||
}
|
||||
|
||||
void Basic::BindUAV(ID3D11UnorderedAccessView* UAVs[], int size)
|
||||
{
|
||||
Core::deviceContext->CSSetUnorderedAccessViews(0,size,UAVs,0);
|
||||
}
|
||||
|
||||
void Basic::ClearBackBuffer(Oyster::Math::Float4 Color, bool ClearDefaultDepthStencil)
|
||||
{
|
||||
Core::deviceContext->ClearRenderTargetView(Core::backBufferRTV,Color);
|
||||
if(ClearDefaultDepthStencil)
|
||||
{
|
||||
Core::deviceContext->ClearDepthStencilView(Core::depthStencil,1,1,0);
|
||||
}
|
||||
}
|
||||
|
||||
void Basic::ClearRTV(ID3D11RenderTargetView* RTVs[], int size,Oyster::Math::Float4 Color)
|
||||
{
|
||||
for(int i = 0; i < size; ++i)
|
||||
{
|
||||
Core::deviceContext->ClearRenderTargetView(RTVs[i],Color);
|
||||
}
|
||||
}
|
||||
|
||||
void Basic::ClearDepthStencil(ID3D11DepthStencilView &depthStencil)
|
||||
{
|
||||
Core::deviceContext->ClearDepthStencilView(&depthStencil,1,1,0);
|
||||
}
|
||||
|
||||
void Basic::SetViewPort()
|
||||
{
|
||||
Core::deviceContext->RSSetViewports(1,Core::viewPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include "..\..\Core\Core.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
namespace Preparations
|
||||
{
|
||||
static class Basic
|
||||
{
|
||||
public:
|
||||
/** @brief Binds the backbuffer as a RenderTargetView with the specified DepthStencil*/
|
||||
static void BindBackBufferRTV(ID3D11DepthStencilView& depthStencil);
|
||||
/** @brief Binds the backbuffer as a RenderTargetView with or without the default DepthStencil*/
|
||||
static void BindBackBufferRTV(bool UseDefaultDepthStencil = true);
|
||||
|
||||
|
||||
/** @brief Binds the backbuffer as a UnorderedAccessView*/
|
||||
static void BindBackBufferUAV();
|
||||
|
||||
/** @brief Binds the specified RenderTargetViews with or without the default DepthStencil*/
|
||||
static void BindRTV(ID3D11RenderTargetView* RTVs[], int size, bool UseDepthStencil = true);
|
||||
/** @brief Binds the specified RenderTargetViews with the specified DepthStencil*/
|
||||
static void BindRTV(ID3D11RenderTargetView* RTVs[], int size,ID3D11DepthStencilView& depthStencil);
|
||||
|
||||
/** @brief Binds the specified UnorderedAccessViews*/
|
||||
static void BindUAV(ID3D11UnorderedAccessView* UAVs[], int size);
|
||||
|
||||
/** @brief Clear the BackBuffer and if true the default DepthStencil*/
|
||||
static void ClearBackBuffer(Oyster::Math::Float4 Color, bool ClearDefaultDepthStencil = true);
|
||||
|
||||
/** @brief Clear the specified RenderTargetViews*/
|
||||
static void ClearRTV(ID3D11RenderTargetView* RTVs[], int size,Oyster::Math::Float4 Color);
|
||||
/** @brief Clear the specified DepthStencil*/
|
||||
static void ClearDepthStencil(ID3D11DepthStencilView &depthStencil);
|
||||
|
||||
/** @brief Binds the default ViewPort*/
|
||||
static void SetViewPort();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#include "Render.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
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));
|
||||
}
|
||||
void Basic::RenderScene(Model* models, int count)
|
||||
{
|
||||
}
|
||||
void Basic::EndFrame()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "..\..\Core\Core.h"
|
||||
#include "..\Preparations\Preparations.h"
|
||||
#include "..\..\Model\Model.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
namespace Rendering
|
||||
{
|
||||
static 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);
|
||||
static void EndFrame();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "..\Engine.h"
|
||||
const int MAX_LETTER_COUNT=60;
|
||||
const int TEXT_NR_LETTERS=95;
|
||||
const float TEXT_SIZE=2.5;
|
||||
struct Text2D
|
||||
{
|
||||
Oyster::Math::Float Pos;
|
||||
int offset;
|
||||
float coff;
|
||||
};
|
||||
/*struct TextInstanceData
|
||||
{
|
||||
Oyster::Buffer InstanceBuffer;
|
||||
bool Visible;
|
||||
int NumLetters;
|
||||
Oyster::Math::Float4x4 World;
|
||||
};*/
|
||||
/*struct TextData
|
||||
{
|
||||
Oyster::Math::Float3 pos;
|
||||
Oyster::Math::Float2 uv;
|
||||
};
|
||||
|
||||
struct PerCharData
|
||||
{
|
||||
float data;
|
||||
Oyster::Math::Float3 charOffset;
|
||||
};
|
||||
struct TextInstanceData
|
||||
{
|
||||
Oyster::Buffer InstanceBuffer;
|
||||
bool Visible;
|
||||
int NumLetters;
|
||||
Oyster::Math::Float4x4 World;
|
||||
};*/
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
class Textbox
|
||||
{
|
||||
private:
|
||||
static float getCharID(char _in);
|
||||
static HRESULT CreateVertexBuffer();
|
||||
static HRESULT CreateTextfield(int _id);
|
||||
public:
|
||||
//static Oyster::Buffer TextBuffer;
|
||||
//static int NumVertices;
|
||||
//static std::vector<TextInstanceData> TextInstances;
|
||||
static Oyster::Buffer TextBuffer;
|
||||
static int NumLetters;
|
||||
static ID3D11ShaderResourceView* Texture;
|
||||
|
||||
static bool Init();
|
||||
static bool UpdateTextField(std::string _str);
|
||||
static bool SetTexture(const char* _file);
|
||||
//Updates a textbox with the certain id
|
||||
static void Update(std::string _str, float _scale);
|
||||
//Removes all old instances and recreates it with the input data
|
||||
static HRESULT Reset(int _count, std::string* _str, Float3* _pos);
|
||||
static void Apply(int _id);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#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 Create Shader Effects
|
||||
/** @todo Create ShaderEffects */
|
||||
#pragma endregion
|
||||
return Core::Init::Sucsess;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "..\Core\Core.h"
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
static class Resources
|
||||
{
|
||||
const Core::ShaderManager::ShaderEffect basic;
|
||||
const Buffer ModelData;
|
||||
|
||||
Core::Init::State Init();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
cbuffer PerFrame : register(b0)
|
||||
{
|
||||
matrix View;
|
||||
float4x4 Projection;
|
||||
}
|
||||
|
||||
cbuffer PerModel : register(b1)
|
||||
{
|
||||
matrix World;
|
||||
}
|
||||
|
||||
float4 main( float4 pos : POSITION ) : SV_POSITION
|
||||
{
|
||||
matrix VP = mul(View, Projection);
|
||||
matrix WVP = mul(World, VP);
|
||||
return mul(WVP, pos);
|
||||
}
|
|
@ -4,75 +4,78 @@
|
|||
|
||||
namespace Oyster
|
||||
{
|
||||
class Shader
|
||||
namespace Graphics
|
||||
{
|
||||
public:
|
||||
struct ShaderEffect
|
||||
class Shader
|
||||
{
|
||||
struct
|
||||
public:
|
||||
struct ShaderEffect
|
||||
{
|
||||
int Pixel,Vertex,Geometry,Compute,Hull,Domain;
|
||||
}Shaders;
|
||||
struct IAStage_
|
||||
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<Buffer*> Vertex;
|
||||
std::vector<Buffer*> Geometry;
|
||||
std::vector<Buffer*> 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;
|
||||
}
|
||||
};
|
||||
static bool InitShaders(const std::string &name = "..\\Shaders\\ShaderConfig.txt");
|
||||
|
||||
static void SetShaderEffect(ShaderEffect);
|
||||
|
||||
static void CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout);
|
||||
|
||||
struct Set
|
||||
{
|
||||
ID3D11InputLayout* Layout;
|
||||
D3D11_PRIMITIVE_TOPOLOGY Topology;
|
||||
}IAStage;
|
||||
struct RenderStates_
|
||||
static void SetPixel(int Index);
|
||||
static void SetVertex(int Index);
|
||||
static void SetGeometry(int Index);
|
||||
static void SetCompute(int Index);
|
||||
static void SetHull(int Index);
|
||||
static void SetDomain(int Index);
|
||||
};
|
||||
|
||||
struct Get
|
||||
{
|
||||
ID3D11DepthStencilState *DepthStencil;
|
||||
ID3D11RasterizerState *Rasterizer;
|
||||
ID3D11SamplerState **SampleState;
|
||||
int SampleCount;
|
||||
ID3D11BlendState *BlendState;
|
||||
}RenderStates;
|
||||
struct
|
||||
{
|
||||
std::vector<Buffer*> Vertex;
|
||||
std::vector<Buffer*> Geometry;
|
||||
std::vector<Buffer*> 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;
|
||||
}
|
||||
static int GetPixel(std::string Name);
|
||||
static int GetVertex(std::string Name);
|
||||
static int GetGeometry(std::string Name);
|
||||
static int GetCompute(std::string Name);
|
||||
static int GetHull(std::string Name);
|
||||
static int GetDomain(std::string Name);
|
||||
};
|
||||
|
||||
static std::stringstream* AccesLog();
|
||||
};
|
||||
static bool InitShaders(const std::string &name = "..\\Shaders\\ShaderConfig.txt");
|
||||
|
||||
static void SetShaderEffect(ShaderEffect);
|
||||
|
||||
static void CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout);
|
||||
|
||||
struct Set
|
||||
{
|
||||
static void SetPixel(int Index);
|
||||
static void SetVertex(int Index);
|
||||
static void SetGeometry(int Index);
|
||||
static void SetCompute(int Index);
|
||||
static void SetHull(int Index);
|
||||
static void SetDomain(int Index);
|
||||
};
|
||||
|
||||
struct Get
|
||||
{
|
||||
static int GetPixel(std::string Name);
|
||||
static int GetVertex(std::string Name);
|
||||
static int GetGeometry(std::string Name);
|
||||
static int GetCompute(std::string Name);
|
||||
static int GetHull(std::string Name);
|
||||
static int GetDomain(std::string Name);
|
||||
};
|
||||
|
||||
static std::stringstream* AccesLog();
|
||||
};
|
||||
}
|
||||
}
|
|
@ -7,7 +7,8 @@
|
|||
//--------------------------------------------------------------------------------------
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include "Engine.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Render\Preparations\Preparations.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Global Variables
|
||||
|
@ -131,22 +132,21 @@ HRESULT InitDirect3D()
|
|||
{
|
||||
HRESULT hr = S_OK;;
|
||||
|
||||
Oyster::Engine::Init::Setup setup;
|
||||
setup.Fullscreen = false;
|
||||
setup.ForceDX11 = true;
|
||||
setup.SingleThreaded = true;
|
||||
setup.window = g_hWnd;
|
||||
Oyster::Graphics::Core::resolution = Oyster::Math::Float2( 1024, 768 );
|
||||
|
||||
if(Oyster::Graphics::Core::Init::FullInit(g_hWnd,false,false)==Oyster::Graphics::Core::Init::Fail)
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
Oyster::Engine::Init::FullInit( setup );
|
||||
|
||||
std::wstring ShaderPath = L"..\\OysterGraphics\\Shader\\HLSL\\";
|
||||
std::wstring EffectPath = L"SimpleDebug\\";
|
||||
|
||||
Oyster::Core::ShaderManager::Init(ShaderPath + EffectPath + L"DebugPixel.hlsl",Oyster::Core::ShaderManager::ShaderType::Pixel,L"Debug",false);
|
||||
Oyster::Core::ShaderManager::Init(ShaderPath + EffectPath + L"DebugVertex.hlsl",Oyster::Core::ShaderManager::ShaderType::Vertex,L"Debug",false);
|
||||
Oyster::Graphics::Core::ShaderManager::Init(ShaderPath + EffectPath + L"DebugPixel.hlsl",Oyster::Graphics::Core::ShaderManager::ShaderType::Pixel,L"Debug",false);
|
||||
Oyster::Graphics::Core::ShaderManager::Init(ShaderPath + EffectPath + L"DebugVertex.hlsl",Oyster::Graphics::Core::ShaderManager::ShaderType::Vertex,L"PassThroughFloat4",false);
|
||||
|
||||
Oyster::Core::ShaderManager::Set::Vertex(Oyster::Core::ShaderManager::Get::Vertex(L"Debug"));
|
||||
Oyster::Core::ShaderManager::Set::Pixel(Oyster::Core::ShaderManager::Get::Pixel(L"Debug"));
|
||||
Oyster::Graphics::Core::ShaderManager::Set::Vertex(Oyster::Graphics::Core::ShaderManager::Get::Vertex(L"PassThroughFloat4"));
|
||||
Oyster::Graphics::Core::ShaderManager::Set::Pixel(Oyster::Graphics::Core::ShaderManager::Get::Pixel(L"Debug"));
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC inputDesc[] =
|
||||
{
|
||||
|
@ -155,12 +155,14 @@ HRESULT InitDirect3D()
|
|||
|
||||
ID3D11InputLayout* layout;
|
||||
|
||||
Oyster::Core::ShaderManager::CreateInputLayout( inputDesc, 1, Oyster::Core::ShaderManager::Get::Vertex(L"Debug"), layout);
|
||||
Oyster::Graphics::Core::ShaderManager::CreateInputLayout( inputDesc, 1, Oyster::Graphics::Core::ShaderManager::Get::Vertex(L"PassThroughFloat4"), layout);
|
||||
|
||||
Oyster::Core::DeviceContext->IASetInputLayout(layout);
|
||||
Oyster::Core::DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
Oyster::Graphics::Core::deviceContext->IASetInputLayout(layout);
|
||||
Oyster::Graphics::Core::deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
Oyster::Engine::PrepareForRendering::BindBackBuffer();
|
||||
Oyster::Graphics::Render::Preparations::Basic::BindBackBufferRTV();
|
||||
|
||||
Oyster::Graphics::Render::Preparations::Basic::SetViewPort();
|
||||
|
||||
struct float4
|
||||
{
|
||||
|
@ -174,14 +176,14 @@ HRESULT InitDirect3D()
|
|||
{1.0f,-1.0f,0.0f,1.0f},
|
||||
};
|
||||
|
||||
Oyster::Buffer::BUFFER_INIT_DESC desc;
|
||||
Oyster::Graphics::Buffer::BUFFER_INIT_DESC desc;
|
||||
desc.ElementSize= sizeof(float4);
|
||||
desc.NumElements = 3;
|
||||
desc.InitData=mesh;
|
||||
desc.Type = Oyster::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
|
||||
desc.Usage = Oyster::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE;
|
||||
desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
|
||||
desc.Usage = Oyster::Graphics::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE;
|
||||
|
||||
Oyster::Buffer b;
|
||||
Oyster::Graphics::Buffer b;
|
||||
b.Init(desc);
|
||||
b.Apply(0);
|
||||
|
||||
|
@ -195,11 +197,11 @@ HRESULT Update(float deltaTime)
|
|||
|
||||
HRESULT Render(float deltaTime)
|
||||
{
|
||||
Oyster::Engine::PrepareForRendering::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1));
|
||||
Oyster::Graphics::Render::Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1));
|
||||
|
||||
Oyster::Core::DeviceContext->Draw(3,0);
|
||||
Oyster::Graphics::Core::deviceContext->Draw(3,0);
|
||||
|
||||
Oyster::Core::SwapChain->Present(0,0);
|
||||
Oyster::Graphics::Core::swapChain->Present(0,0);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,351 @@
|
|||
#include "Core.h"
|
||||
#include <fstream>
|
||||
|
||||
const char* ShaderFunction = "main";
|
||||
|
||||
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<ID3D11PixelShader*> PS;
|
||||
std::map<std::wstring,int> PSMap;
|
||||
|
||||
std::vector<ID3D11GeometryShader*> GS;
|
||||
std::map<std::wstring,int> GSMap;
|
||||
|
||||
std::vector<ID3D11ComputeShader*> CS;
|
||||
std::map<std::wstring,int> CSMap;
|
||||
|
||||
std::vector<ID3D11VertexShader*> VS;
|
||||
std::vector<ShaderData> VData;
|
||||
std::map<std::wstring,int> 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;i<se.CBuffers.Vertex.size();++i)
|
||||
se.CBuffers.Vertex[i]->Apply(i);
|
||||
for(unsigned int i=0;i<se.CBuffers.Geometry.size();++i)
|
||||
se.CBuffers.Geometry[i]->Apply(i);
|
||||
for(unsigned int i=0;i<se.CBuffers.Pixel.size();++i)
|
||||
se.CBuffers.Pixel[i]->Apply(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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Core\Buffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Core\Core.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render\Model.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render\TextBox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\Buffers.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\Manager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\PipelineResources.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resourses\ShaderEffects.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Engine.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Core\ShaderManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Core\Buffer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Core\Core.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Core\CoreIncludes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\Lights.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\Model.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\ModelInfo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render\TextBox.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\Buffers.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\GraphicsDefinitions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\Manager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\PipelineResources.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resourses\ShaderEffects.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Engine.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EngineIncludes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FileLoader\ObjReader.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugVertex.hlsl" />
|
||||
<FxCompile Include="Shader\HLSL\SimpleDebug\DebugPixel.hlsl" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Tester</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\OysterGraphics;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MainTest.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Misc\Misc.vcxproj">
|
||||
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OysterGraphics\OysterGraphics.vcxproj">
|
||||
<Project>{0ec83e64-230e-48ef-b08c-6ac9651b4f82}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OysterMath\OysterMath.vcxproj">
|
||||
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue