2013-11-06 22:52:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef Core_h
|
|
|
|
#define Core_h
|
|
|
|
|
|
|
|
|
2013-11-26 13:44:58 +01:00
|
|
|
#include "Dx11Includes.h"
|
2013-11-06 22:52:00 +01:00
|
|
|
#include <sstream>
|
2013-11-21 10:02:17 +01:00
|
|
|
#include "OysterMath.h"
|
2014-01-31 16:29:50 +01:00
|
|
|
#include "../Misc/Resource/ResourceManager.h"
|
2014-01-16 09:30:01 +01:00
|
|
|
//#include <vld.h>
|
2013-11-20 10:22:01 +01:00
|
|
|
|
2013-11-06 22:52:00 +01:00
|
|
|
namespace Oyster
|
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
namespace Graphics
|
2013-11-06 22:52:00 +01:00
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
class Core
|
|
|
|
{
|
|
|
|
public:
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static ID3D11Device* device;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static ID3D11DeviceContext* deviceContext;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static IDXGISwapChain* swapChain;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static std::stringstream log;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2014-01-31 16:29:50 +01:00
|
|
|
static Resource::ResourceManager loader;
|
|
|
|
|
|
|
|
static std::wstring modelPath, texturePath;
|
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
//BackBufferRTV
|
|
|
|
static ID3D11RenderTargetView* backBufferRTV;
|
|
|
|
//BackBufferUAV
|
|
|
|
static ID3D11UnorderedAccessView* backBufferUAV;
|
|
|
|
//DepthStencil
|
|
|
|
static ID3D11DepthStencilView* depthStencil;
|
2013-12-18 20:28:06 +01:00
|
|
|
static ID3D11ShaderResourceView* depthStencilUAV;
|
2013-11-20 10:22:01 +01:00
|
|
|
//ViewPort
|
|
|
|
static D3D11_VIEWPORT* viewPort;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static Oyster::Math::Float2 resolution;
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
static ID3D11ShaderResourceView* srvNULL[16];
|
|
|
|
static ID3D11RenderTargetView* rtvNULL[8];
|
|
|
|
static ID3D11UnorderedAccessView* uavNULL[8];
|
|
|
|
|
2013-11-26 09:09:35 +01:00
|
|
|
class Buffer
|
|
|
|
{
|
|
|
|
public:
|
2013-12-18 20:28:06 +01:00
|
|
|
enum BUFFER_TYPE
|
|
|
|
{
|
|
|
|
VERTEX_BUFFER,
|
|
|
|
INDEX_BUFFER,
|
|
|
|
CONSTANT_BUFFER_VS,
|
|
|
|
CONSTANT_BUFFER_GS,
|
|
|
|
CONSTANT_BUFFER_PS,
|
|
|
|
CONSTANT_BUFFER_CS,
|
|
|
|
STRUCTURED_BUFFER,
|
|
|
|
BUFFER_TYPE_COUNT
|
|
|
|
};
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
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
|
|
|
|
};
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
struct BUFFER_INIT_DESC
|
2013-11-26 09:09:35 +01:00
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
BUFFER_TYPE Type;
|
|
|
|
UINT32 NumElements;
|
|
|
|
UINT32 ElementSize;
|
|
|
|
BUFFER_USAGE Usage;
|
|
|
|
void* InitData;
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
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();
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
HRESULT Init(const BUFFER_INIT_DESC& initDesc);
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
void* Map();
|
|
|
|
void Unmap();
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
operator ID3D11Buffer*();
|
|
|
|
operator const ID3D11Buffer*() const;
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
HRESULT Apply(UINT32 misc = 0) const;
|
2013-11-26 09:09:35 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
ID3D11Buffer* GetBufferPointer();
|
|
|
|
UINT32 GetVertexSize();
|
|
|
|
UINT32 GetElementCount();
|
2013-11-26 09:09:35 +01:00
|
|
|
};
|
2013-11-20 10:22:01 +01:00
|
|
|
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
class PipelineManager
|
2013-11-10 03:19:46 +01:00
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
public:
|
2013-12-18 20:28:06 +01:00
|
|
|
struct RenderPass
|
2013-11-10 03:19:46 +01:00
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
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;
|
2013-12-18 20:28:06 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
}RenderStates;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
std::vector<ID3D11Buffer*> Vertex;
|
|
|
|
std::vector<ID3D11Buffer*> Geometry;
|
|
|
|
std::vector<ID3D11Buffer*> Pixel;
|
|
|
|
std::vector<ID3D11Buffer*> Compute;
|
2013-11-20 10:22:01 +01:00
|
|
|
}CBuffers;
|
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
std::vector<ID3D11ShaderResourceView*> Vertex;
|
|
|
|
std::vector<ID3D11ShaderResourceView*> Geometry;
|
|
|
|
std::vector<ID3D11ShaderResourceView*> Pixel;
|
|
|
|
std::vector<ID3D11ShaderResourceView*> Compute;
|
|
|
|
}SRV;
|
|
|
|
|
|
|
|
std::vector<ID3D11RenderTargetView*> RTV;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
std::vector<ID3D11UnorderedAccessView*> Pixel;
|
|
|
|
std::vector<ID3D11UnorderedAccessView*> Compute;
|
|
|
|
}UAV;
|
|
|
|
|
|
|
|
ID3D11DepthStencilView* depth;
|
|
|
|
|
|
|
|
RenderPass()
|
2013-11-20 10:22:01 +01:00
|
|
|
{
|
|
|
|
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
|
2013-11-10 03:19:46 +01:00
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
Vertex,
|
|
|
|
Hull,
|
|
|
|
Domain,
|
|
|
|
Geometry,
|
|
|
|
Pixel,
|
|
|
|
Compute
|
|
|
|
};
|
2013-11-29 10:25:27 +01:00
|
|
|
struct ShaderData
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
char* data;
|
|
|
|
};
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
static void SetRenderPass(RenderPass);
|
2013-11-20 10:22:01 +01:00
|
|
|
|
|
|
|
static void CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout);
|
|
|
|
|
2013-11-29 10:25:27 +01:00
|
|
|
static bool Init(std::wstring filename, ShaderType type, std::wstring name);
|
|
|
|
static void* CreateShader(ShaderData data, ShaderType type);
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
struct Get
|
2013-11-10 03:19:46 +01:00
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
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);
|
|
|
|
};
|
2013-11-29 10:25:27 +01:00
|
|
|
|
|
|
|
static void Clean();
|
2013-12-18 20:28:06 +01:00
|
|
|
static void CleanPipeline();
|
2013-11-10 03:19:46 +01:00
|
|
|
};
|
2013-11-20 10:22:01 +01:00
|
|
|
|
|
|
|
//Set resulotion Before Calling Full Init
|
|
|
|
class Init
|
2013-11-10 03:19:46 +01:00
|
|
|
{
|
2013-11-20 10:22:01 +01:00
|
|
|
public:
|
|
|
|
enum State
|
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
Success,
|
2013-11-20 10:22:01 +01:00
|
|
|
Fail
|
|
|
|
};
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static State CreateDeviceAndDeviceContext(bool SingleThreaded = true, bool Reference = false, bool ForceDX11 = true);
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static State CreateSwapChain(HWND Window, int NrofBuffers,bool MSAA_Quality,bool Fullscreen, Oyster::Math::Float2 Size);
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static State CreateDepthStencil(bool MSAA_Quality, Oyster::Math::Float2 Size);
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
static State CreateBackBufferViews();
|
2013-11-10 03:19:46 +01:00
|
|
|
|
2013-11-20 10:22:01 +01:00
|
|
|
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);
|
2013-12-18 20:28:06 +01:00
|
|
|
|
|
|
|
static State CreateLinkedShaderResourceFromTexture(ID3D11RenderTargetView** rtv, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav);
|
|
|
|
|
|
|
|
static State CreateLinkedShaderResourceFromStructuredBuffer(Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav);
|
|
|
|
static State CreateLinkedShaderResourceFromStructuredBuffer(void* InitData, int numElem, int ElemSize, Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav);
|
|
|
|
|
2013-11-10 03:19:46 +01:00
|
|
|
};
|
|
|
|
};
|
2013-11-20 10:22:01 +01:00
|
|
|
}
|
2013-11-06 22:52:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|