Core Update

This commit is contained in:
lanariel 2013-11-20 10:22:01 +01:00
parent c9e6bbf899
commit 425a838f31
22 changed files with 1214 additions and 1003 deletions

View File

@ -1,9 +1,9 @@
#include "Buffer.h" #include "Buffer.h"
#include "Core.h" #include "Core.h"
using namespace Oyster; using namespace Oyster::Graphics;
Oyster::Buffer::Buffer() Buffer::Buffer()
{ {
mBuffer = NULL; mBuffer = NULL;
} }
@ -23,32 +23,32 @@ HRESULT Buffer::Apply(UINT32 misc) const
{ {
UINT32 vertexSize = mElementSize; UINT32 vertexSize = mElementSize;
UINT32 offset = 0; UINT32 offset = 0;
Oyster::Core::DeviceContext->IASetVertexBuffers(misc, 1, &mBuffer, &vertexSize, &offset ); Core::deviceContext->IASetVertexBuffers(misc, 1, &mBuffer, &vertexSize, &offset );
} }
break; break;
case INDEX_BUFFER: case INDEX_BUFFER:
{ {
Oyster::Core::DeviceContext->IASetIndexBuffer(mBuffer, DXGI_FORMAT_R32_UINT, 0); Core::deviceContext->IASetIndexBuffer(mBuffer, DXGI_FORMAT_R32_UINT, 0);
} }
break; break;
case CONSTANT_BUFFER_VS: case CONSTANT_BUFFER_VS:
{ {
Oyster::Core::DeviceContext->VSSetConstantBuffers(misc, 1, &mBuffer); Core::deviceContext->VSSetConstantBuffers(misc, 1, &mBuffer);
} }
break; break;
case CONSTANT_BUFFER_GS: case CONSTANT_BUFFER_GS:
{ {
Oyster::Core::DeviceContext->GSSetConstantBuffers(misc, 1, &mBuffer); Core::deviceContext->GSSetConstantBuffers(misc, 1, &mBuffer);
} }
break; break;
case CONSTANT_BUFFER_PS: case CONSTANT_BUFFER_PS:
{ {
Oyster::Core::DeviceContext->PSSetConstantBuffers(misc, 1, &mBuffer); Core::deviceContext->PSSetConstantBuffers(misc, 1, &mBuffer);
} }
break; break;
case CONSTANT_BUFFER_CS: case CONSTANT_BUFFER_CS:
{ {
Oyster::Core::DeviceContext->CSSetConstantBuffers(misc,1,&mBuffer); Core::deviceContext->CSSetConstantBuffers(misc,1,&mBuffer);
} }
break; break;
default: default:
@ -145,11 +145,11 @@ HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc)
data.pSysMem = initDesc.InitData; data.pSysMem = initDesc.InitData;
data.SysMemPitch=0; data.SysMemPitch=0;
data.SysMemSlicePitch = 0; data.SysMemSlicePitch = 0;
hr = Oyster::Core::Device->CreateBuffer(&bufferDesc, &data, &mBuffer); hr = Core::device->CreateBuffer(&bufferDesc, &data, &mBuffer);
} }
else else
{ {
hr = Oyster::Core::Device->CreateBuffer(&bufferDesc, NULL, &mBuffer); hr = Core::device->CreateBuffer(&bufferDesc, NULL, &mBuffer);
} }
if(FAILED(hr)) if(FAILED(hr))
@ -173,7 +173,7 @@ void* Buffer::Map()
else if(mUsage == BUFFER_CPU_WRITE_DISCARD) mapType = D3D11_MAP_WRITE_DISCARD; else if(mUsage == BUFFER_CPU_WRITE_DISCARD) mapType = D3D11_MAP_WRITE_DISCARD;
HRESULT hr = S_OK; HRESULT hr = S_OK;
if(FAILED(hr = Oyster::Core::DeviceContext->Map( if(FAILED(hr = Core::deviceContext->Map(
mBuffer, mBuffer,
0, 0,
(D3D11_MAP)mapType, (D3D11_MAP)mapType,
@ -194,10 +194,10 @@ void* Buffer::Map()
void Buffer::Unmap() void Buffer::Unmap()
{ {
Oyster::Core::DeviceContext->Unmap( mBuffer, 0 ); Core::deviceContext->Unmap( mBuffer, 0 );
} }
Oyster::Buffer::operator ID3D11Buffer *() Buffer::operator ID3D11Buffer *()
{ {
return this->mBuffer; return this->mBuffer;
} }

View File

@ -6,72 +6,74 @@
namespace Oyster namespace Oyster
{ {
class Buffer namespace Graphics
{ {
public: class Buffer
enum BUFFER_TYPE
{ {
VERTEX_BUFFER, public:
INDEX_BUFFER, enum BUFFER_TYPE
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; VERTEX_BUFFER,
Usage = BUFFER_DEFAULT; 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 #endif

View File

@ -1,169 +1,25 @@
#include "Core.h" #include "Core.h"
using namespace Oyster; using namespace Oyster::Graphics;
using std::string; using std::string;
//GPU //GPU
ID3D11Device *Core::Device = NULL; ID3D11Device *Core::device = NULL;
//API //API
ID3D11DeviceContext *Core::DeviceContext = NULL; ID3D11DeviceContext *Core::deviceContext = NULL;
//SwapChain //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) ID3D11UnorderedAccessView* Core::backBufferUAV = NULL;
{
UINT createDeviceFlags = 0;
if( SingleThreaded ) ID3D11DepthStencilView* Core::depthStencil = NULL;
createDeviceFlags = ::D3D11_CREATE_DEVICE_SINGLETHREADED;
::D3D_DRIVER_TYPE driverType = ::D3D_DRIVER_TYPE_HARDWARE; D3D11_VIEWPORT* Core::viewPort = NULL;
if(Reference) Oyster::Math::Float2 Core::resolution = Oyster::Math::Float2::null;
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;
}

View File

@ -7,108 +7,146 @@
#include "CoreIncludes.h" #include "CoreIncludes.h"
#include <sstream> #include <sstream>
#include "Buffer.h" #include "Buffer.h"
#include "OysterMath.h";
namespace Oyster namespace Oyster
{ {
class Core namespace Graphics
{ {
public: class Core
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
{ {
public: 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; struct
}Shaders; {
int Pixel,Vertex,Geometry,Compute,Hull,Domain;
}Shaders;
struct IAStage_ struct IAStage_
{ {
ID3D11InputLayout* Layout; ID3D11InputLayout* Layout;
D3D11_PRIMITIVE_TOPOLOGY Topology; D3D11_PRIMITIVE_TOPOLOGY Topology;
}IAStage; }IAStage;
struct RenderStates_ struct RenderStates_
{ {
ID3D11DepthStencilState *DepthStencil; ID3D11DepthStencilState *DepthStencil;
ID3D11RasterizerState *Rasterizer; ID3D11RasterizerState *Rasterizer;
ID3D11SamplerState **SampleState; ID3D11SamplerState **SampleState;
int SampleCount; int SampleCount;
ID3D11BlendState *BlendState; ID3D11BlendState *BlendState;
}RenderStates; }RenderStates;
struct struct
{ {
std::vector<Oyster::Buffer*> Vertex; std::vector<Buffer*> Vertex;
std::vector<Oyster::Buffer*> Geometry; std::vector<Buffer*> Geometry;
std::vector<Oyster::Buffer*> Pixel; std::vector<Buffer*> Pixel;
}CBuffers; }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; Vertex,
RenderStates.DepthStencil=NULL; Hull,
RenderStates.Rasterizer=NULL; Domain,
RenderStates.SampleState=NULL; Geometry,
RenderStates.SampleCount=0; Pixel,
Shaders.Compute=-1; Compute
Shaders.Domain=-1; };
Shaders.Geometry=-1;
Shaders.Hull=-1; static void SetShaderEffect(ShaderEffect);
Shaders.Pixel=-1;
Shaders.Vertex=-1; 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);
enum ShaderType
{ struct Get
Vertex, {
Hull, static int Pixel(std::wstring Name);
Domain, static int Vertex(std::wstring Name);
Geometry, static int Geometry(std::wstring Name);
Pixel, static int Compute(std::wstring Name);
Compute 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); //Set resulotion Before Calling Full Init
class Init
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); public:
static int Vertex(std::wstring Name); enum State
static int Geometry(std::wstring Name); {
static int Compute(std::wstring Name); Sucsess,
static int Hull(std::wstring Name); Fail
static int Domain(std::wstring Name); };
};
struct Set static State CreateDeviceAndDeviceContext(bool SingleThreaded = true, bool Reference = false, bool ForceDX11 = true);
{
static void Pixel(int Index); static State CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen, Oyster::Math::Float2 Size);
static void Vertex(int Index);
static void Geometry(int Index); static State CreateDepthStencil(bool MSAA_Quality, Oyster::Math::Float2 Size);
static void Compute(int Index);
static void Hull(int Index); static State CreateBackBufferViews();
static void Domain(int Index);
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);
}; };
}; };
}; }
} }

View File

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

View File

@ -5,347 +5,346 @@ const char* ShaderFunction = "main";
namespace Oyster namespace Oyster
{ {
bool LoadPrecompiled(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name); namespace Graphics
bool LoadCompile(std::wstring filename, Core::ShaderManager::ShaderType type, std::wstring name);
namespace
{ {
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; struct ShaderData
char* data; {
}; size_t size;
std::vector<ID3D11PixelShader*> PS; char* data;
std::map<std::wstring,int> PSMap; };
std::vector<ID3D11PixelShader*> PS;
std::map<std::wstring,int> PSMap;
std::vector<ID3D11GeometryShader*> GS; std::vector<ID3D11GeometryShader*> GS;
std::map<std::wstring,int> GSMap; std::map<std::wstring,int> GSMap;
std::vector<ID3D11ComputeShader*> CS; std::vector<ID3D11ComputeShader*> CS;
std::map<std::wstring,int> CSMap; std::map<std::wstring,int> CSMap;
std::vector<ID3D11VertexShader*> VS; std::vector<ID3D11VertexShader*> VS;
std::vector<ShaderData> VData; std::vector<ShaderData> VData;
std::map<std::wstring,int> VSMap; 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
#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) 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()); std::ifstream stream;
sd.data = new char[sd.size]; ShaderData sd;
stream.seekg(0, std::ios::beg);
stream.read(&sd.data[0], sd.size);
stream.close();
ID3D11VertexShader* vertex; //Create Vertex shader and Layout
ID3D11GeometryShader* geometry; stream.open(filename, std::ifstream::in | std::ifstream::binary);
ID3D11PixelShader* pixel; if(stream.good())
ID3D11ComputeShader* compute; {
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) switch(type)
{ {
case Core::ShaderManager::ShaderType::Vertex: case Core::ShaderManager::ShaderType::Pixel:
if(VSMap.count(name)) ID3D11PixelShader* pixel;
return false;
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; return false;
} }
VSMap[name] = VS.size(); if(FAILED(Core::device->CreatePixelShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&pixel)))
VS.push_back(vertex); {
VData.push_back(sd); Shader->Release();
return false;
}
Shader->Release();
if(!PSMap.count(name))
{
PSMap[name] = PS.size();
PS.push_back(pixel);
}
else
{
PS[PSMap[name]] = pixel;
}
break; break;
case Core::ShaderManager::ShaderType::Hull:
case Core::ShaderManager::ShaderType::Domain:
return false;
case Core::ShaderManager::ShaderType::Geometry: case Core::ShaderManager::ShaderType::Geometry:
if(GSMap.count(name)) ID3D11GeometryShader* geometry;
return false;
if(FAILED(Core::Device->CreateGeometryShader(sd.data, sd.size, 0, &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; return false;
} }
GSMap[name] = GS.size(); if(FAILED(Core::device->CreateGeometryShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&geometry)))
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)))
{ {
Shader->Release();
return false; return false;
} }
PSMap[name] = PS.size(); Shader->Release();
PS.push_back(pixel); if(!GSMap.count(name))
{
GSMap[name] = GS.size();
GS.push_back(geometry);
}
else
{
GS[GSMap[name]] = geometry;
}
break; break;
case Core::ShaderManager::ShaderType::Compute: case Core::ShaderManager::ShaderType::Vertex:
if(CSMap.count(name)) ID3D11VertexShader* vertex;
return false;
if(FAILED(Core::Device->CreateComputeShader(sd.data, sd.size, 0, &compute))) 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; return false;
} }
CSMap[name] = CS.size(); if(FAILED(Core::device->CreateVertexShader(Shader->GetBufferPointer(),Shader->GetBufferSize(),NULL,&vertex)))
CS.push_back(compute); {
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; 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) #pragma region Get
{ int Core::ShaderManager::Get::Pixel(std::wstring Name)
/// \todo error reporting
ID3D10Blob *Shader,*Error;
switch(type)
{ {
case Core::ShaderManager::ShaderType::Pixel: if(PSMap.count(Name))
return PSMap[Name];
ID3D11PixelShader* pixel; return -1;
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) int Core::ShaderManager::Get::Vertex(std::wstring Name)
{ {
if(VertexIndex==-1) 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; 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 /// \todo smart Set ie. not resetting the shader
int Core::ShaderManager::Get::Pixel(std::wstring Name) /// \todo research states
{ /// \todo smart buffer set
if(PSMap.count(Name)) void Core::ShaderManager::SetShaderEffect(ShaderEffect se)
return PSMap[Name]; {
return -1; 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);
}
} }

View File

@ -9,157 +9,160 @@
namespace Oyster namespace Oyster
{ {
class Engine namespace Graphics
{ {
private: class Engine
Engine();
~Engine();
public:
class Init
{ {
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: private:
Init(); Engine();
~Init(); ~Engine();
};
class States
{
public: public:
//SSAO Quality /*class Init
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
{ {
public: public:
//Basic Setup struct Setup
static void NewFrame(const Float4& Color, const Matrix& View, const Matrix& Projection); {
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 bool IsInstanced();
static void InputPointLights(Oyster::Resources::BufferDefinitions::PointLightDescription *p, int NrOfPointlights );
static void RenderLightning(); //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 #endif

View File

@ -1,9 +1,9 @@
//Oyster //Oyster
// Render // Render
#include "Render\Model.h" //#include "Render\Model.h"
#include "Render\Camera.h" //#include "Render\Camera.h"
#include "Render\TextBox.h" //#include "Render\TextBox.h"
// Core // Core
#include "Core\Core.h" #include "Core\Core.h"
@ -16,8 +16,8 @@
#include "OysterMath.h" #include "OysterMath.h"
// Resources // Resources
#include "Resourses\ShaderEffects.h" //#include "Resourses\ShaderEffects.h"
#include "Resourses\Buffers.h" //#include "Resourses\Buffers.h"
#include "Resourses\PipelineResources.h" //#include "Resourses\PipelineResources.h"
#include "Resourses\GraphicsDefinitions.h" //#include "Resourses\GraphicsDefinitions.h"
#include "Resourses\Manager.h" //#include "Resourses\Manager.h"

View File

@ -15,16 +15,17 @@ using namespace Oyster::Math;
namespace Oyster namespace Oyster
{ {
namespace Render namespace Graphics
{ {
namespace Render
struct Model
{ {
ModelInfo* info; struct Model
Float4x4 *World; {
bool Visible; ModelInfo* info;
}; Float4x4 *World;
bool Visible;
};
}
}; };
}; };

View File

@ -14,16 +14,19 @@ using namespace Oyster::Math;
namespace Oyster namespace Oyster
{ {
namespace Render namespace Graphics
{ {
struct ModelInfo namespace Render
{ {
std::vector<ID3D11ShaderResourceView*> Material; struct ModelInfo
Oyster::Buffer Vertices,Indecies; {
bool Indexed; std::vector<ID3D11ShaderResourceView*> Material;
int VertexCount; Buffer Vertices,Indecies;
}; bool Indexed;
}; int VertexCount;
};
}
}
}; };
#endif #endif

View File

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

View File

@ -90,11 +90,14 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)OysterMath;$(SolutionDir)Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
@ -140,31 +143,15 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="Core\Buffer.cpp" /> <ClCompile Include="Core\Buffer.cpp" />
<ClCompile Include="Core\Core.cpp" /> <ClCompile Include="Core\Core.cpp" />
<ClCompile Include="Core\Init.cpp" />
<ClCompile Include="Core\ShaderManager.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" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Core\Buffer.h" /> <ClInclude Include="Core\Buffer.h" />
<ClInclude Include="Core\Core.h" /> <ClInclude Include="Core\Core.h" />
<ClInclude Include="Core\CoreIncludes.h" /> <ClInclude Include="Core\CoreIncludes.h" />
<ClInclude Include="Engine.h" />
<ClInclude Include="EngineIncludes.h" /> <ClInclude Include="EngineIncludes.h" />
<ClInclude Include="FileLoader\ObjReader.h" /> <ClInclude Include="Render\Preparations.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" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Misc\Misc.vcxproj"> <ProjectReference Include="..\Misc\Misc.vcxproj">
@ -192,6 +179,8 @@
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent> <DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel> <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">main</EntryPointName> <EntryPointName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">main</EntryPointName>
<AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</AssemblerOutput>
</FxCompile> </FxCompile>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -21,30 +21,12 @@
<ClCompile Include="Core\Core.cpp"> <ClCompile Include="Core\Core.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </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"> <ClCompile Include="Core\ShaderManager.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Core\Init.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Core\Buffer.h"> <ClInclude Include="Core\Buffer.h">
@ -56,40 +38,10 @@
<ClInclude Include="Core\CoreIncludes.h"> <ClInclude Include="Core\CoreIncludes.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </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"> <ClInclude Include="EngineIncludes.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="FileLoader\ObjReader.h"> <ClInclude Include="Render\Preparations.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,23 @@
#include "..\Core\Core.h"
namespace Oyster
{
namespace Graphics
{
namespace Render
{
namespace Preparations
{
class Basic
{
void BindBackBufferRTV(bool UseDepthStencil = true);
void BindBackBufferRTV(ID3D11DepthStencilView* depthStencil);
void BindBackBufferUAV();
void ClearBackBuffer(Oyster::Math::Float4 Color, bool ClearDepthStencil);
};
}
}
}
}

View File

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

View File

@ -4,75 +4,78 @@
namespace Oyster namespace Oyster
{ {
class Shader namespace Graphics
{ {
public: class Shader
struct ShaderEffect
{ {
struct public:
struct ShaderEffect
{ {
int Pixel,Vertex,Geometry,Compute,Hull,Domain; struct
}Shaders; {
struct IAStage_ 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; static void SetPixel(int Index);
D3D11_PRIMITIVE_TOPOLOGY Topology; static void SetVertex(int Index);
}IAStage; static void SetGeometry(int Index);
struct RenderStates_ static void SetCompute(int Index);
static void SetHull(int Index);
static void SetDomain(int Index);
};
struct Get
{ {
ID3D11DepthStencilState *DepthStencil; static int GetPixel(std::string Name);
ID3D11RasterizerState *Rasterizer; static int GetVertex(std::string Name);
ID3D11SamplerState **SampleState; static int GetGeometry(std::string Name);
int SampleCount; static int GetCompute(std::string Name);
ID3D11BlendState *BlendState; static int GetHull(std::string Name);
}RenderStates; static int GetDomain(std::string Name);
struct };
{
std::vector<Buffer*> Vertex; static std::stringstream* AccesLog();
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
{
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();
};
} }

View File

@ -131,22 +131,21 @@ HRESULT InitDirect3D()
{ {
HRESULT hr = S_OK;; HRESULT hr = S_OK;;
Oyster::Engine::Init::Setup setup; Oyster::Graphics::Core::resolution = Oyster::Math::Float2( 1024, 768 );
setup.Fullscreen = false;
setup.ForceDX11 = true; if(Oyster::Graphics::Core::Init::FullInit(g_hWnd,false,false)==Oyster::Graphics::Core::Init::Fail)
setup.SingleThreaded = true; return E_FAIL;
setup.window = g_hWnd;
Oyster::Engine::Init::FullInit( setup );
std::wstring ShaderPath = L"..\\OysterGraphics\\Shader\\HLSL\\"; std::wstring ShaderPath = L"..\\OysterGraphics\\Shader\\HLSL\\";
std::wstring EffectPath = L"SimpleDebug\\"; std::wstring EffectPath = L"SimpleDebug\\";
Oyster::Core::ShaderManager::Init(ShaderPath + EffectPath + L"DebugPixel.hlsl",Oyster::Core::ShaderManager::ShaderType::Pixel,L"Debug",false); Oyster::Graphics::Core::ShaderManager::Init(ShaderPath + EffectPath + L"DebugPixel.hlsl",Oyster::Graphics::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"DebugVertex.hlsl",Oyster::Graphics::Core::ShaderManager::ShaderType::Vertex,L"Debug",false);
Oyster::Core::ShaderManager::Set::Vertex(Oyster::Core::ShaderManager::Get::Vertex(L"Debug")); Oyster::Graphics::Core::ShaderManager::Set::Vertex(Oyster::Graphics::Core::ShaderManager::Get::Vertex(L"Debug"));
Oyster::Core::ShaderManager::Set::Pixel(Oyster::Core::ShaderManager::Get::Pixel(L"Debug")); Oyster::Graphics::Core::ShaderManager::Set::Pixel(Oyster::Graphics::Core::ShaderManager::Get::Pixel(L"Debug"));
D3D11_INPUT_ELEMENT_DESC inputDesc[] = D3D11_INPUT_ELEMENT_DESC inputDesc[] =
{ {
@ -155,12 +154,14 @@ HRESULT InitDirect3D()
ID3D11InputLayout* layout; 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"Debug"), layout);
Oyster::Core::DeviceContext->IASetInputLayout(layout); Oyster::Graphics::Core::deviceContext->IASetInputLayout(layout);
Oyster::Core::DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); Oyster::Graphics::Core::deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
Oyster::Engine::PrepareForRendering::BindBackBuffer(); Oyster::Graphics::Core::deviceContext->OMSetRenderTargets(1,&Oyster::Graphics::Core::backBufferRTV,Oyster::Graphics::Core::depthStencil);
Oyster::Graphics::Core::deviceContext->RSSetViewports(1,Oyster::Graphics::Core::viewPort);
struct float4 struct float4
{ {
@ -174,14 +175,14 @@ HRESULT InitDirect3D()
{1.0f,-1.0f,0.0f,1.0f}, {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.ElementSize= sizeof(float4);
desc.NumElements = 3; desc.NumElements = 3;
desc.InitData=mesh; desc.InitData=mesh;
desc.Type = Oyster::Buffer::BUFFER_TYPE::VERTEX_BUFFER; desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
desc.Usage = Oyster::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE; desc.Usage = Oyster::Graphics::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE;
Oyster::Buffer b; Oyster::Graphics::Buffer b;
b.Init(desc); b.Init(desc);
b.Apply(0); b.Apply(0);
@ -195,11 +196,12 @@ HRESULT Update(float deltaTime)
HRESULT Render(float deltaTime) HRESULT Render(float deltaTime)
{ {
Oyster::Engine::PrepareForRendering::ClearBackBuffer(Oyster::Math::Float4(0,0,1,1)); Oyster::Graphics::Core::deviceContext->ClearRenderTargetView(Oyster::Graphics::Core::backBufferRTV, Oyster::Math::Float4(0,0,1,1));
Oyster::Graphics::Core::deviceContext->ClearDepthStencilView(Oyster::Graphics::Core::depthStencil,1,1,0);
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; return S_OK;
} }