*
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
#ifndef Enums_h__
|
||||
#define Enums_h__
|
||||
|
||||
enum COMPARISON_FUNC
|
||||
{ COMPARISON_NEVER = 1,
|
||||
COMPARISON_LESS = 2,
|
||||
COMPARISON_EQUAL = 3,
|
||||
COMPARISON_LESS_EQUAL = 4,
|
||||
COMPARISON_GREATER = 5,
|
||||
COMPARISON_NOT_EQUAL = 6,
|
||||
COMPARISON_GREATER_EQUAL = 7,
|
||||
COMPARISON_ALWAYS = 8
|
||||
};
|
||||
|
||||
enum STENCIL_OP
|
||||
{
|
||||
STENCIL_OP_KEEP = 1,
|
||||
STENCIL_OP_ZERO = 2,
|
||||
STENCIL_OP_REPLACE = 3,
|
||||
STENCIL_OP_INCR_SAT = 4,
|
||||
STENCIL_OP_DECR_SAT = 5,
|
||||
STENCIL_OP_INVERT = 6,
|
||||
STENCIL_OP_INCR = 7,
|
||||
STENCIL_OP_DECR = 8
|
||||
};
|
||||
|
||||
enum CULL_MODE {
|
||||
CULL_NONE = 1,
|
||||
CULL_FRONT = 2,
|
||||
CULL_BACK = 3
|
||||
};
|
||||
|
||||
enum CLEAR_FLAGS
|
||||
{
|
||||
CF_COLOR_TARGET = 1,
|
||||
CF_DEPTH_BUFFER = 2,
|
||||
CF_STENCIL = 4
|
||||
};
|
||||
|
||||
enum PRIMITIVE_TOPOLOGY
|
||||
{
|
||||
PT_POINT_LIST = 1,
|
||||
PT_LINE_LIST = 2,
|
||||
PT_LINE_STRIP = 3,
|
||||
PT_TRIANGLE_LIST = 4,
|
||||
PT_TRIANGLE_STRIP = 5,
|
||||
};
|
||||
|
||||
enum BLEND_OP
|
||||
{
|
||||
BLEND_OP_ADD = 1,
|
||||
BLEND_OP_SUBTRACT = 2,
|
||||
BLEND_OP_REV_SUBTRACT = 3,
|
||||
BLEND_OP_MIN = 4,
|
||||
BLEND_OP_MAX = 5
|
||||
};
|
||||
|
||||
enum BLEND_SRC
|
||||
{ BLEND_ZERO = 1,
|
||||
BLEND_ONE = 2,
|
||||
BLEND_SRC_COLOR = 3,
|
||||
BLEND_INV_SRC_COLOR = 4,
|
||||
BLEND_SRC_ALPHA = 5,
|
||||
BLEND_INV_SRC_ALPHA = 6,
|
||||
BLEND_DEST_ALPHA = 7,
|
||||
BLEND_INV_DEST_ALPHA = 8,
|
||||
BLEND_DEST_COLOR = 9,
|
||||
BLEND_INV_DEST_COLOR = 10,
|
||||
BLEND_SRC_ALPHA_SAT = 11,
|
||||
BLEND_BLEND_FACTOR = 14,
|
||||
BLEND_INV_BLEND_FACTOR = 15,
|
||||
BLEND_SRC1_COLOR = 16,
|
||||
BLEND_INV_SRC1_COLOR = 17,
|
||||
BLEND_SRC1_ALPHA = 18,
|
||||
BLEND_INV_SRC1_ALPHA = 19
|
||||
};
|
||||
|
||||
enum IDataFormat
|
||||
{
|
||||
FORMAT_UNKNOWN = 0,
|
||||
FORMAT_R32G32B32A32_TYPELESS = 1,
|
||||
FORMAT_R32G32B32A32_FLOAT = 2,
|
||||
FORMAT_R32G32B32A32_UINT = 3,
|
||||
FORMAT_R32G32B32A32_SINT = 4,
|
||||
FORMAT_R32G32B32_TYPELESS = 5,
|
||||
FORMAT_R32G32B32_FLOAT = 6,
|
||||
FORMAT_R32G32B32_UINT = 7,
|
||||
FORMAT_R32G32B32_SINT = 8,
|
||||
FORMAT_R16G16B16A16_TYPELESS = 9,
|
||||
FORMAT_R16G16B16A16_FLOAT = 10,
|
||||
FORMAT_R16G16B16A16_UNORM = 11,
|
||||
FORMAT_R16G16B16A16_UINT = 12,
|
||||
FORMAT_R16G16B16A16_SNORM = 13,
|
||||
FORMAT_R16G16B16A16_SINT = 14,
|
||||
FORMAT_R32G32_TYPELESS = 15,
|
||||
FORMAT_R32G32_FLOAT = 16,
|
||||
FORMAT_R32G32_UINT = 17,
|
||||
FORMAT_R32G32_SINT = 18,
|
||||
FORMAT_R32G8X24_TYPELESS = 19,
|
||||
FORMAT_D32_FLOAT_S8X24_UINT = 20,
|
||||
FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
|
||||
FORMAT_X32_TYPELESS_G8X24_UINT = 22,
|
||||
FORMAT_R10G10B10A2_TYPELESS = 23,
|
||||
FORMAT_R10G10B10A2_UNORM = 24,
|
||||
FORMAT_R10G10B10A2_UINT = 25,
|
||||
FORMAT_R11G11B10_FLOAT = 26,
|
||||
FORMAT_R8G8B8A8_TYPELESS = 27,
|
||||
FORMAT_R8G8B8A8_UNORM = 28,
|
||||
FORMAT_R8G8B8A8_UNORM_SRGB = 29,
|
||||
FORMAT_R8G8B8A8_UINT = 30,
|
||||
FORMAT_R8G8B8A8_SNORM = 31,
|
||||
FORMAT_R8G8B8A8_SINT = 32,
|
||||
FORMAT_R16G16_TYPELESS = 33,
|
||||
FORMAT_R16G16_FLOAT = 34,
|
||||
FORMAT_R16G16_UNORM = 35,
|
||||
FORMAT_R16G16_UINT = 36,
|
||||
FORMAT_R16G16_SNORM = 37,
|
||||
FORMAT_R16G16_SINT = 38,
|
||||
FORMAT_R32_TYPELESS = 39,
|
||||
FORMAT_D32_FLOAT = 40,
|
||||
FORMAT_R32_FLOAT = 41,
|
||||
FORMAT_R32_UINT = 42,
|
||||
FORMAT_R32_SINT = 43,
|
||||
FORMAT_R24G8_TYPELESS = 44,
|
||||
FORMAT_D24_UNORM_S8_UINT = 45,
|
||||
FORMAT_R24_UNORM_X8_TYPELESS = 46,
|
||||
FORMAT_X24_TYPELESS_G8_UINT = 47,
|
||||
FORMAT_R8G8_TYPELESS = 48,
|
||||
FORMAT_R8G8_UNORM = 49,
|
||||
FORMAT_R8G8_UINT = 50,
|
||||
FORMAT_R8G8_SNORM = 51,
|
||||
FORMAT_R8G8_SINT = 52,
|
||||
FORMAT_R16_TYPELESS = 53,
|
||||
FORMAT_R16_FLOAT = 54,
|
||||
FORMAT_D16_UNORM = 55,
|
||||
FORMAT_R16_UNORM = 56,
|
||||
FORMAT_R16_UINT = 57,
|
||||
FORMAT_R16_SNORM = 58,
|
||||
FORMAT_R16_SINT = 59,
|
||||
FORMAT_R8_TYPELESS = 60,
|
||||
FORMAT_R8_UNORM = 61,
|
||||
FORMAT_R8_UINT = 62,
|
||||
FORMAT_R8_SNORM = 63,
|
||||
FORMAT_R8_SINT = 64,
|
||||
FORMAT_A8_UNORM = 65,
|
||||
FORMAT_R1_UNORM = 66,
|
||||
FORMAT_R9G9B9E5_SHAREDEXP = 67,
|
||||
FORMAT_R8G8_B8G8_UNORM = 68,
|
||||
FORMAT_G8R8_G8B8_UNORM = 69,
|
||||
FORMAT_BC1_TYPELESS = 70,
|
||||
FORMAT_BC1_UNORM = 71,
|
||||
FORMAT_BC1_UNORM_SRGB = 72,
|
||||
FORMAT_BC2_TYPELESS = 73,
|
||||
FORMAT_BC2_UNORM = 74,
|
||||
FORMAT_BC2_UNORM_SRGB = 75,
|
||||
FORMAT_BC3_TYPELESS = 76,
|
||||
FORMAT_BC3_UNORM = 77,
|
||||
FORMAT_BC3_UNORM_SRGB = 78,
|
||||
FORMAT_BC4_TYPELESS = 79,
|
||||
FORMAT_BC4_UNORM = 80,
|
||||
FORMAT_BC4_SNORM = 81,
|
||||
FORMAT_BC5_TYPELESS = 82,
|
||||
FORMAT_BC5_UNORM = 83,
|
||||
FORMAT_BC5_SNORM = 84,
|
||||
FORMAT_B5G6R5_UNORM = 85,
|
||||
FORMAT_B5G5R5A1_UNORM = 86,
|
||||
FORMAT_B8G8R8A8_UNORM = 87,
|
||||
FORMAT_B8G8R8X8_UNORM = 88,
|
||||
FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
|
||||
FORMAT_B8G8R8A8_TYPELESS = 90,
|
||||
FORMAT_B8G8R8A8_UNORM_SRGB = 91,
|
||||
FORMAT_B8G8R8X8_TYPELESS = 92,
|
||||
FORMAT_B8G8R8X8_UNORM_SRGB = 93,
|
||||
FORMAT_BC6H_TYPELESS = 94,
|
||||
FORMAT_BC6H_UF16 = 95,
|
||||
FORMAT_BC6H_SF16 = 96,
|
||||
FORMAT_BC7_TYPELESS = 97,
|
||||
FORMAT_BC7_UNORM = 98,
|
||||
FORMAT_BC7_UNORM_SRGB = 99,
|
||||
FORMAT_FORCE_UINT = 0xffffffff
|
||||
};
|
||||
#endif // Enums_h__
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef IBlendState_h__
|
||||
#define IBlendState_h__
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IBlendState
|
||||
{
|
||||
public:
|
||||
IBlendState()
|
||||
{
|
||||
}
|
||||
virtual ~IBlendState()
|
||||
{
|
||||
}
|
||||
bool AlphaToCoverageEnabled;
|
||||
bool AlphaBlendEnabled;
|
||||
};
|
||||
}
|
||||
#endif // IBlendState_h__
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef IConstantBuffer_h__
|
||||
#define IConstantBuffer_h__
|
||||
#include "IResource.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IConstantBuffer : public IResource
|
||||
{
|
||||
public:
|
||||
IConstantBuffer(){}
|
||||
virtual ~IConstantBuffer(){}
|
||||
virtual void Update(void* pData, int dataLength) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IConstantBuffer_h__
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "render/IConstantMapping.h"
|
||||
|
||||
IConstantMapping::IConstantMapping()
|
||||
:lastSlotId(0)
|
||||
{
|
||||
}
|
||||
IConstantMapping::~IConstantMapping()
|
||||
{
|
||||
}
|
||||
uint32 IConstantMapping::GetAlignedSize()
|
||||
{
|
||||
return (lastSlotId + 1) * HLSL_CONSTANT_SIZE * (mapping.size() > 0 ? 1 : 0);
|
||||
}
|
||||
void IConstantMapping::InsertConstant(const String& name, uint32 numRows, uint32 numCols)
|
||||
{
|
||||
if(!numRows || !numCols) return;
|
||||
|
||||
if(numRows == 1)
|
||||
{
|
||||
//try to insert variable in @white spaces@
|
||||
if(spaces.size() > 0)
|
||||
{
|
||||
for(ConstantCollectionItr it = spaces.begin(); it != spaces.end(); ++it)
|
||||
{
|
||||
if((*it).ColumnCount <= numCols) //found suitable white space! Fill it ^^
|
||||
{
|
||||
mapping.push_back(IConstantMappingData((*it).SlotID, (*it).SlotOffset, 1, numCols));
|
||||
(*it).SlotOffset += numCols;
|
||||
(*it).ColumnCount -= numCols;
|
||||
if((*it).ColumnCount <= 0)
|
||||
spaces.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
mapping.push_back(IConstantMappingData(lastSlotId++, 0, 1, numCols));
|
||||
if(numCols < 4)
|
||||
spaces.push_back(IConstantMappingData(lastSlotId, numCols, 1, 4 - numCols));
|
||||
}
|
||||
else
|
||||
{
|
||||
mapping.push_back(IConstantMappingData(lastSlotId, 0, numRows, numCols));
|
||||
lastSlotId+=numRows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef IConstantMapping_h__
|
||||
#define IConstantMapping_h__
|
||||
|
||||
#include <vector>
|
||||
#include "Types.h"
|
||||
#include <LString.h>
|
||||
|
||||
#define HLSL_CONSTANT_SIZE (4*4)
|
||||
|
||||
struct IConstantMappingData
|
||||
{
|
||||
IConstantMappingData(uint32 slot, uint32 offset, uint32 row_count, uint32 col_count)
|
||||
{
|
||||
SlotID = slot;
|
||||
SlotOffset = offset;
|
||||
RowCount = row_count;
|
||||
ColumnCount = col_count;
|
||||
}
|
||||
uint32 SlotID;
|
||||
uint32 SlotOffset;
|
||||
uint32 ColumnCount;
|
||||
uint32 RowCount;
|
||||
};
|
||||
class IConstantMapping
|
||||
{
|
||||
public:
|
||||
IConstantMapping();
|
||||
~IConstantMapping();
|
||||
void InsertConstant(const String& name, uint32 numRows, uint32 numCols);
|
||||
uint32 GetAlignedSize();
|
||||
private:
|
||||
uint32 lastSlotId;
|
||||
typedef std::vector<IConstantMappingData> ConstantCollection;
|
||||
typedef std::vector<IConstantMappingData>::iterator ConstantCollectionItr;
|
||||
ConstantCollection mapping;
|
||||
ConstantCollection spaces;
|
||||
};
|
||||
#endif // IConstantMapping_h__
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef I_DATA_BUFFER_H__
|
||||
#define I_DATA_BUFFER_H__
|
||||
|
||||
#include "IDataStream.h"
|
||||
#include "IResource.h"
|
||||
namespace LifeGraphics
|
||||
{
|
||||
enum IBufferLockFlags
|
||||
{
|
||||
LF_None = 0,
|
||||
LF_DoNotCopyData = 1,
|
||||
LF_ReadOnly = 16,
|
||||
LF_NoSystemLock = 2048,
|
||||
LF_NoOverwrite = 4096,
|
||||
LF_Discard = 8192,
|
||||
LF_DoNotWait = 16384,
|
||||
LF_NoDirtyUpdate = 32768,
|
||||
};
|
||||
|
||||
class IDataBuffer : public IResource
|
||||
{
|
||||
public:
|
||||
virtual ~IDataBuffer(){}
|
||||
virtual LifeCore::IDataStream* Map(int offset, int flags) = 0;
|
||||
virtual void Unmap() = 0;
|
||||
int length;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef IDepthStencilState_h__
|
||||
#define IDepthStencilState_h__
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IDepthStencilState
|
||||
{
|
||||
public:
|
||||
IDepthStencilState()
|
||||
{
|
||||
}
|
||||
virtual ~IDepthStencilState()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IDepthStencilState_h__
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef I_INDEX_BUFFER_H__
|
||||
#define I_INDEX_BUFFER_H__
|
||||
|
||||
#include "IDataBuffer.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IIndexBuffer : public IDataBuffer
|
||||
{
|
||||
public:
|
||||
virtual ~IIndexBuffer(){}
|
||||
int isShort;
|
||||
int indexCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef IInputElement_h__
|
||||
#define IInputElement_h__
|
||||
|
||||
#include "LString.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
struct IInputElement
|
||||
{
|
||||
String Name;
|
||||
int SemanticIndex;
|
||||
int Offset;
|
||||
int Format;
|
||||
int Slot;
|
||||
int IsInstancingData;
|
||||
int InstancingRate;
|
||||
|
||||
IInputElement(String name, int semanticIndex, int offset, int format, int slot, int isInstData, int instancingRate)
|
||||
{
|
||||
Name = name;
|
||||
SemanticIndex = semanticIndex;
|
||||
Offset = offset;
|
||||
Format = format;
|
||||
Slot = slot;
|
||||
IsInstancingData = isInstData;
|
||||
InstancingRate = instancingRate;
|
||||
}
|
||||
|
||||
IInputElement(String name, int semanticIndex, int offset, int format, int slot)
|
||||
{
|
||||
Name = name;
|
||||
SemanticIndex = semanticIndex;
|
||||
Offset = offset;
|
||||
Format = format;
|
||||
Slot = slot;
|
||||
IsInstancingData = 0;
|
||||
InstancingRate = 0;
|
||||
}
|
||||
IInputElement()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IInputElement_h__
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef IInputLayout_h__
|
||||
#define IInputLayout_h__
|
||||
|
||||
#include "render/IInputElement.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IInputLayout : public IResource
|
||||
{
|
||||
public:
|
||||
IInputLayout():elementCount(0)
|
||||
{
|
||||
}
|
||||
virtual ~IInputLayout()
|
||||
{
|
||||
}
|
||||
int count()
|
||||
{
|
||||
return elementCount;
|
||||
}
|
||||
IInputElement* GetElements() const
|
||||
{
|
||||
return elements;
|
||||
}
|
||||
protected:
|
||||
IInputElement* elements;
|
||||
int elementCount;
|
||||
};
|
||||
}
|
||||
#endif // IInputLayout_h__
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef IMacroDefine_h__
|
||||
#define IMacroDefine_h__
|
||||
#include "LString.h"
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IMacroDefine
|
||||
{
|
||||
public:
|
||||
IMacroDefine(){}
|
||||
~IMacroDefine(){}
|
||||
IMacroDefine(std::string& _name)
|
||||
: definition("true")
|
||||
{
|
||||
name = _name;
|
||||
}
|
||||
IMacroDefine(std::string& _name, std::string& _def)
|
||||
{
|
||||
name = _name;
|
||||
definition = _def;
|
||||
}
|
||||
std::string name;
|
||||
std::string definition;
|
||||
};
|
||||
}
|
||||
#endif // IMacroDefine_h__
|
||||
@@ -0,0 +1,232 @@
|
||||
#include "render/IMaterial.h"
|
||||
#include "render/IMaterialProxy.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
|
||||
IMaterialPass::IMaterialPass(MaterialPass _type)
|
||||
:passType(_type), ps(nullptr), vs(nullptr), gs(nullptr), cb(nullptr)
|
||||
{
|
||||
}
|
||||
IMaterialPass::~IMaterialPass()
|
||||
{
|
||||
}
|
||||
void IMaterialPass::SetShader(SHADER_TYPE _type, IShader* shader)
|
||||
{
|
||||
switch(_type)
|
||||
{
|
||||
case ST_VS:
|
||||
vs = shader;
|
||||
break;
|
||||
case ST_PS:
|
||||
ps = shader;
|
||||
break;
|
||||
case ST_GS:
|
||||
gs = shader;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
//TODO replace it by new log error
|
||||
printf("Unknown shader type in IMaterialPass::SetShader\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
IShader* IMaterialPass::GetShader(SHADER_TYPE _type)
|
||||
{
|
||||
switch(_type)
|
||||
{
|
||||
case ST_VS:
|
||||
return vs;
|
||||
case ST_PS:
|
||||
return ps;
|
||||
case ST_GS:
|
||||
return gs;
|
||||
default:
|
||||
{
|
||||
//TODO replace it by new log error
|
||||
printf("Unknown shader type in IMaterialPass::GetShader\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
MaterialPass IMaterialPass::GetPassType()
|
||||
{
|
||||
return passType;
|
||||
}
|
||||
IConstantBuffer* IMaterialPass::GetConstantBuffer()
|
||||
{
|
||||
return cb;
|
||||
}
|
||||
void IMaterialPass::SetTexture(texture_ptr tex, uint32 slot)
|
||||
{
|
||||
textureSlots[slot] = tex;
|
||||
}
|
||||
void IMaterialPass::Apply()
|
||||
{
|
||||
for(int i = 0; i < MAX_TEX_SLOT; i++)
|
||||
{
|
||||
texture_ptr tex = textureSlots[i];
|
||||
if(tex.ptr() != nullptr)
|
||||
{
|
||||
CG::me()->GetRenderer()->SetPSTexture(tex.ptr(), i);
|
||||
}
|
||||
}
|
||||
|
||||
CG::me()->GetRenderer()->SetPixelShader(ps);
|
||||
CG::me()->GetRenderer()->SetVertexShader(vs);
|
||||
}
|
||||
|
||||
IMaterial::IMaterial(IShaderGraph* _graph, IShaderGraphCompiler* _compiler)
|
||||
:CastShadows(false), ReceiveShadows(false), Opaque(false), flags(MF_NONE)
|
||||
{
|
||||
graph = _graph;
|
||||
compiler = _compiler;
|
||||
}
|
||||
IMaterial::~IMaterial()
|
||||
{
|
||||
}
|
||||
IMaterialPass* IMaterial::AddPass(MaterialPass _type)
|
||||
{
|
||||
IMaterialPass* result = GetPass(_type);
|
||||
if(result == nullptr)
|
||||
{
|
||||
result = new IMaterialPass(_type);
|
||||
passes[_type] = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
void IMaterial::SetTexture(int id, texture_ptr tex)
|
||||
{
|
||||
textures[id] = tex;
|
||||
}
|
||||
texture_ptr IMaterial::GetTexture(int id)
|
||||
{
|
||||
return textures[id];
|
||||
}
|
||||
IMaterialPass* IMaterial::GetPass(MaterialPass _type)
|
||||
{
|
||||
PassCollectionItr it = passes.find(_type);
|
||||
return it == passes.end() ? nullptr : it->second;
|
||||
}
|
||||
uint32 IMaterial::GetPassCount()
|
||||
{
|
||||
return passes.size();
|
||||
}
|
||||
IMaterialProxy* IMaterial::CreateProxy(IObjectMesh* parent)
|
||||
{
|
||||
IMaterialProxy* proxy = new IMaterialProxy(this, parent);
|
||||
//TODO
|
||||
//Add proxy to watch collection!
|
||||
return proxy;
|
||||
}
|
||||
IMaterialTechnique* IMaterial::CreateTechnique(MaterialTechnique tech, IMaterialProxy* target)
|
||||
{
|
||||
switch (tech)
|
||||
{
|
||||
case LifeGraphics::MT_RENDER_FORWARD:
|
||||
return nullptr;
|
||||
break;
|
||||
case LifeGraphics::MT_RENDER_DEFERRED:
|
||||
{
|
||||
IMaterialTechnique* technique = new IMaterialTechnique(tech, target);
|
||||
|
||||
|
||||
return technique;
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return nullptr;
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IMaterialPass* IMaterial::CreatePass(IMaterialTechnique* tech, MaterialPass pass)
|
||||
{
|
||||
switch (tech->GetTechniqueType())
|
||||
{
|
||||
case MT_RENDER_FORWARD:
|
||||
return nullptr;
|
||||
break;
|
||||
case MT_RENDER_DEFERRED:
|
||||
{
|
||||
switch(pass)
|
||||
{
|
||||
case MP_G_FILL:
|
||||
{
|
||||
IMaterialPass* p = new IMaterialPass(pass);
|
||||
String ps, vs;
|
||||
compiler->CompileNode(graph->GetNodeByID(0), pass, ps, vs, &p->inputInfo);
|
||||
IShader* psh = ResourceManager::me()->CompileUserShaderPS(ps.c_str(), ps.size());
|
||||
IShader* vsh = ResourceManager::me()->CompileUserShaderVS(vs.c_str(), vs.size());
|
||||
|
||||
|
||||
|
||||
p->SetShader(ST_PS, psh);
|
||||
p->SetShader(ST_VS, vsh);
|
||||
|
||||
//set textures
|
||||
for(int i = 0; i < p->inputInfo.Textures.size(); i++)
|
||||
{
|
||||
ShaderTextureMapping mapping = p->inputInfo.Textures[i];
|
||||
p->SetTexture(GetTexture(mapping.nodeId), mapping.reg);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
case MP_DEPTH_SM:
|
||||
{
|
||||
IMaterialPass* p = new IMaterialPass(pass);
|
||||
String ps, vs;
|
||||
compiler->CompileNode(graph->GetNodeByID(0), pass, ps, vs, &p->inputInfo);
|
||||
IShader* psh = ResourceManager::me()->CompileUserShaderPS(ps.c_str(), ps.size());
|
||||
IShader* vsh = ResourceManager::me()->CompileUserShaderVS(vs.c_str(), vs.size());
|
||||
|
||||
p->SetShader(ST_PS, psh);
|
||||
p->SetShader(ST_VS, vsh);
|
||||
|
||||
return p;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*IMaterial::IMaterial(uint32 constantBufferSize)
|
||||
:castShadows(false),receiveShadows(false),
|
||||
ownerFlags(EF_NONE), AlphaBlendEnable(false)
|
||||
{
|
||||
Name = AS_STRING("unnamed");
|
||||
materialCb = CG::me()->GetRenderer()->CreateConstantBuffer(sizeof(PER_MATERIAL_CONSTANTS));
|
||||
}
|
||||
IMaterial::~IMaterial()
|
||||
{
|
||||
}
|
||||
IConstantBuffer* IMaterial::GetConstantBuffer()
|
||||
{
|
||||
return materialCb;
|
||||
}
|
||||
void IMaterial::SetTexture(texture_ptr tex, uint32 slot)
|
||||
{
|
||||
textureSlots[slot] = tex;
|
||||
}
|
||||
void IMaterial::Apply()
|
||||
{
|
||||
for(int i = 0; i < MAX_TEX_SLOT; i++)
|
||||
{
|
||||
texture_ptr tex = textureSlots[i];
|
||||
if(tex.ptr() != 0)
|
||||
{
|
||||
CG::me()->GetRenderer()->SetPSTexture(tex.ptr(), i);
|
||||
}
|
||||
}
|
||||
|
||||
//CG::me()->GetRenderer()->SetPixelShader(g_buffer_pass_ps);
|
||||
//CG::me()->GetRenderer()->SetVertexShader(g_buffer_pass_vs);
|
||||
}*/
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifndef IMaterial_h__
|
||||
#define IMaterial_h__
|
||||
#include "render/IShader.h"
|
||||
#include "Types.h"
|
||||
#include "XML.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "CG.h"
|
||||
#include "render/IVideoTexture.h"
|
||||
#include "shaders/IShaderGraph.h"
|
||||
#include "shaders/IShaderGraphCompiler.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
#define MAX_TEX_SLOT 16
|
||||
struct TextureSlot
|
||||
{
|
||||
texture_ptr Texture;
|
||||
uint32 SlotID;
|
||||
};
|
||||
|
||||
enum MaterialTechnique
|
||||
{
|
||||
MT_RENDER_FORWARD,
|
||||
MT_RENDER_DEFERRED
|
||||
};
|
||||
|
||||
enum MaterialPass
|
||||
{
|
||||
MP_G_FILL,
|
||||
MP_DEPTH_SM,
|
||||
MP_DEPTH_SOLID,
|
||||
};
|
||||
|
||||
enum MaterialFlags
|
||||
{
|
||||
MF_NONE = 0,
|
||||
MF_GEN_DEFAULT = 1 << 0,
|
||||
};
|
||||
|
||||
class IMaterialPass
|
||||
{
|
||||
public:
|
||||
IMaterialPass(MaterialPass _type);
|
||||
~IMaterialPass();
|
||||
MaterialPass GetPassType();
|
||||
IConstantBuffer* GetConstantBuffer();
|
||||
IShader* GetShader(SHADER_TYPE _type);
|
||||
void SetShader(SHADER_TYPE _type, IShader* shader);
|
||||
void SetTexture(texture_ptr tex, uint32 slot);
|
||||
void Apply();
|
||||
ShaderInputInfo inputInfo;
|
||||
private:
|
||||
MaterialPass passType;
|
||||
IShader* ps;
|
||||
IShader* vs;
|
||||
IShader* gs;
|
||||
IConstantBuffer* cb;
|
||||
|
||||
texture_ptr textureSlots[MAX_TEX_SLOT];
|
||||
};
|
||||
|
||||
class IMaterialProxy;
|
||||
class IMaterialTechnique;
|
||||
class IObjectMesh;
|
||||
class IMaterial : public IResource
|
||||
{
|
||||
friend class IMaterialProxy;
|
||||
public:
|
||||
IMaterial(IShaderGraph* _graph, IShaderGraphCompiler* _compiler);
|
||||
~IMaterial();
|
||||
IMaterialPass* AddPass(MaterialPass _type);
|
||||
IMaterialPass* GetPass(MaterialPass id);
|
||||
void SetTexture(int id, texture_ptr tex);
|
||||
texture_ptr GetTexture(int id);
|
||||
uint32 GetPassCount();
|
||||
bool CastShadows;
|
||||
bool ReceiveShadows;
|
||||
bool Opaque;
|
||||
IMaterialProxy* CreateProxy(IObjectMesh* parent);
|
||||
MaterialFlags flags;
|
||||
IMaterialTechnique* CreateTechnique(MaterialTechnique tech, IMaterialProxy* target);
|
||||
IMaterialPass* CreatePass(IMaterialTechnique* tech, MaterialPass pass);
|
||||
private:
|
||||
|
||||
|
||||
typedef std::map<MaterialPass, IMaterialPass*> PassCollection;
|
||||
typedef std::map<MaterialPass, IMaterialPass*>::iterator PassCollectionItr;
|
||||
|
||||
typedef std::map<int, texture_ptr> TexCollection;
|
||||
typedef std::map<int, texture_ptr>::iterator TexCollectionItr;
|
||||
TexCollection textures;
|
||||
PassCollection passes;
|
||||
EFFECT_FLAGS ownerFlags;
|
||||
IShaderGraph* graph;
|
||||
IShaderGraphCompiler* compiler;
|
||||
};
|
||||
}
|
||||
#endif // IMaterial_h__
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "render/IMaterialProxy.h"
|
||||
#include "IObjectMesh.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
IMaterial* IMaterialProxy::GetBaseMaterial()
|
||||
{
|
||||
return base;
|
||||
}
|
||||
bool IMaterialProxy::SelectTechnique(MaterialTechnique tech)
|
||||
{
|
||||
TechniqueCollectionItr it = technics.find(tech);
|
||||
if(it != technics.end()){
|
||||
active_technique = it->second;
|
||||
return true;
|
||||
}
|
||||
else //try to request it from parent material
|
||||
{
|
||||
IMaterialTechnique* t = base->CreateTechnique(MT_RENDER_DEFERRED,this);
|
||||
if(t == nullptr) return false;
|
||||
active_technique = t;
|
||||
return AddTechnique(t);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
IMaterialProxy::IMaterialProxy(IMaterial* source, IObjectMesh* _geom)
|
||||
:active_technique(nullptr)
|
||||
{
|
||||
base = source;
|
||||
geom = _geom;
|
||||
}
|
||||
bool IMaterialProxy::AddTechnique(IMaterialTechnique* tech)
|
||||
{
|
||||
TechniqueCollectionItr it = technics.find(tech->GetTechniqueType());
|
||||
if(it != technics.end())//found
|
||||
return false;
|
||||
else
|
||||
{
|
||||
technics[tech->GetTechniqueType()] = tech;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
IMaterialTechnique* IMaterialProxy::GetTechnique()
|
||||
{
|
||||
return active_technique;
|
||||
}
|
||||
|
||||
bool IMaterialTechnique::SelectPass(MaterialPass pass)
|
||||
{
|
||||
if(active_pass != NULL && active_pass->GetPassType() == pass)
|
||||
return true;
|
||||
PassCollectionItr it = passes.find(pass);
|
||||
if(it != passes.end())
|
||||
{
|
||||
active_pass = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
//pass not found -> try to create it!
|
||||
IMaterialPass* newpass = parent->GetBaseMaterial()->CreatePass(this, pass);
|
||||
if(newpass != nullptr)
|
||||
{
|
||||
active_pass = newpass;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
IMaterialPass* IMaterialTechnique::GetPass()
|
||||
{
|
||||
return active_pass;
|
||||
}
|
||||
bool IMaterialTechnique::AddPass(IMaterialPass* pass)
|
||||
{
|
||||
PassCollectionItr it = passes.find(pass->GetPassType());
|
||||
if(it != passes.end()) //found
|
||||
return false;
|
||||
else
|
||||
{
|
||||
passes[pass->GetPassType()] = pass;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
IMaterialTechnique::IMaterialTechnique(MaterialTechnique tech, IMaterialProxy* _parent)
|
||||
:active_pass(nullptr), tech_type(tech), parent(_parent)
|
||||
{
|
||||
}
|
||||
MaterialTechnique IMaterialTechnique::GetTechniqueType()
|
||||
{
|
||||
return tech_type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef IMaterialProxy_h__
|
||||
#define IMaterialProxy_h__
|
||||
|
||||
#include "render/IMaterial.h"
|
||||
#include <map>
|
||||
#include <Types.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IObjectMesh;
|
||||
class IMaterialProxy;
|
||||
class IMaterialTechnique
|
||||
{
|
||||
friend class IMaterial;
|
||||
public:
|
||||
bool SelectPass(MaterialPass pass);
|
||||
IMaterialPass* GetPass();
|
||||
MaterialTechnique GetTechniqueType();
|
||||
private:
|
||||
IMaterialTechnique(MaterialTechnique tech, IMaterialProxy* _parent);
|
||||
bool AddPass(IMaterialPass* pass);
|
||||
typedef std::map<MaterialPass, IMaterialPass*> PassCollection;
|
||||
typedef std::map<MaterialPass, IMaterialPass*>::iterator PassCollectionItr;
|
||||
PassCollection passes;
|
||||
IMaterialPass* active_pass;
|
||||
MaterialTechnique tech_type;
|
||||
IMaterialProxy* parent;
|
||||
};
|
||||
|
||||
class IMaterialProxy
|
||||
{
|
||||
friend class IMaterial;
|
||||
public:
|
||||
bool SelectTechnique(MaterialTechnique tech);
|
||||
IMaterialTechnique* GetTechnique();
|
||||
IMaterial* GetBaseMaterial();
|
||||
private:
|
||||
bool AddTechnique(IMaterialTechnique* tech);
|
||||
typedef std::map<MaterialTechnique, IMaterialTechnique*> TechniqueCollection;
|
||||
typedef std::map<MaterialTechnique, IMaterialTechnique*>::iterator TechniqueCollectionItr;
|
||||
TechniqueCollection technics;
|
||||
|
||||
IMaterialTechnique* active_technique;
|
||||
IMaterialProxy(IMaterial* source, IObjectMesh* _geom);
|
||||
IObjectMesh* geom;
|
||||
IMaterial* base;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IMaterialProxy_h__
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef IRasterizerState_h__
|
||||
#define IRasterizerState_h__
|
||||
#include "IResource.h"
|
||||
|
||||
enum FILL_MODE
|
||||
{
|
||||
FILL_WIREFRAME = 2,
|
||||
FILL_SOLID = 3
|
||||
};
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IRasterizerState : public IResource
|
||||
{
|
||||
public:
|
||||
FILL_MODE Fill;
|
||||
IRasterizerState()
|
||||
{
|
||||
}
|
||||
virtual ~IRasterizerState()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IRasterizerState_h__
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef IRenderTargetView_h__
|
||||
#define IRenderTargetView_h__
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IRenderTargetView
|
||||
{
|
||||
public:
|
||||
IRenderTargetView(){}
|
||||
virtual ~IRenderTargetView(){}
|
||||
};
|
||||
}
|
||||
#endif // IRenderTargetView_h__
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "render/IRenderer.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
IRenderer::IRenderer(){}
|
||||
|
||||
IRenderer::~IRenderer(){}
|
||||
|
||||
HRESULT IRenderer::Open(RenderParams params){return S_OK;}
|
||||
|
||||
void IRenderer::Close(){}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
#ifndef I_RENDERER
|
||||
#define I_RENDERER
|
||||
|
||||
#include "render/ITexture2D.h"
|
||||
#include "render/RenderParams.h"
|
||||
#include <winerror.h>
|
||||
#include "LString.h"
|
||||
#include <math/Rectangle.h>
|
||||
|
||||
#include "render/IVertexBuffer.h"
|
||||
#include "render/IIndexBuffer.h"
|
||||
#include "render/IInputLayout.h"
|
||||
#include "render/IShader.h"
|
||||
#include "render/IMacroDefine.h"
|
||||
#include "render/IConstantBuffer.h"
|
||||
#include "ISwapChain.h"
|
||||
#include "IMesh.h"
|
||||
#include "camera/Camera.h"
|
||||
//#include "render/IMaterial.h"
|
||||
#include "render/IBlendState.h"
|
||||
#include "render/IDepthStencilState.h"
|
||||
#include "Rectangle2D.h"
|
||||
#include "render/IRenderTargetView.h"
|
||||
#include "render/ITextureSampler.h"
|
||||
#include "render/IRasterizerState.h"
|
||||
#include "Types.h"
|
||||
#include "render/Enums.h"
|
||||
#include "DisplayMode.h"
|
||||
#include "render/ISurface.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IMaterial;
|
||||
enum PassType
|
||||
{
|
||||
PT_RENDER_SHADOW_MAP = 1 << 0,
|
||||
PT_LIGHTING = 1 << 1,
|
||||
PT_COMPOSE_FINAL = 1 << 2,
|
||||
PT_COMPOSE_G_BUF = 1 << 3,
|
||||
PT_ENV_MAP = 1 << 4,
|
||||
PT_RENDER_SHADOW_MAP_PSSM = 1 << 5,
|
||||
};
|
||||
|
||||
struct PassDesc
|
||||
{
|
||||
Camera* camera;
|
||||
Frustum* frustum;
|
||||
PassType type;
|
||||
IMesh* mesh;
|
||||
uint32 subset;
|
||||
uint32 flags;
|
||||
ITexture2D* colorTarget;
|
||||
ITexture2D* depthTarget;
|
||||
ITexture2D* colorTarget1;
|
||||
std::vector<IGraphicsNode*> objectList;
|
||||
};
|
||||
|
||||
class LIFE_EXPORTS IRenderer
|
||||
{
|
||||
public:
|
||||
IRenderer();
|
||||
virtual ~IRenderer();
|
||||
virtual void BeginCleanup() = 0;
|
||||
virtual void EndCleanup() = 0;
|
||||
virtual HRESULT Open(RenderParams params);
|
||||
virtual void Close();
|
||||
//virtual void ClearBuffers(int flags, int rtColor, float zValue, int stencilValue) = 0;
|
||||
virtual void ClearRenderTarget(ITexture2D* tex, LifeMath::float4* color) = 0;
|
||||
virtual void ClearDepthStencil(ITexture2D* tex, float zValue, int stencilValue) = 0;
|
||||
virtual void ClearDepthStencil(ITexture2D* tex, int flag, float zValue, int stencilValue) = 0;
|
||||
|
||||
virtual void ClearRenderTarget(ISurface* target, LifeMath::float4* color) = 0;
|
||||
virtual void ClearDepthStencil(ISurface* target, int flag, float zValue, int stencilValue) = 0;
|
||||
|
||||
virtual ITexture2D* CreateRenderTarget(int width, int height, int format) = 0;
|
||||
virtual ITexture2D* CreateRenderTargetCube(int size, int format) = 0;
|
||||
virtual ITexture2D* CreateDepthTarget(int width, int height, int format) = 0;
|
||||
virtual ITexture2D* CreateDepthTargetCube(int width, int format) = 0;
|
||||
virtual const String &GetRendererName() const = 0;
|
||||
virtual ITexture2D* LoadTexture2D(LifeCore::IDataStreamPtr src) = 0;
|
||||
virtual ITexture2D* CreateTexture2D(int canRead, int canWrite, int width, int height, int format) = 0;
|
||||
virtual void RenderToTexture() = 0;
|
||||
virtual void RenderToTextureNoPs() = 0;
|
||||
virtual void RenderToTextureNoShader() = 0;
|
||||
virtual IVertexBuffer* CreateVertexBuffer(int size, void* data, int stride) = 0;
|
||||
virtual IVertexBuffer* CreateVertexBufferDynamic(int size, int stride) = 0;
|
||||
|
||||
virtual IIndexBuffer* CreateIndexBuffer(int size, void* data, int sixteenBit) = 0;
|
||||
virtual IIndexBuffer* CreateIndexBufferDynamic(int size, bool sixteenBit) = 0;
|
||||
virtual IInputLayout* CreateInputLayout(IInputElement* elements, int elementCount, IShader* vertexShader) = 0;
|
||||
|
||||
virtual ITextureSampler* CreateTextureSampler(ISamplerDescription* desc) = 0;
|
||||
|
||||
virtual IShader* CompileVertexShader(const char* pData, int length) = 0;
|
||||
virtual IShader* CompileVertexShader(LifeCore::IDataStreamPtr stream) = 0;
|
||||
virtual IShader* CompileVertexShader(LifeCore::IDataStreamPtr stream, std::vector<IMacroDefine>* defines) = 0;
|
||||
|
||||
virtual IShader* CompilePixelShader(const char* pData, int length) = 0;
|
||||
virtual IShader* CompilePixelShader(LifeCore::IDataStreamPtr stream) = 0;
|
||||
virtual IShader* CompilePixelShader(LifeCore::IDataStreamPtr stream, std::vector<IMacroDefine>* defines) = 0;
|
||||
|
||||
virtual IConstantBuffer* CreateConstantBuffer(int size) = 0;
|
||||
|
||||
virtual void SetVSConstantBuffer(IConstantBuffer* buffer, int slot) = 0;
|
||||
virtual void SetPSConstantBuffer(IConstantBuffer* buffer, int slot) = 0;
|
||||
|
||||
virtual void SetInputLayout(IInputLayout* layout) = 0;
|
||||
virtual void RenderMesh(IMesh* mesh) = 0;
|
||||
|
||||
virtual void SetMaterial(IMaterial* material) = 0;
|
||||
|
||||
virtual void SetTargets(ITexture2D* colorTarget, ITexture2D* depthTarget) = 0;
|
||||
|
||||
virtual void SetTargets(ISurface* colorTarget, ISurface* depthTarget) = 0;
|
||||
|
||||
virtual void SetCubeTarget(ITexture2D* colorTarget, ITexture2D* depthTarget, int faceIndex) = 0;
|
||||
|
||||
virtual void SetTargets(ITexture2D** colorTargets, int targetCount, ITexture2D* depthTarget) = 0;
|
||||
|
||||
virtual void UnbindRenderTargets() = 0;
|
||||
|
||||
virtual void SetColorTarget(ITexture2D* colorTarget) = 0;
|
||||
virtual void SetDepthTarget(ITexture2D* depthTarget) = 0;
|
||||
|
||||
virtual void SetVertexBuffer(IVertexBuffer* vb) = 0;
|
||||
virtual void SetIndexBuffer(IIndexBuffer* ib) = 0;
|
||||
|
||||
virtual void SetPrimitiveTopology(PRIMITIVE_TOPOLOGY topology) = 0;
|
||||
|
||||
virtual void SetPSTextureNULL(int slot) = 0;
|
||||
virtual void DrawIndexed(int offset, int length) = 0;
|
||||
virtual void DrawIndexed(int offset, int length, int baseVertex) = 0;
|
||||
|
||||
virtual void SetPSTextureSampler(ITextureSampler* sampler, int slot) = 0;
|
||||
virtual void SetVertexShader(IShader* shader) = 0;
|
||||
virtual void SetPixelShader(IShader* shader) = 0;
|
||||
|
||||
virtual void SetPSTexture(ITexture2D* texture, int slot) = 0;
|
||||
virtual void SetPSTextureCube(ITexture2D* texture, int slot) = 0;
|
||||
virtual void SetPSTexture(ITexture2D* texture, ITexture2D* texture2, int start, int count) = 0;
|
||||
|
||||
virtual void SetVSTexture(ITexture2D* texture, int slot) = 0;
|
||||
|
||||
virtual void UnbindResourcesPS() = 0;
|
||||
|
||||
virtual void Draw(int vertexCount, int vertexOffset) = 0;
|
||||
|
||||
virtual IBlendState* CreateBlendState(bool blendEnable, bool atocEnable, BLEND_OP blendOperation, BLEND_SRC srcBlend, BLEND_SRC dstBlend, uint8 colorMask) = 0;
|
||||
|
||||
virtual void SetBlendState(IBlendState* state) = 0;
|
||||
|
||||
virtual IDepthStencilState* CreateDSState(bool zEnable, bool zWrite, COMPARISON_FUNC zFunc) = 0;
|
||||
|
||||
virtual IDepthStencilState* CreateDSState(bool zEnable, bool zWrite, COMPARISON_FUNC zFunc, bool stencil, int stencilMask, int stencilFunc, int stencilFail, int depthFail, int depthFailBack, int stencilPass) = 0;
|
||||
|
||||
virtual void SetDepthStencilState(IDepthStencilState* state, UINT sref = 0) = 0;
|
||||
|
||||
virtual void SetScissorRectangle(const LifeMath::Rect2i& rect) = 0;
|
||||
|
||||
virtual void SetViewport(const LifeMath::Rect2i& rect) = 0;
|
||||
|
||||
virtual void SetViewport(const LifeMath::Rect2i& rect, float minDepth, float maxDepth) = 0;
|
||||
|
||||
virtual void VerticalBlur(ITexture2D* src, ITexture2D* dst, int numSamples) = 0;
|
||||
|
||||
virtual IShader* CompileUserShaderPS(char* data) = 0;
|
||||
|
||||
virtual IRasterizerState* CreateRasterizerState(FILL_MODE mode) = 0;
|
||||
virtual IRasterizerState* CreateRasterizerState(FILL_MODE mode, CULL_MODE cmode) = 0;
|
||||
|
||||
virtual void SetRasterizerState(IRasterizerState* state) = 0;
|
||||
|
||||
virtual void SetVertexBuffer(IVertexBuffer** vb, int count) = 0;
|
||||
|
||||
virtual void DrawIndexedInstanced(int offset, int length, int instanceCnt) = 0;
|
||||
virtual void DrawIndexedInstanced(int offset, int length, int baseVertex, int instanceCnt) = 0;
|
||||
|
||||
virtual void DownSample2x2(ITexture2D* src, ITexture2D* dst, ITexture2D* depth) = 0;
|
||||
virtual void BlurGaussH(ITexture2D* src, ITexture2D* dst, ITexture2D* depth) = 0;
|
||||
virtual void BlurGaussV(ITexture2D* src, ITexture2D* dst, ITexture2D* depth) = 0;
|
||||
virtual int GetDisplayModes(LifeCore::DisplayMode** modeList) = 0;
|
||||
|
||||
virtual ISwapChain* CreateSwapChain(LifeCore::IRenderWindow* window) = 0;
|
||||
|
||||
protected:
|
||||
RenderParams g_params;
|
||||
};
|
||||
|
||||
enum RENDERER_TYPE
|
||||
{
|
||||
RT_DIRECTX_10 = 1 << 0,
|
||||
RT_DIRECTX_9 = 1 << 1,
|
||||
RT_OPENGL = 1 << 2,
|
||||
RT_SOFTWARE = 1 << 3,
|
||||
RT_DIRECTX_11 = 1 << 4,
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef IShader_h__
|
||||
#define IShader_h__
|
||||
|
||||
#include "IResource.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
enum SHADER_TYPE
|
||||
{
|
||||
ST_VS = 0,
|
||||
ST_PS = 1,
|
||||
ST_GS = 2
|
||||
};
|
||||
class IShader : public IResource
|
||||
{
|
||||
public:
|
||||
int Flags;
|
||||
virtual ~IShader()
|
||||
{
|
||||
}
|
||||
//public event ShaderCallback SetConstants;
|
||||
|
||||
//public delegate void ShaderCallback(IObject obj, IShader shader, int subset, ICamera camera);
|
||||
|
||||
// public void OnSetConstants(IObject obj, IShader shader, int subset, ICamera camera)
|
||||
//{
|
||||
//if (SetConstants != null)
|
||||
//SetConstants(obj, shader, subset, camera);
|
||||
// }
|
||||
|
||||
virtual void* Disassemble() = 0;
|
||||
virtual SHADER_TYPE getShaderType() = 0;
|
||||
virtual char* GetByteCode() = 0;
|
||||
};
|
||||
}
|
||||
#endif // IShader_h__
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef IShaderResourceView_h__
|
||||
#define IShaderResourceView_h__
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IShaderResourceView
|
||||
{
|
||||
public:
|
||||
IShaderResourceView()
|
||||
{
|
||||
}
|
||||
virtual ~IShaderResourceView()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IShaderResourceView_h__
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef ISurface_h__
|
||||
#define ISurface_h__
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ISurface
|
||||
{
|
||||
public:
|
||||
virtual ~ISurface() {}
|
||||
};
|
||||
}
|
||||
#endif // ISurface_h__
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef ITexture2D_h__
|
||||
#define ITexture2D_h__
|
||||
|
||||
#include "IResource.h"
|
||||
#include "render/ITextureDescription.h"
|
||||
#include "LString.h"
|
||||
#include "IDataRectangle.h"
|
||||
#include "render/IRenderTargetView.h"
|
||||
#include "render/IShaderResourceView.h"
|
||||
#include "render/ISurface.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ITexture2D : public IResource
|
||||
{
|
||||
public:
|
||||
int bpp;
|
||||
virtual ~ITexture2D(){}
|
||||
ITextureDescription Description;
|
||||
virtual bool IsVideoTexture() = 0;
|
||||
virtual int Width() = 0;
|
||||
virtual int Height() = 0;
|
||||
virtual LifeCore::IDataRectangle* Map(int level, int read, int write) = 0;
|
||||
virtual void Unmap(int level){};
|
||||
virtual void ToFile(const String& path) {};
|
||||
virtual void Load(LifeCore::IDataStream* src) {};
|
||||
virtual void CompleteAsyncRequest(IResource* source){};
|
||||
virtual IRenderTargetView* getRTView() = 0;
|
||||
virtual IRenderTargetView* getRTView(int index) = 0;
|
||||
|
||||
virtual IShaderResourceView* getSRView() = 0;
|
||||
virtual IShaderResourceView* getSRView(int index) = 0;
|
||||
virtual ISurface* getSurface(int id) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef ITextureContainer_h__
|
||||
#define ITextureContainer_h__
|
||||
|
||||
#include "render/ITexture2D.h"
|
||||
#include <vector>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ITextureContainer
|
||||
{
|
||||
private:
|
||||
void Reset()
|
||||
{
|
||||
currTex = frames[0];
|
||||
}
|
||||
std::vector<ITexture2D*> frames;
|
||||
ITexture2D* currTex;
|
||||
public:
|
||||
ITextureContainer()
|
||||
{
|
||||
}
|
||||
~ITextureContainer()
|
||||
{
|
||||
}
|
||||
void AddFrame(ITexture2D* frame)
|
||||
{
|
||||
frames.push_back(frame);
|
||||
Reset();
|
||||
}
|
||||
ITexture2D* operator->(){return currTex;}
|
||||
};
|
||||
}
|
||||
#endif // ITextureContainer_h__
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef ITextureCube_h__
|
||||
#define ITextureCube_h__
|
||||
|
||||
#include "render/ITexture2D.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ITexture2DArray : public ITexture2D
|
||||
{
|
||||
public:
|
||||
ITexture2DArray()
|
||||
{
|
||||
}
|
||||
~ITexture2DArray()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // ITextureCube_h__
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef ITextureDescription_h__
|
||||
#define ITextureDescription_h__
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
typedef struct ITextureDescription
|
||||
{
|
||||
int Width, Height;
|
||||
int Format;
|
||||
int SampleCount, SampleQuality;
|
||||
}ITextureDescription;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,79 @@
|
||||
#ifndef ITextureSampler_h__
|
||||
#define ITextureSampler_h__
|
||||
#include "IResource.h"
|
||||
#include "render/Enums.h"
|
||||
namespace LifeGraphics
|
||||
{
|
||||
enum TextureFilter
|
||||
{
|
||||
MinMagMipPoint = 0,
|
||||
MinMagPointMipLinear = 1,
|
||||
MinPointMagLinearMipPoint = 4,
|
||||
MinPointMagMipLinear = 5,
|
||||
MinLinearMagMipPoint = 16,
|
||||
MinLinearMagPointMipLinear = 17,
|
||||
MinMagLinearMipPoint = 20,
|
||||
MinMagMipLinear = 21,
|
||||
Anisotropic = 85,
|
||||
ComparisonMinMagMipPoint = 128,
|
||||
ComparisonMinMagPointMipLinear = 129,
|
||||
ComparisonMinPointMagLinearMipPoint = 132,
|
||||
ComparisonMinPointMagMipLinear = 133,
|
||||
ComparisonMinLinearMagMipPoint = 144,
|
||||
ComparisonMinLinearMagPointMipLinear = 145,
|
||||
ComparisonMinMagLinearMipPoint = 148,
|
||||
ComparisonMinMagMipLinear = 149,
|
||||
ComparisonAnisotropic = 213,
|
||||
};
|
||||
|
||||
enum TextureAddressMode
|
||||
{
|
||||
Wrap = 1,
|
||||
Mirror = 2,
|
||||
Clamp = 3,
|
||||
Border = 4,
|
||||
MirrorOnce = 5,
|
||||
};
|
||||
|
||||
struct ISamplerDescription
|
||||
{
|
||||
TextureAddressMode AddressU;
|
||||
TextureAddressMode AddressV;
|
||||
TextureAddressMode AddressW;
|
||||
TextureFilter Filter;
|
||||
COMPARISON_FUNC CmpFunc;
|
||||
|
||||
ISamplerDescription(TextureAddressMode _aU, TextureAddressMode _aV, TextureAddressMode _aW, TextureFilter _f)
|
||||
{
|
||||
AddressU = _aU;
|
||||
AddressV = _aV;
|
||||
AddressW = _aW;
|
||||
Filter = _f;
|
||||
CmpFunc = COMPARISON_ALWAYS;
|
||||
}
|
||||
ISamplerDescription(TextureAddressMode _aU, TextureAddressMode _aV, TextureAddressMode _aW, TextureFilter _f, COMPARISON_FUNC cmp)
|
||||
{
|
||||
AddressU = _aU;
|
||||
AddressV = _aV;
|
||||
AddressW = _aW;
|
||||
Filter = _f;
|
||||
CmpFunc = cmp;
|
||||
}
|
||||
ISamplerDescription()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ITextureSampler : public IResource
|
||||
{
|
||||
public:
|
||||
ISamplerDescription Description;
|
||||
ITextureSampler()
|
||||
{
|
||||
}
|
||||
virtual ~ITextureSampler()
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // ITextureSampler_h__
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef I_VERTEX_BUFFER_H__
|
||||
#define I_VERTEX_BUFFER_H__
|
||||
|
||||
#include "IDataBuffer.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IVertexBuffer : public IDataBuffer
|
||||
{
|
||||
public:
|
||||
virtual ~IVertexBuffer(){}
|
||||
unsigned int stride;
|
||||
int vertexCount;
|
||||
virtual void Update(void* data, size_t length)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef IVideoTexture_h__
|
||||
#define IVideoTexture_h__
|
||||
|
||||
#include "render/ITexture2D.h"
|
||||
#include <vector>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IVideoTexture : public LifeGraphics::ITexture2D
|
||||
{
|
||||
public:
|
||||
float fps;
|
||||
float time;
|
||||
IVideoTexture()
|
||||
:fps(24.0f), time(0.0f)
|
||||
{
|
||||
}
|
||||
~IVideoTexture()
|
||||
{
|
||||
}
|
||||
ISurface* getSurface(int id)
|
||||
{
|
||||
return currTex->getSurface(id);
|
||||
}
|
||||
void AddFrame(ITexture2D* frame)
|
||||
{
|
||||
frames.push_back(frame);
|
||||
currTex = frames[0];
|
||||
}
|
||||
ITexture2D* GetPtr()
|
||||
{
|
||||
return currTex;
|
||||
}
|
||||
//ITexture2D* operator->(){return currTex;}
|
||||
|
||||
LifeCore::IDataRectangle* Map(int level, int read, int write)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void Update(float dt)
|
||||
{
|
||||
time+=dt;
|
||||
int cnt = frames.size();
|
||||
float tpf = 1.0f / fps;
|
||||
int cur = (int)(time / tpf); //-V2003
|
||||
cur = cur%cnt;
|
||||
SelectFrame(cur);
|
||||
}
|
||||
void SelectFrame(int frame)
|
||||
{
|
||||
currTex = frames[frame];
|
||||
}
|
||||
int Width()
|
||||
{
|
||||
return currTex->Width();
|
||||
}
|
||||
int Height()
|
||||
{
|
||||
return currTex->Height();
|
||||
}
|
||||
bool IsVideoTexture()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
IRenderTargetView* getRTView()
|
||||
{
|
||||
return currTex->getRTView();
|
||||
}
|
||||
IRenderTargetView* getRTView(int index)
|
||||
{
|
||||
return currTex->getRTView(index);
|
||||
}
|
||||
|
||||
IShaderResourceView* getSRView()
|
||||
{
|
||||
return currTex->getSRView();
|
||||
}
|
||||
IShaderResourceView* getSRView(int index)
|
||||
{
|
||||
return currTex->getSRView(index);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<ITexture2D*> frames;
|
||||
ITexture2D* currTex;
|
||||
};
|
||||
}
|
||||
#endif // IVideoTexture_h__
|
||||
@@ -0,0 +1,86 @@
|
||||
#ifndef PostDOF_h__
|
||||
#define PostDOF_h__
|
||||
|
||||
#include "render/PostEffect.h"
|
||||
#include "Globals.h"
|
||||
#include "render/ITextureSampler.h"
|
||||
#include "math/LifeMath.h"
|
||||
#include "LifeDebug.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class PostDOF : public PostEffect
|
||||
{
|
||||
private:
|
||||
IRenderer* renderer;
|
||||
IShader* psDof;
|
||||
IBlendState* blendState;
|
||||
IBlendState* blendStateOpaque;
|
||||
IDepthStencilState* depthState;
|
||||
public:
|
||||
ITexture2D* dofBlur1;
|
||||
ITexture2D* dofBlur2;
|
||||
ITexture2D* dofBlur3;
|
||||
ITexture2D* dofBlur4;
|
||||
//ITexture2D* dofResult;
|
||||
PostDOF()
|
||||
{
|
||||
}
|
||||
ITexture2D* Execute(PostEffectParams& params)
|
||||
{
|
||||
renderer->SetBlendState(blendStateOpaque);
|
||||
renderer->SetDepthStencilState(depthState);
|
||||
|
||||
renderer->UnbindResourcesPS();
|
||||
renderer->UnbindRenderTargets();
|
||||
LifeMath::float4 color(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
renderer->ClearRenderTarget(dofBlur1, &color);
|
||||
renderer->DownSample2x2(params.renderTarget, dofBlur1, params.depthTarget);
|
||||
|
||||
renderer->UnbindResourcesPS();
|
||||
renderer->UnbindRenderTargets();
|
||||
renderer->DownSample2x2(dofBlur1, dofBlur2, params.depthTarget);
|
||||
|
||||
renderer->UnbindResourcesPS();
|
||||
renderer->UnbindRenderTargets();
|
||||
renderer->DownSample2x2(dofBlur2, dofBlur3, params.depthTarget);
|
||||
|
||||
renderer->UnbindResourcesPS();
|
||||
renderer->UnbindRenderTargets();
|
||||
renderer->DownSample2x2(dofBlur3, dofBlur4, params.depthTarget);
|
||||
|
||||
renderer->UnbindResourcesPS();
|
||||
renderer->UnbindRenderTargets();
|
||||
LifeMath::Rect2i vp = LifeMath::Rect2i(0,0,params.renderTarget->Width(), params.renderTarget->Height());
|
||||
renderer->SetScissorRectangle(vp);
|
||||
renderer->SetViewport(vp);
|
||||
renderer->SetPixelShader(psDof);
|
||||
renderer->SetPSTexture(params.depthTex, 1);
|
||||
renderer->SetPSTexture(dofBlur4, 2);
|
||||
renderer->SetTargets(params.renderTarget, params.depthTarget);
|
||||
renderer->SetBlendState(blendState);
|
||||
renderer->SetDepthStencilState(depthState);
|
||||
renderer->RenderToTextureNoPs();
|
||||
|
||||
return dofBlur1;
|
||||
}
|
||||
void Init(SceneDescriptor& desc)
|
||||
{
|
||||
renderer = CG::me()->GetRenderer();
|
||||
|
||||
dofBlur1 = renderer->CreateRenderTarget(desc.width / 2, desc.height / 2, FORMAT_R16G16B16A16_FLOAT);
|
||||
dofBlur2 = renderer->CreateRenderTarget(desc.width / 4, desc.height / 4, FORMAT_R16G16B16A16_FLOAT);
|
||||
dofBlur3 = renderer->CreateRenderTarget(desc.width / 8, desc.height / 8, FORMAT_R16G16B16A16_FLOAT);
|
||||
dofBlur4 = renderer->CreateRenderTarget(desc.width / 16, desc.height / 16, FORMAT_R16G16B16A16_FLOAT);
|
||||
//dofResult = renderer->CreateRenderTarget(desc.width, desc.height);
|
||||
//
|
||||
psDof = ResourceManager::me()->CompileUserShaderPS(STR("PostDOF.psh"));
|
||||
|
||||
blendState = renderer->CreateBlendState(true, false, BLEND_OP_ADD, BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA, 1 | 2 | 4 | 8);
|
||||
blendStateOpaque = renderer->CreateBlendState(false, false, BLEND_OP_ADD, BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA, 1 | 2 | 4 | 8);
|
||||
depthState = renderer->CreateDSState(false, false, COMPARISON_NEVER);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PostDOF_h__
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef PostEffect_h__
|
||||
#define PostEffect_h__
|
||||
#include "ResourceManager.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
struct SceneDescriptor
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct PostEffectParams
|
||||
{
|
||||
ITexture2D* renderTarget;
|
||||
ITexture2D* depthTarget;
|
||||
ITexture2D* depthTex;
|
||||
float timeElapsed;
|
||||
};
|
||||
|
||||
class PostEffect
|
||||
{
|
||||
public:
|
||||
PostEffect(){}
|
||||
virtual ~PostEffect(){}
|
||||
virtual ITexture2D* Execute(PostEffectParams& params) = 0;
|
||||
virtual void Init(SceneDescriptor& desc) = 0;
|
||||
};
|
||||
}
|
||||
#endif // PostEffect_h__
|
||||
@@ -0,0 +1,420 @@
|
||||
#ifndef PostHDR_h__
|
||||
#define PostHDR_h__
|
||||
#include "render/PostEffect.h"
|
||||
#include "Globals.h"
|
||||
#include "render/ITextureSampler.h"
|
||||
#include "math/LifeMath.h"
|
||||
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
|
||||
#include "LifeDebug.h"
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class PostHDR : public PostEffect
|
||||
{
|
||||
public:
|
||||
ITexture2D* g_brightPassTexture;
|
||||
ITexture2D* g_downSampleTexture;
|
||||
ITexture2D* g_horizontalBlur;
|
||||
ITexture2D* g_verticalBlur;
|
||||
ITexture2D* g_finalImage;
|
||||
ITexture2D* g_lumLast;
|
||||
ITexture2D* g_lumCur;
|
||||
static const int NumLuminanceTextures = 4;
|
||||
ITexture2D* luminanceTextures[NumLuminanceTextures];
|
||||
ITexture2D* luminanceTexturesZ[NumLuminanceTextures];
|
||||
ITexture2D* src;
|
||||
ITexture2D* srcZ;
|
||||
|
||||
ITexture2D* downSampleZ;
|
||||
ITexture2D* brightPassZ;
|
||||
|
||||
ITextureSampler* samplerPointClamp;
|
||||
|
||||
float exposure;
|
||||
float brightTheresold;
|
||||
|
||||
PostHDR()
|
||||
{
|
||||
}
|
||||
~PostHDR()
|
||||
{
|
||||
SAFE_DELETE(g_brightPassTexture);
|
||||
SAFE_DELETE(g_downSampleTexture);
|
||||
SAFE_DELETE(g_horizontalBlur);
|
||||
SAFE_DELETE(g_verticalBlur);
|
||||
SAFE_DELETE(g_finalImage);
|
||||
SAFE_DELETE(g_lumLast);
|
||||
SAFE_DELETE(g_lumCur);
|
||||
SAFE_DELETE(downSampleZ);
|
||||
SAFE_DELETE(brightPassZ);
|
||||
|
||||
SAFE_DELETE(g_downSamplePS);
|
||||
SAFE_DELETE(g_brightPassPS);
|
||||
SAFE_DELETE(g_horizontalBlurPS);
|
||||
SAFE_DELETE(g_verticalBlurPS);
|
||||
SAFE_DELETE(g_downSample2x2PS);
|
||||
SAFE_DELETE(g_downSample3x3PS);
|
||||
SAFE_DELETE(g_resampleAvgLumExp);
|
||||
SAFE_DELETE(g_lumAdaptation);
|
||||
SAFE_DELETE(g_composePS);
|
||||
SAFE_DELETE(g_constBuffer);
|
||||
SAFE_DELETE(g_pointSampler);
|
||||
SAFE_DELETE(g_linearSampler);
|
||||
SAFE_DELETE(g_cbLumAdaptation);
|
||||
|
||||
for(int i = 0; i<NumLuminanceTextures; i++)
|
||||
{
|
||||
SAFE_DELETE(luminanceTextures[i]);
|
||||
SAFE_DELETE(luminanceTexturesZ[i]);
|
||||
}
|
||||
}
|
||||
ITexture2D* Execute(PostEffectParams& params)
|
||||
{
|
||||
g_renderer->SetPSTextureSampler(g_pointSampler, 0);
|
||||
g_renderer->SetPSTextureSampler(g_linearSampler, 1);
|
||||
|
||||
g_renderer->SetTargets(g_downSampleTexture, downSampleZ);
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, g_downSampleTexture->Width(), g_downSampleTexture->Height()));
|
||||
|
||||
//1'st pass - do down sampling
|
||||
g_renderer->SetPixelShader(g_downSamplePS);
|
||||
g_renderer->SetPSTexture(params.renderTarget, 0);
|
||||
src = params.renderTarget;
|
||||
srcZ = params.depthTarget;
|
||||
|
||||
Get4x4Offsets(params.renderTarget->Width(), params.renderTarget->Height(), offsets2);
|
||||
g_constBuffer->Update(offsets2, sizeof(LifeMath::float4)*16);
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
// g_downSamplePS.SetFloat4A("downSampleOffsets", offsets2);
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
|
||||
// g_downSampleTexture.ToFile("C:\\rt_1_downSample.jpg");
|
||||
|
||||
//2'nd measure scene luminance
|
||||
MeasureLuminance(g_downSampleTexture, params.depthTex);
|
||||
//3'rd calculate scene luminance adaptation
|
||||
//
|
||||
CalculateLuminanceAdaptation(params.timeElapsed);
|
||||
|
||||
//4'th step - bright pass
|
||||
g_renderer->UnbindResourcesPS();
|
||||
g_renderer->SetTargets(g_brightPassTexture, brightPassZ);
|
||||
g_renderer->SetPixelShader(g_brightPassPS);
|
||||
g_renderer->SetPSTexture(g_downSampleTexture, 0);
|
||||
g_renderer->SetPSTexture(g_lumCur, 1);
|
||||
g_renderer->SetPSTexture(params.depthTex, 2);
|
||||
//g_renderer.SetTextureSampler(g_pointSampler, 0);
|
||||
/// g_renderer.SetTextureSampler(g_pointSampler, 1);
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, g_brightPassTexture->Width(), g_brightPassTexture->Height()));
|
||||
g_renderer->SetScissorRectangle(LifeMath::Rect2i(0, 0, g_brightPassTexture->Width(), g_brightPassTexture->Height()));
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
|
||||
// g_brightPassTexture.ToFile("C:\\rt_2_brightPass.jpg");
|
||||
// g_renderer.SetTextureSampler(g_linearSampler, 0);
|
||||
|
||||
g_renderer->UnbindResourcesPS();
|
||||
|
||||
g_renderer->SetPSTextureSampler(samplerPointClamp, 0);
|
||||
g_renderer->SetPSTextureSampler(samplerPointClamp, 1);
|
||||
//5'th pass - do horizontal blur
|
||||
g_renderer->SetTargets(g_horizontalBlur, downSampleZ);
|
||||
g_renderer->SetPixelShader(g_horizontalBlurPS);
|
||||
g_renderer->SetPSTexture(g_brightPassTexture, 0);
|
||||
|
||||
GetBlurWeightedOffsets((float)NumBlurSamples, g_brightPassTexture->Width(), offsets3);
|
||||
g_constBuffer->Update(offsets3, sizeof(LifeMath::float4)*NumBlurSamples);
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
// g_horizontalBlurPS.SetFloat4A("hBlurOffsets", offsets3);
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, g_horizontalBlur->Width(), g_horizontalBlur->Height()));
|
||||
g_renderer->SetScissorRectangle(LifeMath::Rect2i(0, 0, g_horizontalBlur->Width(), g_horizontalBlur->Height()));
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
|
||||
// g_horizontalBlur.ToFile("C:\\rt_3_horBlur.jpg");
|
||||
//6'th pass - do vertical blur
|
||||
|
||||
g_renderer->UnbindResourcesPS();
|
||||
g_renderer->SetTargets(g_verticalBlur, downSampleZ);
|
||||
g_renderer->SetPixelShader(g_verticalBlurPS);
|
||||
g_renderer->SetPSTexture(g_horizontalBlur, 0);
|
||||
|
||||
GetBlurWeightedOffsets((float)NumBlurSamples, g_brightPassTexture->Height(), offsets3);
|
||||
//g_verticalBlurPS.SetFloat4A("vBlurOffsets", offsets4);
|
||||
|
||||
g_constBuffer->Update(offsets3, sizeof(LifeMath::float4)*NumBlurSamples);
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
|
||||
//7'th compose final image
|
||||
ComposeFinalImage(params.renderTarget, g_lumCur, g_verticalBlur);
|
||||
// g_finalImage.ToFile("C:\\rt_5_final.jpg");
|
||||
return g_finalImage;
|
||||
}
|
||||
void Init(SceneDescriptor& desc)
|
||||
{
|
||||
g_renderer = CG::me()->GetRenderer();
|
||||
|
||||
g_lumAdaptation = ResourceManager::me()->CompileUserShaderPS(String(_text("HDRLumAdaptation.psh")));
|
||||
|
||||
/* char laPs[] =
|
||||
"Texture2D tex0 : register(t7);"\
|
||||
"Texture2D tex1 : register(t8);"\
|
||||
"SamplerState linearSampler : register(s0);"\
|
||||
"cbuffer timeData : register(b11){float4 g_fElapsedTime : packoffset(c0);};"\
|
||||
"float4 main_PS(in float4 Position : SV_Position, in float2 texcoord : TEXCOORD0) : SV_Target{"\
|
||||
"float4 fAdaptedLum =tex0.Sample(linearSampler, float2(0.25f, 0.25f));"\
|
||||
"float4 fCurrentLum = tex1.Sample(linearSampler, float2(0.5f, 0.5f));"\
|
||||
"float fNewAdaptation = fAdaptedLum + (fCurrentLum - fAdaptedLum) * g_fElapsedTime.x;"\
|
||||
"return fAdaptedLum;}";
|
||||
|
||||
g_lumAdaptation = g_renderer->CompileUserShaderPS(laPs);*/
|
||||
|
||||
ISamplerDescription pscDesc(Clamp, Clamp, Clamp, MinMagMipPoint);
|
||||
samplerPointClamp = g_renderer->CreateTextureSampler(&pscDesc);
|
||||
|
||||
exposure = 0.72f;
|
||||
brightTheresold = 0.7f;
|
||||
|
||||
g_finalImage = g_renderer->CreateRenderTarget(desc.width, desc.height, FORMAT_R16G16B16A16_FLOAT);
|
||||
|
||||
//Bright pass texture
|
||||
int brightPassTextureWidth = desc.width / 4;
|
||||
int brightPassTextureHeight = desc.height / 4;
|
||||
g_brightPassTexture = g_renderer->CreateRenderTarget(brightPassTextureWidth,
|
||||
brightPassTextureHeight, FORMAT_R16G16B16A16_FLOAT);
|
||||
|
||||
brightPassZ = g_renderer->CreateDepthTarget(brightPassTextureWidth,
|
||||
brightPassTextureHeight, FORMAT_D16_UNORM);
|
||||
|
||||
//Down sample texture
|
||||
int downSampledTextureWidth = brightPassTextureWidth / 1;
|
||||
int downSampledTextureHeight = brightPassTextureHeight / 1;
|
||||
g_downSampleTexture = g_renderer->CreateRenderTarget(downSampledTextureWidth,
|
||||
downSampledTextureHeight, FORMAT_R16G16B16A16_FLOAT);
|
||||
|
||||
downSampleZ = g_renderer->CreateDepthTarget(downSampledTextureWidth,
|
||||
downSampledTextureHeight, FORMAT_D16_UNORM);
|
||||
|
||||
//Horizontal blur texture
|
||||
int horizontalBlurTextureWidth = downSampledTextureWidth;
|
||||
int horizontalBlurTextureHeight = downSampledTextureHeight;
|
||||
g_horizontalBlur = g_renderer->CreateRenderTarget(horizontalBlurTextureWidth,
|
||||
horizontalBlurTextureHeight, FORMAT_R16G16B16A16_FLOAT);
|
||||
|
||||
//Vertical blur texture
|
||||
int verticalBlurTextureWidth = horizontalBlurTextureWidth;
|
||||
int verticalBlurTextureHeight = horizontalBlurTextureHeight;
|
||||
g_verticalBlur = g_renderer->CreateRenderTarget(verticalBlurTextureWidth,
|
||||
verticalBlurTextureHeight, FORMAT_R16G16B16A16_FLOAT);
|
||||
|
||||
g_downSamplePS = ResourceManager::me()->CompileUserShaderPS(String(_text("DownSample.psh")));
|
||||
g_brightPassPS = ResourceManager::me()->CompileUserShaderPS(String(_text("BrightPass.psh")));
|
||||
g_horizontalBlurPS = ResourceManager::me()->CompileUserShaderPS(String(_text("HorizontalBlur.psh")));
|
||||
|
||||
g_verticalBlurPS = ResourceManager::me()->CompileUserShaderPS(String(_text("VerticalBlur.psh")));
|
||||
|
||||
g_resampleAvgLumExp = ResourceManager::me()->CompileUserShaderPS(String(_text("ResampleAvgLumExp.psh")));
|
||||
|
||||
//LC
|
||||
g_downSample2x2PS = ResourceManager::me()->CompileUserShaderPS(String(_text("SampleLumInitial.psh")));
|
||||
g_downSample3x3PS = ResourceManager::me()->CompileUserShaderPS(String(_text("DownSampleLum3.psh")));
|
||||
g_composePS = ResourceManager::me()->CompileUserShaderPS(String(_text("ComposeHDR.psh")));
|
||||
|
||||
g_constBuffer = g_renderer->CreateConstantBuffer(16 * 16*256);
|
||||
|
||||
g_cbLumAdaptation = g_renderer->CreateConstantBuffer(sizeof(LifeMath::float4));
|
||||
|
||||
CreateLuminanceTextures();
|
||||
|
||||
ISamplerDescription psDesc(Wrap, Wrap, Wrap, MinMagMipPoint);
|
||||
ISamplerDescription lsDesc(Wrap, Wrap, Wrap, Anisotropic);
|
||||
|
||||
g_pointSampler = g_renderer->CreateTextureSampler(&psDesc);
|
||||
g_linearSampler = g_renderer->CreateTextureSampler(&lsDesc);
|
||||
}
|
||||
private:
|
||||
static const int MAX_SAMPLES = 6;
|
||||
|
||||
//post effects
|
||||
IShader* g_downSamplePS;
|
||||
IShader* g_brightPassPS;
|
||||
IShader* g_horizontalBlurPS;
|
||||
IShader* g_verticalBlurPS;
|
||||
|
||||
//luminance calculation
|
||||
IShader* g_downSample2x2PS;
|
||||
IShader* g_downSample3x3PS;
|
||||
IShader* g_resampleAvgLumExp;
|
||||
IShader* g_lumAdaptation;
|
||||
|
||||
//final composing shader
|
||||
IShader* g_composePS;
|
||||
|
||||
static const int NumBlurSamples = 9;
|
||||
|
||||
//luminance calculator
|
||||
|
||||
IRenderer* g_renderer;
|
||||
|
||||
IConstantBuffer* g_constBuffer;
|
||||
ITextureSampler* g_pointSampler;
|
||||
ITextureSampler* g_linearSampler;
|
||||
|
||||
IConstantBuffer* g_cbLumAdaptation;
|
||||
|
||||
LifeMath::float4 offsets2[16];
|
||||
LifeMath::float4 offsets3[NumBlurSamples];
|
||||
LifeMath::float4 offsets[9];
|
||||
|
||||
void CreateLuminanceTextures()
|
||||
{
|
||||
for (int i = 0; i < NumLuminanceTextures; i++)
|
||||
{
|
||||
int iSampleLen = 1 << (2 * i);
|
||||
luminanceTextures[i] = g_renderer->CreateRenderTarget(iSampleLen, iSampleLen, FORMAT_R16G16B16A16_FLOAT);
|
||||
luminanceTexturesZ[i] = g_renderer->CreateDepthTarget(iSampleLen, iSampleLen, FORMAT_D16_UNORM);
|
||||
}
|
||||
|
||||
g_lumCur = g_renderer->CreateRenderTarget(1, 1, FORMAT_R16G16B16A16_FLOAT);
|
||||
g_lumLast = g_renderer->CreateRenderTarget(1, 1, FORMAT_R16G16B16A16_FLOAT);
|
||||
|
||||
|
||||
LifeMath::float4 clear_color(1,1,1,1);
|
||||
g_renderer->ClearRenderTarget(g_lumCur, &clear_color);
|
||||
g_renderer->ClearRenderTarget(g_lumLast, &clear_color);
|
||||
}
|
||||
|
||||
void Render2x2Pass(ITexture2D* srcTexture, ITexture2D* destTexture, ITexture2D* sceneDepth)
|
||||
{
|
||||
float tU, tV;
|
||||
tU = 1.0f / (3.0f * destTexture->Width());
|
||||
tV = 1.0f / (3.0f * destTexture->Height());
|
||||
|
||||
int index = 0;
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int y = -1; y <= 1; y++)
|
||||
{
|
||||
offsets[index].X = (float)x * tU;
|
||||
offsets[index].Y = (float)y * tV;
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
g_renderer->SetTargets(destTexture,luminanceTexturesZ[NumLuminanceTextures - 1]);
|
||||
g_renderer->SetPSTexture(srcTexture, 0);
|
||||
g_renderer->SetPSTexture(sceneDepth, 1);
|
||||
g_renderer->SetPixelShader(g_downSample2x2PS);
|
||||
|
||||
g_constBuffer->Update(&offsets, sizeof(LifeMath::float4)* 9);
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
|
||||
// With everything configured we can now render the first pass to the luminance textures.
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, destTexture->Width(), destTexture->Height()));
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
}
|
||||
void MeasureLuminance(ITexture2D* hdrTexture, ITexture2D* depth)
|
||||
{
|
||||
int curTex = NumLuminanceTextures - 1;
|
||||
Render2x2Pass(hdrTexture, luminanceTextures[curTex],depth);
|
||||
|
||||
curTex--;
|
||||
while (curTex > 0)
|
||||
{
|
||||
g_renderer->SetTargets(luminanceTextures[curTex], luminanceTexturesZ[curTex]);
|
||||
Get4x4Offsets(luminanceTextures[curTex + 1]->Width(), luminanceTextures[curTex + 1]->Height(), offsets2);
|
||||
|
||||
g_renderer->SetPixelShader(g_downSample3x3PS);
|
||||
g_renderer->SetPSTexture(luminanceTextures[curTex + 1], 0);
|
||||
|
||||
g_constBuffer->Update(offsets2, sizeof(LifeMath::float4)*16);
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, luminanceTextures[curTex]->Width(), luminanceTextures[curTex]->Height()));
|
||||
g_renderer->SetScissorRectangle(LifeMath::Rect2i(0, 0, luminanceTextures[curTex]->Width(), luminanceTextures[curTex]->Height()));
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
curTex--;
|
||||
}
|
||||
|
||||
g_renderer->SetTargets(luminanceTextures[0],luminanceTexturesZ[0]);
|
||||
g_renderer->SetPixelShader(g_resampleAvgLumExp);
|
||||
Get4x4Offsets(luminanceTextures[1]->Width(), luminanceTextures[1]->Height(), offsets2);
|
||||
g_constBuffer->Update(offsets2, sizeof(LifeMath::float4)*16);
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
|
||||
g_renderer->SetPSTexture(luminanceTextures[1], 0);
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, luminanceTextures[0]->Width(), luminanceTextures[0]->Height()));
|
||||
g_renderer->SetScissorRectangle(LifeMath::Rect2i(0, 0, luminanceTextures[0]->Width(), luminanceTextures[0]->Height()));
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
}
|
||||
void CalculateLuminanceAdaptation(float timeElapsed)
|
||||
{
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, 1, 1));
|
||||
g_renderer->SetScissorRectangle(LifeMath::Rect2i(0, 0, 1, 1));
|
||||
|
||||
g_renderer->UnbindResourcesPS();
|
||||
|
||||
ITexture2D* texSwap = g_lumLast;
|
||||
g_lumLast = g_lumCur;
|
||||
g_lumCur = texSwap;
|
||||
|
||||
g_renderer->SetTargets(g_lumCur, luminanceTexturesZ[0]);
|
||||
LifeMath::float4 clear_color(0,0,0,0);
|
||||
g_renderer->ClearRenderTarget(g_lumCur, &clear_color);
|
||||
g_renderer->SetPixelShader(g_lumAdaptation);
|
||||
|
||||
g_renderer->SetPSTexture(g_lumLast, luminanceTextures[0], 7,2);
|
||||
// g_renderer->SetPSTexture(rgba.ptr(), luminanceTextures[0], 7,2);
|
||||
|
||||
if(timeElapsed <0.0000001f)
|
||||
timeElapsed = 0.0000001f;
|
||||
|
||||
if(timeElapsed > 1.0f)
|
||||
timeElapsed = 1.0f;
|
||||
|
||||
float val = (1.0f - (pow(0.98f, 30.0f * timeElapsed)));
|
||||
LifeMath::float4 time(val, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
g_cbLumAdaptation->Update(&time, sizeof(LifeMath::float4));
|
||||
g_renderer->SetPSConstantBuffer(g_cbLumAdaptation, 11);
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
}
|
||||
void ComposeFinalImage(ITexture2D* hdrTexture, ITexture2D* luminanceTexture, ITexture2D* bloomTexture)
|
||||
{
|
||||
g_renderer->SetPSTextureSampler(g_linearSampler, 1);
|
||||
g_renderer->SetTargets(g_finalImage, srcZ);
|
||||
|
||||
g_renderer->SetPixelShader(g_composePS);
|
||||
g_renderer->SetPSTexture(hdrTexture, 0);
|
||||
g_renderer->SetPSTexture(bloomTexture, 1);
|
||||
g_renderer->SetPSTextureNULL(2);
|
||||
g_renderer->SetPSTexture(luminanceTexture, 3);
|
||||
|
||||
float g_fKeyValue = 0.05f;
|
||||
LifeMath::float4 key(g_fKeyValue, 0, 0, 0);
|
||||
g_constBuffer->Update(key, sizeof(LifeMath::float4));
|
||||
g_renderer->SetPSConstantBuffer(g_constBuffer, 0);
|
||||
// g_composePS.SetFloat("g_fMiddleGray", g_fKeyValue);
|
||||
|
||||
g_renderer->SetViewport(LifeMath::Rect2i(0, 0, g_finalImage->Width(), g_finalImage->Height()));
|
||||
|
||||
g_renderer->SetScissorRectangle(LifeMath::Rect2i(0, 0, g_finalImage->Width(), g_finalImage->Height()));
|
||||
|
||||
g_renderer->RenderToTextureNoPs();
|
||||
|
||||
g_renderer->UnbindResourcesPS();
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // PostHDR_h__
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "render/PostSSAO.h"
|
||||
#include "IScene.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
struct QUAD_VERT
|
||||
{
|
||||
LifeMath::float4 position;
|
||||
LifeMath::float2 texcoord;
|
||||
};
|
||||
|
||||
PostSSAO::PostSSAO(IScene* scene, QUALITY effectQuality)
|
||||
{
|
||||
pScene = scene;
|
||||
pRenderer = CG::me()->GetRenderer();
|
||||
|
||||
ssaoSize = pScene->getOutputSize();
|
||||
|
||||
int divider = 1;
|
||||
|
||||
//adjust ssao texture size by quality
|
||||
switch(effectQuality)
|
||||
{
|
||||
case Q_MED:
|
||||
divider = 2;
|
||||
break;
|
||||
case Q_LOW:
|
||||
divider = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
ssaoSize /= divider;
|
||||
|
||||
ssaoTex = pRenderer->CreateRenderTarget(ssaoSize.X, ssaoSize.Y, FORMAT_R8_UNORM);
|
||||
ssaoBlur = pRenderer->CreateRenderTarget(ssaoSize.X, ssaoSize.Y, FORMAT_R8_UNORM);
|
||||
|
||||
psRender = ResourceManager::me()->CompileUserShaderPS(String(_text("SSAO.psh")));
|
||||
vs = ResourceManager::me()->CompileUserShaderVS(String(_text("SSAO.vsh")));
|
||||
psBlur = ResourceManager::me()->CompileUserShaderPS(String(_text("SSAO_BLUR.psh")));
|
||||
|
||||
ISamplerDescription pscDesc(Clamp, Clamp, Clamp, MinMagMipPoint);
|
||||
ISamplerDescription lsDesc(Wrap, Wrap, Wrap, MinMagMipLinear);
|
||||
|
||||
linearSampler = CG::me()->GetRenderer()->CreateTextureSampler(&lsDesc);
|
||||
pointSamplerClamp = CG::me()->GetRenderer()->CreateTextureSampler(&pscDesc);
|
||||
|
||||
depthState = pRenderer->CreateDSState(false, false, COMPARISON_NEVER);
|
||||
|
||||
ssaoRandom = ResourceManager::me()->GetTexture(String(_text("root/Data/Textures/ssao_random.bmp")));
|
||||
}
|
||||
void PostSSAO::process(IConstantBuffer* camera, ITexture2D* sceneGbuf, ITexture2D* sceneDepthTarget)
|
||||
{
|
||||
pRenderer->UnbindRenderTargets();
|
||||
|
||||
//pRenderer->SetPSConstantBuffer(cbGlobal, 0);
|
||||
//pRenderer->SetVSConstantBuffer(cbGlobal, 0);
|
||||
|
||||
pRenderer->SetPSTextureSampler(pointSamplerClamp, 0);
|
||||
pRenderer->SetPSTextureSampler(linearSampler, 1);
|
||||
pRenderer->SetVSConstantBuffer(camera, 1);
|
||||
pRenderer->SetPSConstantBuffer(camera, 1);
|
||||
pRenderer->SetViewport(LifeMath::Rect2i(0, 0, ssaoSize.X, ssaoSize.Y));
|
||||
|
||||
pRenderer->SetDepthStencilState(depthState);
|
||||
|
||||
// renderer->SetBlendState(lppBlend);
|
||||
pRenderer->SetVertexShader(vs);
|
||||
pRenderer->SetPixelShader(psRender);
|
||||
|
||||
//pRenderer->ClearRenderTarget(ssaoTex, &color );
|
||||
pRenderer->SetTargets(ssaoTex, sceneDepthTarget);
|
||||
pRenderer->SetPSTexture(sceneGbuf, 0);
|
||||
pRenderer->SetPSTexture(ssaoRandom.ptr(), 1);
|
||||
|
||||
pRenderer->RenderToTextureNoShader();
|
||||
|
||||
pRenderer->SetPSTextureSampler(linearSampler, 0);
|
||||
pRenderer->SetPSTextureSampler(pointSamplerClamp, 1);
|
||||
|
||||
//blur ssao
|
||||
pRenderer->UnbindRenderTargets();
|
||||
pRenderer->SetTargets(ssaoBlur, sceneDepthTarget);
|
||||
|
||||
pRenderer->SetPSTexture(ssaoTex, 0);
|
||||
pRenderer->SetPSTexture(sceneGbuf, 9);
|
||||
pRenderer->SetPixelShader(psBlur);
|
||||
pRenderer->RenderToTextureNoShader();
|
||||
}
|
||||
ITexture2D* PostSSAO::getTexture()
|
||||
{
|
||||
return ssaoBlur;
|
||||
}
|
||||
PostSSAO::~PostSSAO()
|
||||
{
|
||||
vs->Release();
|
||||
psBlur->Release();
|
||||
psRender->Release();
|
||||
ssaoTex->Release();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef PostSSAO_h__
|
||||
#define PostSSAO_h__
|
||||
|
||||
#include "render/IRenderer.h"
|
||||
#include "Globals.h"
|
||||
#include "math/LifeMath.h"
|
||||
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IScene;
|
||||
class PostSSAO
|
||||
{
|
||||
private:
|
||||
IRenderer* pRenderer;
|
||||
IScene* pScene;
|
||||
IShader* vs;
|
||||
IShader* psRender;
|
||||
IShader* psBlur;
|
||||
ITexture2D* ssaoTex;
|
||||
ITexture2D* ssaoBlur;
|
||||
texture_ptr ssaoRandom;
|
||||
ITextureSampler* pointSamplerClamp;
|
||||
IDepthStencilState* depthState;
|
||||
ITextureSampler* linearSampler;
|
||||
LifeMath::Vec2i ssaoSize;
|
||||
public:
|
||||
LifeMath::Vec2i getSize()
|
||||
{
|
||||
return ssaoSize;
|
||||
}
|
||||
ITexture2D* getTexture();
|
||||
void process(IConstantBuffer* camera, ITexture2D* sceneGbuf, ITexture2D* sceneDepthTarget);
|
||||
PostSSAO(IScene* scene, QUALITY effectQuality);
|
||||
~PostSSAO();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PostSSAO_h__
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef PosteffectManager_h__
|
||||
#define PosteffectManager_h__
|
||||
#include <vector>
|
||||
#include "render/PostEffect.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class PostEffectManager
|
||||
{
|
||||
private:
|
||||
std::vector<PostEffect*> postEffects;
|
||||
SceneDescriptor descriptor;
|
||||
public:
|
||||
PostEffectManager()
|
||||
{
|
||||
}
|
||||
~PostEffectManager()
|
||||
{
|
||||
}
|
||||
void Init(SceneDescriptor& desc)
|
||||
{
|
||||
descriptor = desc;
|
||||
}
|
||||
|
||||
void Add(PostEffect* effect)
|
||||
{
|
||||
postEffects.push_back(effect);
|
||||
}
|
||||
|
||||
ITexture2D* Execute(ITexture2D* source, ITexture2D* depth, ITexture2D* depthTex, float dt)
|
||||
{
|
||||
ITexture2D* tmpResult = (ITexture2D*)0;
|
||||
|
||||
for (UINT i = 0; i < postEffects.size(); i++)
|
||||
{
|
||||
PostEffectParams params;
|
||||
params.timeElapsed = dt;
|
||||
params.depthTarget = depth;
|
||||
params.depthTex = depthTex;
|
||||
|
||||
if (tmpResult)
|
||||
{
|
||||
params.renderTarget = tmpResult;
|
||||
tmpResult = postEffects[i]->Execute(params);
|
||||
}
|
||||
else
|
||||
{
|
||||
params.renderTarget = source;
|
||||
tmpResult = postEffects[i]->Execute(params);
|
||||
}
|
||||
}
|
||||
return tmpResult;
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // PosteffectManager_h__
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef RENDERER_PARAMETERS
|
||||
#define RENDERER_PARAMETERS
|
||||
#include "Build.h"
|
||||
#include <IRenderWindow.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class LIFE_EXPORTS RenderParams
|
||||
{
|
||||
public:
|
||||
RenderParams(){}
|
||||
~RenderParams(){}
|
||||
bool ForceWideScreen;
|
||||
bool AllowSwitchToSoftware;
|
||||
RenderParams(bool allowSoftware, bool fwdScrn)
|
||||
{
|
||||
AllowSwitchToSoftware = allowSoftware;
|
||||
ForceWideScreen = fwdScrn;
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
#pragma once
|
||||
#include "render/RendererDX10.h"
|
||||
#include <d3d10.h>
|
||||
#include <D3DX10.h>
|
||||
namespace Video
|
||||
{
|
||||
HRESULT RendererDX10::Open(RenderParams params)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
g_params = params;
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC sd;
|
||||
ZeroMemory(&sd, sizeof(sd));
|
||||
|
||||
//fill swap chain description parameters
|
||||
sd.BufferCount = 1;
|
||||
sd.BufferDesc.Width = g_params.ScreenWidth;
|
||||
sd.BufferDesc.Height = g_params.ScreenHeight;
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
sd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.OutputWindow = (HWND)params.WindowHandle;
|
||||
sd.Windowed = TRUE;
|
||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
|
||||
D3D10_DRIVER_TYPE drivers[]=
|
||||
{
|
||||
D3D10_DRIVER_TYPE_HARDWARE,
|
||||
D3D10_DRIVER_TYPE_WARP
|
||||
};
|
||||
int numDrivers = sizeof(drivers) / sizeof(drivers[0]);
|
||||
|
||||
for(int i = 0; i< numDrivers; i++)
|
||||
{
|
||||
g_driverType = drivers[i];
|
||||
hr = D3D10CreateDeviceAndSwapChain(NULL,g_driverType,NULL,D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
break;
|
||||
}
|
||||
|
||||
if(FAILED(hr))
|
||||
return hr;
|
||||
|
||||
ID3D10Texture2D* pBuffer;
|
||||
hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&pBuffer);
|
||||
if(FAILED(hr))
|
||||
return hr;
|
||||
|
||||
hr = g_pDevice->CreateRenderTargetView(pBuffer, NULL, &g_pBackBuffer);
|
||||
if(FAILED(hr))
|
||||
return hr;
|
||||
|
||||
g_pDevice->OMSetRenderTargets(0, &g_pBackBuffer, NULL);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void RendererDX10::Close()
|
||||
{
|
||||
if(g_pDevice)
|
||||
{
|
||||
float clearColor[4] = {1.0f, 1.0f,0.0f,1.0f};
|
||||
g_pDevice->ClearRenderTargetView(g_pBackBuffer, clearColor);
|
||||
|
||||
g_pSwapChain->Present(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
void RendererDX10::ClearBuffers(int flags, int rtColor, float zValue, float stencilValue)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef RENDERER_D3D10
|
||||
#define RENDERER_D3D10
|
||||
|
||||
|
||||
|
||||
namespace Video
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,183 @@
|
||||
#ifndef RendererSoftware_h__
|
||||
#define RendererSoftware_h__
|
||||
|
||||
#include "Globals.h"
|
||||
#include "render/IRenderer.h"
|
||||
#include "math/LifeMath.h"
|
||||
#include <Build.h>
|
||||
#include "render/software/ITexture2DS.h"
|
||||
#include "render/software/IVertexBufferS.h"
|
||||
#include "render/software/IIndexBufferS.h"
|
||||
|
||||
#include "render/RenderParams.h"
|
||||
#include <PluginServer.h>
|
||||
#include "render/software/IVertexShaderS.h"
|
||||
#include "render/software/IPixelShaderS.h"
|
||||
#include "render/software/IInputLayoutS.h"
|
||||
#include "render/software/IBlendStateS.h"
|
||||
#include "math/LifeMath.h"
|
||||
#include "render/software/IRasterizerStateS.h"
|
||||
#include "render/software/ITextureSamplerS.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class RendererSoftware : public IRenderer
|
||||
{
|
||||
public:
|
||||
RendererSoftware(){};
|
||||
~RendererSoftware(){printf("Destroying renderer...");Close();};
|
||||
virtual HRESULT Open(RenderParams params);
|
||||
virtual void Close();
|
||||
virtual void ClearBuffers(int flags, int rtColor, float zValue, int stencilValue);
|
||||
virtual const std::string &GetRendererName() const {
|
||||
static String sName("LifeEngine software graphics driver");
|
||||
return sName;
|
||||
}
|
||||
ITexture2D* CreateRenderTarget(int width, int height, int format);
|
||||
ITexture2D* CreateDepthTarget(int width, int height, int format);
|
||||
ITexture2D* LoadTexture2D(LifeCore::IDataStream* src);
|
||||
ITexture2D* CreateTexture2D(int canRead, int canWrite, int width, int height, int format);
|
||||
void RenderToTexture();
|
||||
void RenderToTextureNoPs();
|
||||
void RenderToTextureNoShader();
|
||||
IVertexBuffer* CreateVertexBuffer(int size, void* data, int stride);
|
||||
IVertexBuffer* CreateVertexBufferDynamic(int size, int stride);
|
||||
IIndexBuffer* CreateIndexBuffer(int size, void* data, int sixteenBit);
|
||||
IIndexBuffer* CreateIndexBufferDynamic(int size, bool sixteenBit);
|
||||
IInputLayout* CreateInputLayout(IInputElement* elements, int elementCount, IShader* vertexShader);
|
||||
|
||||
IShader* CompileVertexShader(LifeCore::IDataStream* stream);
|
||||
IShader* CompileVertexShader(LifeCore::IDataStream* stream, std::vector<IMacroDefine>* defines);
|
||||
|
||||
IShader* CompilePixelShader(LifeCore::IDataStream* stream);
|
||||
IShader* CompilePixelShader(LifeCore::IDataStream* stream, std::vector<IMacroDefine>* defines);
|
||||
|
||||
IConstantBuffer* CreateConstantBuffer(int size);
|
||||
|
||||
void SetVSConstantBuffer(IConstantBuffer* buffer, int slot);
|
||||
void SetPSConstantBuffer(IConstantBuffer* buffer, int slot);
|
||||
|
||||
void SetInputLayout(IInputLayout* layout);
|
||||
|
||||
void SwapBuffers();
|
||||
void RenderMesh(IMesh* mesh);
|
||||
|
||||
void SetCamera(Camera* camera);
|
||||
void SetMaterial(IMaterial* material);
|
||||
|
||||
void SetTargets(ITexture2D* colorTarget, ITexture2D* depthTarget);
|
||||
|
||||
void SetDefaultTargets();
|
||||
|
||||
void SetVertexBuffer(IVertexBuffer* vb);
|
||||
void SetIndexBuffer(IIndexBuffer* ib);
|
||||
|
||||
void SetPrimitiveTopology(PRIMITIVE_TOPOLOGY topology);
|
||||
|
||||
void DrawIndexed(int offset, int length);
|
||||
|
||||
void SetVertexShader(IShader* shader);
|
||||
void SetPixelShader(IShader* shader);
|
||||
|
||||
void SetPSTexture(ITexture2D* texture, int slot);
|
||||
void SetVSTexture(ITexture2D* texture, int slot);
|
||||
|
||||
void UnbindResourcesPS();
|
||||
|
||||
void Draw(int vertexCount, int vertexOffset);
|
||||
|
||||
IBlendState* CreateBlendState(bool blendEnable, bool atocEnable, BLEND_OP blendOperation, BLEND_SRC srcBlend, BLEND_SRC dstBlend, uint8 colorMask);
|
||||
|
||||
void SetBlendState(IBlendState* state);
|
||||
|
||||
IDepthStencilState* CreateDSState(bool zEnable, bool zWrite, COMPARISON_FUNC zFunc);
|
||||
|
||||
void SetDepthStencilState(IDepthStencilState* state);
|
||||
|
||||
void SetScissorRectangle(const Rectangle2D& rect);
|
||||
|
||||
void SetViewport(const Rectangle2D& rect);
|
||||
|
||||
ITexture2D* CreateRenderTargetCube(int size, int format);
|
||||
|
||||
ITexture2D* CreateDepthTargetCube(int width, int format);
|
||||
|
||||
void SetPSTextureNULL(int slot);
|
||||
|
||||
void SetPSTextureSampler(ITextureSampler* sampler, int slot);
|
||||
|
||||
ITextureSampler* CreateTextureSampler(ISamplerDescription* desc);
|
||||
|
||||
void SetColorTarget(ITexture2D* colorTarget);
|
||||
void SetDepthTarget(ITexture2D* depthTarget);
|
||||
|
||||
void VerticalBlur(ITexture2D* src, ITexture2D* dst, int numSamples);
|
||||
|
||||
void SetPSTexture(ITexture2D* texture, ITexture2D* texture2, int start, int count);
|
||||
|
||||
IShader* CompileUserShaderPS(char* data);
|
||||
|
||||
IRasterizerState* CreateRasterizerState(FILL_MODE mode);
|
||||
|
||||
void DrawIndexed(int offset, int length, int baseVertex);
|
||||
|
||||
void SetRasterizerState(IRasterizerState* state);
|
||||
|
||||
void SetTargets(ITexture2D** colorTargets, int targetCount, ITexture2D* depthTarget);
|
||||
|
||||
void UnbindRenderTargets();
|
||||
|
||||
void SetVertexBuffer(IVertexBuffer** vb, int count);
|
||||
|
||||
void DrawIndexedInstanced(int offset, int length, int instanceCnt);
|
||||
|
||||
void DrawIndexedInstanced(int offset, int length, int baseVertex, int instanceCnt);
|
||||
|
||||
void SetViewport(const Rectangle2D& rect, float minDepth, float maxDepth);
|
||||
|
||||
IRasterizerState* CreateRasterizerState(FILL_MODE mode, CULL_MODE cmode);
|
||||
|
||||
void BeginCleanup();
|
||||
void EndCleanup();
|
||||
|
||||
void ClearRenderTarget(ITexture2D* tex, LifeMath::float4* color);
|
||||
void ClearDepthStencil(ITexture2D* tex, float zValue, int stencilValue);
|
||||
|
||||
int GetDisplayModes(LifeCore::DisplayMode** modeList);
|
||||
|
||||
private:
|
||||
struct SimpleVertex
|
||||
{
|
||||
LifeMath::float4 Pos;
|
||||
LifeMath::float2 TC;
|
||||
};
|
||||
//ID3D11RasterizerState* rState;
|
||||
// ID3D11Device* g_pDevice;
|
||||
//ID3D11DeviceContext* g_pDeviceContext;
|
||||
//IDXGISwapChain* g_pSwapChain;
|
||||
//ID3D11RenderTargetView* g_pBackBuffer;
|
||||
//ID3D11DepthStencilView* g_pDepthBuffer;
|
||||
|
||||
// ID3D11RenderTargetView* currentBackBuffer;
|
||||
// ID3D11DepthStencilView* currentDepthBuffer;
|
||||
|
||||
//D3D_FEATURE_LEVEL g_pFeatureLevel;
|
||||
//D3D_DRIVER_TYPE g_driverType;
|
||||
LifeMath::float4x4 wvp;
|
||||
//ID3D11Buffer* fsQuadBuffer;
|
||||
//ID3D11PixelShader* psQuad;
|
||||
//ID3D11VertexShader* vsQuad;
|
||||
//ID3D11InputLayout* fsQuadLayout;
|
||||
//ID3D11SamplerState* samplerLinear;
|
||||
//ID3D11SamplerState* samplerPoint;
|
||||
//ID3D11Texture2D* pBuffer;
|
||||
//ID3D11Texture2D* dBuf;
|
||||
Camera* cam;
|
||||
|
||||
//ID3D11PixelShader* psVerticalBlur;
|
||||
|
||||
IConstantBuffer* vbBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // RendererSoftware_h__
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef IBlendState11_h__
|
||||
#define IBlendState11_h__
|
||||
|
||||
#include "render/IBlendState.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IBlendState11 : public IBlendState
|
||||
{
|
||||
private:
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
|
||||
public:
|
||||
ID3D11BlendState* state;
|
||||
IBlendState11(ID3D11Device* _device, ID3D11BlendState* _state)
|
||||
{
|
||||
device = _device;
|
||||
device->GetImmediateContext(&context);
|
||||
state = _state;
|
||||
}
|
||||
~IBlendState11()
|
||||
{
|
||||
SAFE_RELEASE(state);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IBlendState11_h__
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "render/dx11/IConstantBuffer11.h"
|
||||
#include <stdio.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
void IConstantBuffer11::Update(void* pData, int dataLength)
|
||||
{
|
||||
context->Map(buffer,0, D3D11_MAP_WRITE_DISCARD, 0, &subresource);
|
||||
memcpy(subresource.pData, pData, dataLength);
|
||||
context->Unmap(buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef IConstantBuffer11_h__
|
||||
#define IConstantBuffer11_h__
|
||||
|
||||
#include "render/IConstantBuffer.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "Globals.h"
|
||||
#include <log/CLog.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IConstantBuffer11 : public IConstantBuffer
|
||||
{
|
||||
public:
|
||||
ID3D11Buffer* buffer;
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
int size;
|
||||
D3D11_MAPPED_SUBRESOURCE subresource;
|
||||
|
||||
IConstantBuffer11(ID3D11Device* _device, int _size)
|
||||
{
|
||||
if((_size % 0x10) !=0 )
|
||||
{
|
||||
LOG_ERROR("Buffer size must be multiple of 16", "IConstantBuffer11", "ctor()");
|
||||
return;
|
||||
}
|
||||
device = _device;
|
||||
size = _size;
|
||||
|
||||
D3D11_BUFFER_DESC desc = {0};
|
||||
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.ByteWidth = _size;
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
|
||||
HRESULT hr = device->CreateBuffer(&desc,NULL, &buffer);
|
||||
|
||||
device->GetImmediateContext(&context);
|
||||
/*
|
||||
BufferDescription desc = new BufferDescription();
|
||||
desc.BindFlags = BindFlags.ConstantBuffer;
|
||||
desc.CpuAccessFlags = CpuAccessFlags.Write;
|
||||
desc.OptionFlags = ResourceOptionFlags.None;
|
||||
desc.SizeInBytes = size;
|
||||
desc.StructureByteStride = 0;
|
||||
desc.Usage = D3D11.ResourceUsage.Dynamic;
|
||||
|
||||
buffer = new D3D11.Buffer(device, desc);*/
|
||||
}
|
||||
~IConstantBuffer11()
|
||||
{
|
||||
SAFE_RELEASE(buffer);
|
||||
context = NULL;
|
||||
}
|
||||
void Update(void* pData, int dataLength);
|
||||
};
|
||||
}
|
||||
#endif // IConstantBuffer11_h__
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef IDepthStencilState11_h__
|
||||
#define IDepthStencilState11_h__
|
||||
|
||||
#include "render/IDepthStencilState.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IDepthStencilState11 : public IDepthStencilState
|
||||
{
|
||||
private:
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
public:
|
||||
ID3D11DepthStencilState* state;
|
||||
IDepthStencilState11(ID3D11Device* _device, ID3D11DepthStencilState* _state)
|
||||
{
|
||||
device = _device;
|
||||
device->GetImmediateContext(&context);
|
||||
state = _state;
|
||||
}
|
||||
~IDepthStencilState11()
|
||||
{
|
||||
SAFE_RELEASE(state);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IDepthStencilState11_h__
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef I_INDEX_BUFFER11_H__
|
||||
#define I_INDEX_BUFFER11_H__
|
||||
|
||||
#include "render/IIndexBuffer.h"
|
||||
#include "Globals.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "IMemoryStream.h"
|
||||
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IIndexBuffer11 : public IIndexBuffer
|
||||
{
|
||||
public:
|
||||
ID3D11Buffer* ib;
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
D3D11_MAPPED_SUBRESOURCE* mappedData;
|
||||
LifeCore::IMemoryStream stm;
|
||||
|
||||
~IIndexBuffer11()
|
||||
{
|
||||
SAFE_RELEASE(ib);
|
||||
}
|
||||
IIndexBuffer11(ID3D11Device* _device, void* pBuffer, int _size, int _sixteenBit, int staging)
|
||||
{
|
||||
device = _device;
|
||||
length = _size;
|
||||
isShort = _sixteenBit;
|
||||
|
||||
//g_desc = new BufferDescription(size, D3D11.ResourceUsage.Default,
|
||||
// BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
|
||||
D3D11_BUFFER_DESC bd;
|
||||
ZeroMemory( &bd, sizeof(bd) );
|
||||
if(pBuffer)
|
||||
bd.Usage = D3D11_USAGE_DEFAULT;
|
||||
else
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
if(staging)
|
||||
bd.Usage = D3D11_USAGE_STAGING;
|
||||
|
||||
bd.ByteWidth = _size;
|
||||
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
|
||||
if(bd.Usage == D3D11_USAGE_DEFAULT)
|
||||
bd.CPUAccessFlags = 0;
|
||||
else if(bd.Usage == D3D11_USAGE_DYNAMIC)
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
else if(bd.Usage == D3D11_USAGE_STAGING)
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
|
||||
|
||||
if(pBuffer)
|
||||
{
|
||||
D3D11_SUBRESOURCE_DATA InitData;
|
||||
ZeroMemory( &InitData, sizeof(InitData) );
|
||||
InitData.pSysMem = pBuffer;
|
||||
|
||||
device->CreateBuffer( &bd, &InitData, &ib );
|
||||
}
|
||||
else
|
||||
device->CreateBuffer( &bd, NULL, &ib );
|
||||
device->GetImmediateContext(&context);
|
||||
//if( FAILED( hr ) )
|
||||
// return hr;
|
||||
}
|
||||
LifeCore::IDataStream* Map(int offset, int flags)
|
||||
{
|
||||
D3D11_MAP mapFlags;
|
||||
|
||||
if (flags & LF_Discard)
|
||||
mapFlags = D3D11_MAP_WRITE_DISCARD;
|
||||
else if ((flags & LF_NoOverwrite))
|
||||
mapFlags = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
|
||||
else if ((flags & LF_ReadOnly))
|
||||
mapFlags = D3D11_MAP_READ;
|
||||
|
||||
else if (flags == LF_None)
|
||||
mapFlags = D3D11_MAP_READ_WRITE;
|
||||
else
|
||||
mapFlags = D3D11_MAP_WRITE;
|
||||
|
||||
context->Map(ib,0, mapFlags,0, mappedData);
|
||||
stm.Reset(((char*)mappedData->pData) + offset, length);
|
||||
return &stm;
|
||||
}
|
||||
void Unmap()
|
||||
{
|
||||
context->Unmap(ib, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef IInputLayout11_h__
|
||||
#define IInputLayout11_h__
|
||||
|
||||
#include "render/IInputLayout.h"
|
||||
#include "Globals.h"
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IInputLayout11 : public IInputLayout
|
||||
{
|
||||
public:
|
||||
ID3D11InputLayout* Decl;
|
||||
IInputLayout11(){}
|
||||
~IInputLayout11()
|
||||
{
|
||||
SAFE_RELEASE(Decl);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IInputLayout11_h__
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef IPixelShader11_h__
|
||||
#define IPixelShader11_h__
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "render/IShader.h"
|
||||
#include "render/IMacroDefine.h"
|
||||
#include <vector>
|
||||
#include "Globals.h"
|
||||
#include "D3Dcompiler.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IPixelShader11 : public IShader
|
||||
{
|
||||
public:
|
||||
ID3D11PixelShader* g_shader;
|
||||
ID3DBlob* g_bytecode;
|
||||
ID3D11Device* g_device;
|
||||
IPixelShader11(ID3D11Device* device)
|
||||
{
|
||||
g_device = device;
|
||||
}
|
||||
~IPixelShader11()
|
||||
{
|
||||
SAFE_RELEASE(g_bytecode);
|
||||
SAFE_RELEASE(g_shader);
|
||||
}
|
||||
void* Disassemble()
|
||||
{
|
||||
/*ID3D10Blob* errorMsg = NULL;
|
||||
D3D10DisassembleShader(g_bytecode->GetBufferPointer(), g_bytecode->GetBufferSize(),TRUE, "OLOLO", &errorMsg);
|
||||
return errorMsg->GetBufferPointer();*/
|
||||
return 0;
|
||||
}
|
||||
SHADER_TYPE getShaderType()
|
||||
{
|
||||
return ST_PS;
|
||||
}
|
||||
char* GetByteCode()
|
||||
{
|
||||
return (char*)0;
|
||||
}
|
||||
void Compile(LifeCore::IDataStreamPtr stream, std::vector<IMacroDefine>* defines)
|
||||
{
|
||||
char* shader = new char[stream->Length()];
|
||||
stream->Read(shader, stream->Length());
|
||||
Compile(shader, stream->Length(), defines);
|
||||
delete[]shader;
|
||||
}
|
||||
void Compile(const char* pData, int length, std::vector<IMacroDefine>* defines)
|
||||
{
|
||||
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
|
||||
#ifdef _DEBUG
|
||||
dwShaderFlags |= D3DCOMPILE_DEBUG;
|
||||
#endif
|
||||
|
||||
HRESULT hr;
|
||||
g_bytecode = NULL;
|
||||
|
||||
// char* ololo = new char[10*1024*1024];
|
||||
// void* lol = malloc(10*1024*1024);
|
||||
ID3D10Blob* errorMsg = NULL;
|
||||
|
||||
if(!defines)
|
||||
{
|
||||
hr = D3DX11CompileFromMemory(pData, length, "system_shader", NULL, NULL, "main_PS", "ps_5_0",dwShaderFlags,0,NULL, &g_bytecode,&errorMsg, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//create macro
|
||||
D3D10_SHADER_MACRO* macros = new D3D10_SHADER_MACRO[defines->size() + 1];
|
||||
int cnt = defines->size();
|
||||
for(int i = 0; i < cnt; i++)
|
||||
{
|
||||
macros[i].Definition = defines[0][i].definition.c_str();
|
||||
macros[i].Name = defines[0][i].name.c_str();
|
||||
}
|
||||
D3D10_SHADER_MACRO m;
|
||||
m.Definition = NULL;
|
||||
m.Name = NULL;
|
||||
macros[cnt] = m;
|
||||
|
||||
hr = D3DX11CompileFromMemory(pData, length, "system_shader", macros, NULL, "main_PS", "ps_5_0",dwShaderFlags,0,NULL, &g_bytecode, &errorMsg, NULL);
|
||||
delete[] macros;
|
||||
}
|
||||
|
||||
if(hr != S_OK)
|
||||
{
|
||||
printf("SHADER COMPILE ERROR: %s", errorMsg->GetBufferPointer());
|
||||
}
|
||||
SAFE_RELEASE(errorMsg);
|
||||
|
||||
hr = g_device->CreatePixelShader(g_bytecode->GetBufferPointer(), g_bytecode->GetBufferSize(), NULL, &g_shader);
|
||||
SAFE_RELEASE(g_bytecode);
|
||||
}
|
||||
void Load(LifeCore::IDataStreamPtr src)
|
||||
{
|
||||
printf("Load VS is not implemented: %i\n", src->Length());
|
||||
}
|
||||
void CompleteAsyncRequest(IResource* source)
|
||||
{
|
||||
// printf("VS async not implemented: %s\n", source->Name.c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IPixelShader11_h__
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef IRasterizerState11_h__
|
||||
#define IRasterizerState11_h__
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "render/IRasterizerState.h"
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IRasterizerState11 : public IRasterizerState
|
||||
{
|
||||
public:
|
||||
ID3D11Device* device;
|
||||
ID3D11RasterizerState* state;
|
||||
|
||||
IRasterizerState11(FILL_MODE mode, ID3D11Device* _device)
|
||||
{
|
||||
device = _device;
|
||||
|
||||
D3D11_RASTERIZER_DESC rsDesc;
|
||||
rsDesc.AntialiasedLineEnable = false;
|
||||
rsDesc.CullMode = D3D11_CULL_BACK;
|
||||
rsDesc.DepthBias = 0;
|
||||
rsDesc.DepthBiasClamp = 0.0f;
|
||||
rsDesc.SlopeScaledDepthBias = 0.0f;
|
||||
rsDesc.DepthClipEnable = TRUE;
|
||||
rsDesc.FillMode = static_cast<D3D11_FILL_MODE>(mode);
|
||||
rsDesc.FrontCounterClockwise = FALSE;
|
||||
rsDesc.MultisampleEnable = FALSE;
|
||||
rsDesc.ScissorEnable = TRUE;
|
||||
|
||||
device->CreateRasterizerState(&rsDesc, &state);
|
||||
}
|
||||
IRasterizerState11(FILL_MODE mode, ID3D11Device* _device, CULL_MODE cmode)
|
||||
{
|
||||
device = _device;
|
||||
|
||||
D3D11_RASTERIZER_DESC rsDesc;
|
||||
rsDesc.AntialiasedLineEnable = false;
|
||||
rsDesc.CullMode = static_cast<D3D11_CULL_MODE>(cmode);
|
||||
rsDesc.DepthBias = 0;
|
||||
rsDesc.DepthBiasClamp = 0.0f;
|
||||
rsDesc.SlopeScaledDepthBias = 0.0f;
|
||||
rsDesc.DepthClipEnable = TRUE;
|
||||
rsDesc.FillMode = static_cast<D3D11_FILL_MODE>(mode);
|
||||
rsDesc.FrontCounterClockwise = FALSE;
|
||||
rsDesc.MultisampleEnable = FALSE;
|
||||
rsDesc.ScissorEnable = TRUE;
|
||||
|
||||
device->CreateRasterizerState(&rsDesc, &state);
|
||||
}
|
||||
~IRasterizerState11()
|
||||
{
|
||||
SAFE_RELEASE(state);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // IRasterizerState11_h__
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef IRenderTargetViewDX11_h__
|
||||
#define IRenderTargetViewDX11_h__
|
||||
#include "render/IRenderTargetView.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IRenderTargetView11 : public IRenderTargetView
|
||||
{
|
||||
public:
|
||||
ID3D11RenderTargetView* view;
|
||||
|
||||
IRenderTargetView11(ID3D11RenderTargetView* _view)
|
||||
{
|
||||
view = _view;
|
||||
}
|
||||
~IRenderTargetView11()
|
||||
{
|
||||
SAFE_RELEASE(view);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IRenderTargetViewDX11_h__
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef IShaderResourceView11_h__
|
||||
#define IShaderResourceView11_h__
|
||||
|
||||
#include "../IShaderResourceView.h"
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IShaderResourceView11 : public IShaderResourceView
|
||||
{
|
||||
public:
|
||||
ID3D11ShaderResourceView* view;
|
||||
IShaderResourceView11(ID3D11ShaderResourceView* _view)
|
||||
{
|
||||
view = _view;
|
||||
}
|
||||
~IShaderResourceView11()
|
||||
{
|
||||
SAFE_RELEASE(view);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // IShaderResourceView11_h__
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "render/dx11/ISurface11.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
ISurface11::ISurface11()
|
||||
{
|
||||
}
|
||||
void ISurface11::setRTV(ID3D11RenderTargetView* _rtv)
|
||||
{
|
||||
rtv = _rtv;
|
||||
}
|
||||
void ISurface11::setSRV(ID3D11ShaderResourceView* _srv)
|
||||
{
|
||||
srv = _srv;
|
||||
}
|
||||
void ISurface11::setDSV(ID3D11DepthStencilView* _dsv)
|
||||
{
|
||||
dsv = _dsv;
|
||||
}
|
||||
|
||||
ID3D11RenderTargetView* ISurface11::getRTV()
|
||||
{
|
||||
return rtv;
|
||||
}
|
||||
ID3D11ShaderResourceView* ISurface11::getSRV()
|
||||
{
|
||||
return srv;
|
||||
}
|
||||
ID3D11DepthStencilView* ISurface11::getDSV()
|
||||
{
|
||||
return dsv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef ISurface11_h__
|
||||
#define ISurface11_h__
|
||||
|
||||
#include "render/ISurface.h"
|
||||
#include "render/dx11/IRenderTargetViewDX11.h"
|
||||
#include "render/dx11/IShaderResourceView11.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ISurface11 : public ISurface
|
||||
{
|
||||
public:
|
||||
ISurface11();
|
||||
void setRTV(ID3D11RenderTargetView* _rtv);
|
||||
void setSRV(ID3D11ShaderResourceView* _srv);
|
||||
void setDSV(ID3D11DepthStencilView* _dsv);
|
||||
|
||||
ID3D11RenderTargetView* getRTV();
|
||||
ID3D11ShaderResourceView* getSRV();
|
||||
ID3D11DepthStencilView* getDSV();
|
||||
protected:
|
||||
ID3D11RenderTargetView* rtv;
|
||||
ID3D11ShaderResourceView* srv;
|
||||
ID3D11DepthStencilView* dsv;
|
||||
};
|
||||
}
|
||||
#endif // ISurface11_h__
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "render/dx11/ISwapChain11.h"
|
||||
#include <Windows.h>
|
||||
#include "render/dx11/ITexture2D11.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
ISwapChain11::ISwapChain11(ID3D11Device* device, LifeCore::IRenderWindow* wnd){
|
||||
IDXGIDevice* dxgi_dev;
|
||||
IDXGIAdapter* dxgi_adapter;
|
||||
IDXGIFactory* gxgi_factory;
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC sd;
|
||||
ZeroMemory(&sd, sizeof(sd));
|
||||
|
||||
//fill swap chain description parameters
|
||||
sd.BufferCount = 1;
|
||||
sd.BufferDesc.Width = wnd->GetWidth();
|
||||
sd.BufferDesc.Height = wnd->GetHeight();
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
||||
sd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
sd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.OutputWindow = (HWND)wnd->GetWindowHandle();
|
||||
sd.Windowed = true;
|
||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
|
||||
device->QueryInterface(__uuidof(IDXGIDevice), (void**)(&dxgi_dev));
|
||||
dxgi_dev->GetParent(__uuidof(IDXGIAdapter), (void**)(&dxgi_adapter));
|
||||
dxgi_adapter->GetParent(__uuidof(IDXGIFactory), (void**)(&gxgi_factory));
|
||||
// dxgi_adapter->EnumOutputs(0, &pDXGIOutput);
|
||||
gxgi_factory->CreateSwapChain(device, &sd, &swap_chain);
|
||||
gxgi_factory->MakeWindowAssociation((HWND)wnd->GetWindowHandle(), DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES);
|
||||
|
||||
ID3D11Texture2D* back_buffer_raw;
|
||||
ID3D11RenderTargetView* back_buffer_rtv;
|
||||
swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&back_buffer_raw);
|
||||
device->CreateRenderTargetView(back_buffer_raw, NULL, &back_buffer_rtv);
|
||||
|
||||
|
||||
|
||||
back_buffer = new LifeGraphics::ITexture2D11(device);
|
||||
back_buffer->FromTexture(back_buffer_raw);
|
||||
back_buffer->addRenderTargetView(new LifeGraphics::IRenderTargetView11(back_buffer_rtv));
|
||||
|
||||
|
||||
D3D11_TEXTURE2D_DESC dDesc = {0};
|
||||
dDesc.ArraySize = 1;
|
||||
dDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
dDesc.CPUAccessFlags = 0;
|
||||
dDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
dDesc.MipLevels = 1;
|
||||
dDesc.SampleDesc.Count = 1;
|
||||
dDesc.SampleDesc.Quality = 0;
|
||||
dDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
dDesc.Width = wnd->GetWidth();
|
||||
dDesc.Height = wnd->GetHeight();
|
||||
|
||||
ID3D11Texture2D* depth_buffer_raw;
|
||||
ID3D11DepthStencilView* depth_buffer_raw_dsv;
|
||||
device->CreateTexture2D(&dDesc, NULL, &depth_buffer_raw);
|
||||
device->CreateDepthStencilView(depth_buffer_raw,NULL, &depth_buffer_raw_dsv);
|
||||
|
||||
depth_buffer = new LifeGraphics::ITexture2D11(device);
|
||||
depth_buffer->FromTexture(depth_buffer_raw);
|
||||
depth_buffer->addDepthStencilView(depth_buffer_raw_dsv);
|
||||
}
|
||||
LifeGraphics::ITexture2D* ISwapChain11::GetBackBuffer(uint8 id){
|
||||
return static_cast<ITexture2D*>(back_buffer);
|
||||
}
|
||||
LifeGraphics::ITexture2D* ISwapChain11::GetDepthBuffer(uint8 id){
|
||||
return static_cast<ITexture2D*>(depth_buffer);
|
||||
}
|
||||
void ISwapChain11::Resize(uint16 width, uint16 height){
|
||||
|
||||
}
|
||||
void ISwapChain11::Present(){
|
||||
swap_chain->Present(0,0);
|
||||
}
|
||||
ISwapChain11::~ISwapChain11(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef ISwapChain11_h__
|
||||
#define ISwapChain11_h__
|
||||
|
||||
#include "../../ISwapChain.h"
|
||||
#include <IRenderWindow.h>
|
||||
#include "render/dx11/ITexture2D11.h"
|
||||
#include <d3d11.h>
|
||||
|
||||
namespace LifeGraphics{
|
||||
class ISwapChain11 : public ISwapChain{
|
||||
public:
|
||||
ISwapChain11(ID3D11Device* device, LifeCore::IRenderWindow* wnd);
|
||||
LifeGraphics::ITexture2D* GetBackBuffer(uint8 id);
|
||||
LifeGraphics::ITexture2D* GetDepthBuffer(uint8 id);
|
||||
void Resize(uint16 width, uint16 height);
|
||||
void Present();
|
||||
~ISwapChain11();
|
||||
private:
|
||||
IDXGISwapChain* swap_chain;
|
||||
LifeGraphics::ITexture2D11* back_buffer;
|
||||
LifeGraphics::ITexture2D11* depth_buffer;
|
||||
};
|
||||
}
|
||||
#endif // ISwapChain11_h__
|
||||
@@ -0,0 +1,325 @@
|
||||
#ifndef ITEXTURE2D11_H__
|
||||
#define ITEXTURE2D11_H__
|
||||
|
||||
#include "render/ITexture2D.h"
|
||||
#include "render/dx11/IRenderTargetViewDX11.h"
|
||||
#include "render/dx11/IShaderResourceView11.h"
|
||||
#include "render/dx11/ISurface11.h"
|
||||
#include "ResourceManager.h"
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include <vector>
|
||||
#include "Globals.h"
|
||||
#include <log/CLog.h>
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ITexture2D11 : public ITexture2D
|
||||
{
|
||||
private:
|
||||
int FormatToSize(DXGI_FORMAT format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case DXGI_FORMAT_R32G32B32A32_TYPELESS:
|
||||
case DXGI_FORMAT_R32G32B32A32_FLOAT:
|
||||
case DXGI_FORMAT_R32G32B32A32_UINT:
|
||||
case DXGI_FORMAT_R32G32B32A32_SINT:
|
||||
return 16;
|
||||
case DXGI_FORMAT_R32G32B32_TYPELESS:
|
||||
case DXGI_FORMAT_R32G32B32_FLOAT:
|
||||
case DXGI_FORMAT_R32G32B32_UINT:
|
||||
case DXGI_FORMAT_R32G32B32_SINT:
|
||||
return 12;
|
||||
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
|
||||
case DXGI_FORMAT_R16G16B16A16_FLOAT:
|
||||
case DXGI_FORMAT_R16G16B16A16_UNORM:
|
||||
case DXGI_FORMAT_R16G16B16A16_UINT:
|
||||
case DXGI_FORMAT_R16G16B16A16_SNORM:
|
||||
case DXGI_FORMAT_R16G16B16A16_SINT:
|
||||
case DXGI_FORMAT_R32G32_TYPELESS:
|
||||
case DXGI_FORMAT_R32G32_FLOAT:
|
||||
case DXGI_FORMAT_R32G32_UINT:
|
||||
case DXGI_FORMAT_R32G32_SINT:
|
||||
case DXGI_FORMAT_R32G8X24_TYPELESS:
|
||||
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
|
||||
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
|
||||
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT:
|
||||
return 8;
|
||||
case DXGI_FORMAT_R10G10B10A2_TYPELESS:
|
||||
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
||||
case DXGI_FORMAT_R10G10B10A2_UINT:
|
||||
case DXGI_FORMAT_R11G11B10_FLOAT:
|
||||
case DXGI_FORMAT_R8G8B8A8_TYPELESS:
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||
case DXGI_FORMAT_R8G8B8A8_UINT:
|
||||
case DXGI_FORMAT_R8G8B8A8_SNORM:
|
||||
case DXGI_FORMAT_R8G8B8A8_SINT:
|
||||
case DXGI_FORMAT_R16G16_TYPELESS:
|
||||
case DXGI_FORMAT_R16G16_FLOAT:
|
||||
case DXGI_FORMAT_R16G16_UNORM:
|
||||
case DXGI_FORMAT_R16G16_UINT:
|
||||
case DXGI_FORMAT_R16G16_SNORM:
|
||||
case DXGI_FORMAT_R16G16_SINT:
|
||||
case DXGI_FORMAT_R32_TYPELESS:
|
||||
case DXGI_FORMAT_D32_FLOAT:
|
||||
case DXGI_FORMAT_R32_FLOAT:
|
||||
case DXGI_FORMAT_R32_UINT:
|
||||
case DXGI_FORMAT_R32_SINT:
|
||||
case DXGI_FORMAT_R24G8_TYPELESS:
|
||||
case DXGI_FORMAT_D24_UNORM_S8_UINT:
|
||||
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
|
||||
case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
|
||||
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
||||
case DXGI_FORMAT_B8G8R8X8_UNORM:
|
||||
case DXGI_FORMAT_B8G8R8A8_TYPELESS:
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
|
||||
case DXGI_FORMAT_B8G8R8X8_TYPELESS:
|
||||
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
|
||||
return 4;
|
||||
case DXGI_FORMAT_R8G8_TYPELESS:
|
||||
case DXGI_FORMAT_R8G8_UNORM:
|
||||
case DXGI_FORMAT_R8G8_UINT:
|
||||
case DXGI_FORMAT_R8G8_SNORM:
|
||||
case DXGI_FORMAT_R8G8_SINT:
|
||||
case DXGI_FORMAT_R16_TYPELESS:
|
||||
case DXGI_FORMAT_R16_FLOAT:
|
||||
case DXGI_FORMAT_D16_UNORM:
|
||||
case DXGI_FORMAT_R16_UNORM:
|
||||
case DXGI_FORMAT_R16_UINT:
|
||||
case DXGI_FORMAT_R16_SNORM:
|
||||
case DXGI_FORMAT_R16_SINT:
|
||||
case DXGI_FORMAT_B5G6R5_UNORM:
|
||||
case DXGI_FORMAT_B5G5R5A1_UNORM:
|
||||
return 2;
|
||||
case DXGI_FORMAT_R8_TYPELESS:
|
||||
case DXGI_FORMAT_R8_UNORM:
|
||||
case DXGI_FORMAT_R8_UINT:
|
||||
case DXGI_FORMAT_R8_SNORM:
|
||||
case DXGI_FORMAT_R8_SINT:
|
||||
case DXGI_FORMAT_A8_UNORM:
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public:
|
||||
ID3D11ShaderResourceView* cubeResourceView;
|
||||
ISurface* getSurface(int id)
|
||||
{
|
||||
return &surfaces[id];
|
||||
}
|
||||
bool IsVideoTexture()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ITexture2D11(ID3D11Device* _device)
|
||||
{
|
||||
IsRenderTarget = 0;
|
||||
IsDepthTarget = 0;
|
||||
pDevice = _device;
|
||||
pDevice->GetImmediateContext(&context);
|
||||
}
|
||||
~ITexture2D11()
|
||||
{
|
||||
for(UINT i = 0; i<rtViews.size(); i++)
|
||||
{
|
||||
SAFE_DELETE(rtViews[i]);
|
||||
}
|
||||
for(UINT i = 0; i<srViews.size(); i++)
|
||||
{
|
||||
SAFE_DELETE(srViews[i]);
|
||||
}
|
||||
//SAFE_RELEASE(dsView); FIX ME
|
||||
rtViews.clear();
|
||||
srViews.clear();
|
||||
|
||||
SAFE_RELEASE(texture);
|
||||
}
|
||||
std::vector<IRenderTargetView11*> rtViews;
|
||||
std::vector<IShaderResourceView11*> srViews;
|
||||
std::vector<ID3D11DepthStencilView*> dsViews;
|
||||
|
||||
ID3D11Texture2D* texture;
|
||||
ID3D11Device* pDevice;
|
||||
ID3D11DeviceContext* context;
|
||||
LifeCore::IDataRectangle rectangle;
|
||||
D3D11_MAPPED_SUBRESOURCE mappedData;
|
||||
int t_width, t_height;
|
||||
int IsRenderTarget;
|
||||
int IsDepthTarget;
|
||||
|
||||
IShaderResourceView* getSRView()
|
||||
{
|
||||
return srViews[0];
|
||||
}
|
||||
|
||||
IShaderResourceView* getSRView(int index)
|
||||
{
|
||||
return srViews[index];
|
||||
}
|
||||
|
||||
ID3D11DepthStencilView* getDSView()
|
||||
{
|
||||
return dsViews[0];
|
||||
}
|
||||
|
||||
ID3D11DepthStencilView* getDSView(int index)
|
||||
{
|
||||
return dsViews[index];
|
||||
}
|
||||
|
||||
IRenderTargetView* getRTView()
|
||||
{
|
||||
return rtViews[0];
|
||||
}
|
||||
|
||||
IRenderTargetView* getRTView(int index)
|
||||
{
|
||||
return rtViews[index];
|
||||
}
|
||||
|
||||
void addRenderTargetView(IRenderTargetView11* view)
|
||||
{
|
||||
rtViews.push_back(view);
|
||||
surfaces[rtViews.size() - 1].setRTV(view->view);
|
||||
}
|
||||
|
||||
void addDepthStencilView(ID3D11DepthStencilView* view)
|
||||
{
|
||||
dsViews.push_back(view);
|
||||
surfaces[dsViews.size() - 1].setDSV(view);
|
||||
}
|
||||
|
||||
void addShaderResourceView(IShaderResourceView11* view)
|
||||
{
|
||||
srViews.push_back(view);
|
||||
surfaces[srViews.size() - 1].setSRV(view->view);
|
||||
}
|
||||
|
||||
void FromTexture(ID3D11Texture2D* tex)
|
||||
{
|
||||
if (tex)
|
||||
{
|
||||
texture = tex;
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
texture->GetDesc(&desc);
|
||||
|
||||
t_width = desc.Width;
|
||||
t_height = desc.Height;
|
||||
|
||||
bpp = FormatToSize(desc.Format);
|
||||
|
||||
this->Description.Width = desc.Width;
|
||||
this->Description.Height = desc.Height;
|
||||
this->Description.SampleCount = desc.SampleDesc.Count;
|
||||
this->Description.SampleQuality = desc.SampleDesc.Quality;
|
||||
this->Description.Format = desc.Format;
|
||||
}
|
||||
}
|
||||
ID3D11Texture2D* GetData()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
LifeCore::IDataRectangle* Map(int level, int read, int write)
|
||||
{
|
||||
D3D11_MAP flags = D3D11_MAP_WRITE_DISCARD;
|
||||
|
||||
if(!read && !write)
|
||||
throw "ff";
|
||||
|
||||
if(read && !write)
|
||||
flags = D3D11_MAP_READ;
|
||||
else if(!read && write)
|
||||
flags = D3D11_MAP_WRITE_DISCARD;
|
||||
else if (read && write)
|
||||
flags = D3D11_MAP_READ_WRITE;
|
||||
|
||||
context->Map(texture, level, flags,0, &mappedData);
|
||||
|
||||
rectangle.pitch = mappedData.RowPitch;
|
||||
rectangle.data.Reset((char*)mappedData.pData, t_width * t_height * bpp);
|
||||
|
||||
return &rectangle;
|
||||
|
||||
// return new LifeCore::IDataRectangle(stm.RowPitch, stm.Data.DataPointer);
|
||||
}
|
||||
void Unmap(int level)
|
||||
{
|
||||
context->Unmap(texture, level);
|
||||
// g_textureData.Device.ImmediateContext.UnmapSubresource(g_textureData, 0);
|
||||
|
||||
//g_textureData.AsSurface().Unmap();
|
||||
}
|
||||
|
||||
int Width()
|
||||
{
|
||||
return t_width;
|
||||
}
|
||||
|
||||
int Height()
|
||||
{
|
||||
return t_height;
|
||||
}
|
||||
|
||||
void ToFile(const String& path)
|
||||
{
|
||||
D3DX11SaveTextureToFile(context,texture, D3DX11_IFF_DDS, path.c_str());
|
||||
LifeCore::CLog::me()->Write(AS_STRING("OH SHIIIT!!! Texture saving!"));
|
||||
//Logger.Instance.Write("WARNING! Saving render target to file!" + "\n" + path);
|
||||
//Texture2D.ToFile((this.g_parent as RendererDX11).GetDeviceContext(), g_textureData,ImageFileFormat.Jpg, path );
|
||||
}
|
||||
void CompleteAsyncRequest(IResource* source)
|
||||
{
|
||||
//Core::CLog::me()->Write(String(_text("CompleteAsyncRequest called in texture2D!")) + source->Name);
|
||||
//Texture2D11 src = (Texture2D11)source;
|
||||
// this.FromTexture(src.g_textureData);
|
||||
}
|
||||
|
||||
void Load(LifeCore::IDataStreamPtr source)
|
||||
{
|
||||
ID3D11Resource* tex = 0;
|
||||
char* dataBuffer = new char[source->Length()];
|
||||
source->Read(dataBuffer, source->Length());
|
||||
HRESULT result = 0;
|
||||
D3DX11_IMAGE_LOAD_INFO info;
|
||||
|
||||
info.Width = D3DX11_DEFAULT;
|
||||
info.Height = D3DX11_DEFAULT;
|
||||
info.Depth = D3DX11_DEFAULT;
|
||||
info.FirstMipLevel = 0;
|
||||
info.MipLevels = 6;
|
||||
info.Usage = (D3D11_USAGE) D3DX11_DEFAULT;
|
||||
info.BindFlags = D3DX11_DEFAULT;
|
||||
info.CpuAccessFlags = D3DX11_DEFAULT;
|
||||
info.MiscFlags = D3DX11_DEFAULT;
|
||||
info.Format = DXGI_FORMAT_FROM_FILE;
|
||||
info.Filter = D3DX11_FILTER_TRIANGLE;
|
||||
info.MipFilter = D3DX11_FILTER_TRIANGLE;
|
||||
info.pSrcInfo = NULL;
|
||||
|
||||
result = D3DX11CreateTextureFromMemory(pDevice, dataBuffer,source->Length(),&info, 0, &tex, 0);
|
||||
delete[] dataBuffer;
|
||||
if(result == S_OK)
|
||||
FromTexture((ID3D11Texture2D*) tex);
|
||||
else
|
||||
LifeCore::CLog::me()->Write(String(_text("Can not load texture!")));
|
||||
}
|
||||
|
||||
private:
|
||||
ISurface11 surfaces[6];
|
||||
/* virtual int Width();
|
||||
virtual int Height();
|
||||
virtual LifeCore::IDataRectangle* Map(int level, bool read, bool write, int bpp) = 0;
|
||||
virtual void Unmap(int level) = 0;
|
||||
virtual void ToFile(const String& path) = 0;
|
||||
virtual void Load(const Core::IDataStream* src) {}
|
||||
virtual void CompleteAsyncRequest(IResource* source) {}*/
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef ITextureSampler11_h__
|
||||
#define ITextureSampler11_h__
|
||||
#include "render/ITextureSampler.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class ITextureSampler11 : public ITextureSampler
|
||||
{
|
||||
public:
|
||||
ID3D11SamplerState* state;
|
||||
|
||||
ITextureSampler11(ISamplerDescription* desc, ID3D11Device* dev)
|
||||
{
|
||||
D3D11_SAMPLER_DESC d;
|
||||
ZeroMemory(&d, sizeof(D3D11_SAMPLER_DESC));
|
||||
d.AddressU = static_cast<D3D11_TEXTURE_ADDRESS_MODE>(desc->AddressU);
|
||||
d.AddressV = static_cast<D3D11_TEXTURE_ADDRESS_MODE>(desc->AddressV);
|
||||
d.AddressW = static_cast<D3D11_TEXTURE_ADDRESS_MODE>(desc->AddressW);
|
||||
d.MaxAnisotropy = 1;
|
||||
d.Filter = static_cast<D3D11_FILTER>(desc->Filter);
|
||||
d.ComparisonFunc = static_cast<D3D11_COMPARISON_FUNC>(desc->CmpFunc);
|
||||
d.MaxLOD = 3.402823466e+38F;
|
||||
dev->CreateSamplerState(&d, &state);
|
||||
}
|
||||
~ITextureSampler11()
|
||||
{
|
||||
SAFE_RELEASE(state);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // ITextureSampler11_h__
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef I_VERTEX_BUFFER11_H__
|
||||
#define I_VERTEX_BUFFER11_H__
|
||||
|
||||
#include "render/IVertexBuffer.h"
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "IMemoryStream.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "Globals.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IVertexBuffer11 : public IVertexBuffer
|
||||
{
|
||||
public:
|
||||
ID3D11Buffer* vb;
|
||||
ID3D11Device* device;
|
||||
ID3D11DeviceContext* context;
|
||||
D3D11_MAPPED_SUBRESOURCE mappedData;
|
||||
LifeCore::IMemoryStream stm;
|
||||
|
||||
~IVertexBuffer11()
|
||||
{
|
||||
SAFE_RELEASE(vb);
|
||||
}
|
||||
IVertexBuffer11(ID3D11Device* _device, void* pBuffer, int _size, int _stride, int staging)
|
||||
{
|
||||
device = _device;
|
||||
length = _size;
|
||||
stride = _stride;
|
||||
|
||||
//g_desc = new BufferDescription(size, D3D11.ResourceUsage.Default,
|
||||
// BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
|
||||
D3D11_BUFFER_DESC bd;
|
||||
ZeroMemory( &bd, sizeof(bd) );
|
||||
if(pBuffer)
|
||||
bd.Usage = D3D11_USAGE_DEFAULT;
|
||||
else
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
if(staging)
|
||||
bd.Usage = D3D11_USAGE_STAGING;
|
||||
|
||||
bd.ByteWidth = _size;
|
||||
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
|
||||
if(bd.Usage == D3D11_USAGE_DEFAULT)
|
||||
bd.CPUAccessFlags = 0;
|
||||
else if(bd.Usage == D3D11_USAGE_DYNAMIC)
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
else if(bd.Usage == D3D11_USAGE_STAGING)
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
|
||||
|
||||
if(pBuffer)
|
||||
{
|
||||
D3D11_SUBRESOURCE_DATA InitData;
|
||||
ZeroMemory( &InitData, sizeof(InitData) );
|
||||
InitData.pSysMem = pBuffer;
|
||||
|
||||
device->CreateBuffer( &bd, &InitData, &vb );
|
||||
}
|
||||
else
|
||||
device->CreateBuffer( &bd, NULL, &vb );
|
||||
device->GetImmediateContext(&context);
|
||||
//if( FAILED( hr ) )
|
||||
// return hr;
|
||||
}
|
||||
LifeCore::IDataStream* Map(int offset, int flags)
|
||||
{
|
||||
D3D11_MAP mapFlags;
|
||||
|
||||
if (flags & LF_Discard)
|
||||
mapFlags = D3D11_MAP_WRITE_DISCARD;
|
||||
else if ((flags & LF_NoOverwrite))
|
||||
mapFlags = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
|
||||
else if ((flags & LF_ReadOnly))
|
||||
mapFlags = D3D11_MAP_READ;
|
||||
|
||||
else if (flags == LF_None)
|
||||
mapFlags = D3D11_MAP_READ_WRITE;
|
||||
else
|
||||
mapFlags = D3D11_MAP_WRITE;
|
||||
|
||||
context->Map(vb,0, mapFlags,0, &mappedData);
|
||||
stm.Reset(((char*)mappedData.pData) + offset, length);
|
||||
return &stm;
|
||||
}
|
||||
void Update(void* data, size_t length)
|
||||
{
|
||||
D3D11_BOX b;
|
||||
b.left = 0;
|
||||
b.right = 1;
|
||||
b.top = 0;
|
||||
b.bottom = 1;
|
||||
b.front = 0;
|
||||
b.back = 0;
|
||||
context->UpdateSubresource(vb, 0, NULL, data, length, 0);
|
||||
}
|
||||
void Unmap()
|
||||
{
|
||||
context->Unmap(vb, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
#ifndef IVertexShader11_h__
|
||||
#define IVertexShader11_h__
|
||||
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "render/IShader.h"
|
||||
#include "render/IMacroDefine.h"
|
||||
#include <vector>
|
||||
#include "Globals.h"
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IVertexShader11 : public IShader
|
||||
{
|
||||
public:
|
||||
ID3D11VertexShader* g_shader;
|
||||
ID3DBlob* g_bytecode;
|
||||
ID3D11Device* g_device;
|
||||
IVertexShader11(ID3D11Device* device)
|
||||
{
|
||||
g_device = device;
|
||||
}
|
||||
~IVertexShader11()
|
||||
{
|
||||
SAFE_RELEASE(g_bytecode);
|
||||
SAFE_RELEASE(g_shader);
|
||||
}
|
||||
void* Disassemble()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
SHADER_TYPE getShaderType()
|
||||
{
|
||||
return ST_VS;
|
||||
}
|
||||
char* GetByteCode()
|
||||
{
|
||||
return (char*)0;
|
||||
}
|
||||
void Compile(LifeCore::IDataStreamPtr stream, std::vector<IMacroDefine>* defines)
|
||||
{
|
||||
char* shader = new char[stream->Length()];
|
||||
stream->Read(shader, stream->Length());
|
||||
Compile(shader, stream->Length(), defines);
|
||||
delete[]shader;
|
||||
}
|
||||
void Compile(const char* pData, int length, std::vector<IMacroDefine>* defines)
|
||||
{
|
||||
HRESULT hr;
|
||||
g_bytecode = NULL;
|
||||
ID3D10Blob* errorBlob;
|
||||
|
||||
if(!defines)
|
||||
{
|
||||
hr = D3DX11CompileFromMemory(pData, length, "system_shader", NULL, NULL, "main_VS", "vs_5_0",0,0,NULL, &g_bytecode,&errorBlob, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//create macro
|
||||
D3D10_SHADER_MACRO* macros = new D3D10_SHADER_MACRO[defines->size() + 1];
|
||||
int cnt = defines->size();
|
||||
for(int i = 0; i < cnt; i++)
|
||||
{
|
||||
macros[i].Definition = defines[0][i].definition.c_str();
|
||||
macros[i].Name = defines[0][i].name.c_str();
|
||||
}
|
||||
D3D10_SHADER_MACRO m;
|
||||
m.Definition = NULL;
|
||||
m.Name = NULL;
|
||||
macros[cnt] = m;
|
||||
|
||||
hr = D3DX11CompileFromMemory(pData, length, "system_shader", macros, NULL, "main_VS", "vs_5_0",0,0,NULL, &g_bytecode,&errorBlob, NULL);
|
||||
delete[] macros;
|
||||
}
|
||||
if( FAILED( hr ) )
|
||||
{
|
||||
printf("SHADER COMPILE ERROR: %s", errorBlob->GetBufferPointer());
|
||||
}
|
||||
hr = g_device->CreateVertexShader(g_bytecode->GetBufferPointer(), g_bytecode->GetBufferSize(), NULL, &g_shader);
|
||||
}
|
||||
void Load(LifeCore::IDataStreamPtr src)
|
||||
{
|
||||
printf("Load VS is not implemented: %i\n", src->Length());
|
||||
}
|
||||
void CompleteAsyncRequest(IResource* source)
|
||||
{
|
||||
//printf("VS async not implemented: %s\n", source->Name.c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // IPixelShader11_h__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,213 @@
|
||||
#ifndef RendererDX11_h__
|
||||
#define RendererDX11_h__
|
||||
|
||||
#include "Globals.h"
|
||||
#include <render/IRenderer.h>
|
||||
#include "math/LifeMath.h"
|
||||
#include <Build.h>
|
||||
#include "ITexture2D11.h"
|
||||
#include <d3dcompiler.h>
|
||||
#include "render/dx11/IVertexBuffer11.h"
|
||||
#include "render/dx11/IIndexBuffer11.h"
|
||||
#include "Globals.h"
|
||||
|
||||
#include "render/RenderParams.h"
|
||||
#include <PluginServer.h>
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
#include <d3dx11.h>
|
||||
#include "render/dx11/IVertexShader11.h"
|
||||
#include "render/dx11/IPixelShader11.h"
|
||||
#include "render/dx11/IInputLayout11.h"
|
||||
#include "render/dx11/IBlendState11.h"
|
||||
#include "math/LifeMath.h"
|
||||
#include "render/dx11/IRasterizerState11.h"
|
||||
#include "render/dx11/ITextureSampler11.h"
|
||||
#include "render/dx11/ISurface11.h"
|
||||
|
||||
#include "render/dx11/ISwapChain11.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
struct SimpleVertex
|
||||
{
|
||||
LifeMath::float4 Pos;
|
||||
LifeMath::float2 TC;
|
||||
};
|
||||
class RendererDX11 : public IRenderer
|
||||
{
|
||||
public:
|
||||
RendererDX11(){};
|
||||
~RendererDX11(){printf("Destroying renderer...");Close();};
|
||||
virtual HRESULT Open(RenderParams params);
|
||||
virtual void Close();
|
||||
//virtual void ClearBuffers(int flags, int rtColor, float zValue, int stencilValue);
|
||||
virtual const String& GetRendererName() const {
|
||||
static String sName("DirectX11 graphics driver");
|
||||
return sName;
|
||||
}
|
||||
|
||||
void ClearRenderTarget(ISurface* target, LifeMath::float4* color);
|
||||
void ClearDepthStencil(ISurface* target, int flag, float zValue, int stencilValue);
|
||||
|
||||
ITexture2D* CreateRenderTarget(int width, int height, int format);
|
||||
ITexture2D* CreateDepthTarget(int width, int height, int format);
|
||||
ITexture2D* LoadTexture2D(LifeCore::IDataStreamPtr src);
|
||||
ITexture2D* CreateTexture2D(int canRead, int canWrite, int width, int height, int format);
|
||||
void RenderToTexture();
|
||||
void RenderToTextureNoPs();
|
||||
void RenderToTextureNoShader();
|
||||
IVertexBuffer* CreateVertexBuffer(int size, void* data, int stride);
|
||||
IVertexBuffer* CreateVertexBufferDynamic(int size, int stride);
|
||||
IIndexBuffer* CreateIndexBuffer(int size, void* data, int sixteenBit);
|
||||
IIndexBuffer* CreateIndexBufferDynamic(int size, bool sixteenBit);
|
||||
IInputLayout* CreateInputLayout(IInputElement* elements, int elementCount, IShader* vertexShader);
|
||||
|
||||
IShader* CompileVertexShader(const char* pData, int length);
|
||||
IShader* CompileVertexShader(LifeCore::IDataStreamPtr stream);
|
||||
IShader* CompileVertexShader(LifeCore::IDataStreamPtr stream, std::vector<IMacroDefine>* defines);
|
||||
|
||||
IShader* CompilePixelShader(const char* pData, int length);
|
||||
IShader* CompilePixelShader(LifeCore::IDataStreamPtr stream);
|
||||
IShader* CompilePixelShader(LifeCore::IDataStreamPtr stream, std::vector<IMacroDefine>* defines);
|
||||
|
||||
IConstantBuffer* CreateConstantBuffer(int size);
|
||||
|
||||
void SetVSConstantBuffer(IConstantBuffer* buffer, int slot);
|
||||
void SetPSConstantBuffer(IConstantBuffer* buffer, int slot);
|
||||
|
||||
void SetInputLayout(IInputLayout* layout);
|
||||
void RenderMesh(IMesh* mesh);
|
||||
|
||||
void SetMaterial(IMaterial* material);
|
||||
|
||||
void SetTargets(ITexture2D* colorTarget, ITexture2D* depthTarget);
|
||||
void SetTargets(ISurface* colorTarget, ISurface* depthTarget);
|
||||
void SetCubeTarget(ITexture2D* colorTarget, ITexture2D* depthTarget, int faceIndex);
|
||||
|
||||
void SetVertexBuffer(IVertexBuffer* vb);
|
||||
void SetIndexBuffer(IIndexBuffer* ib);
|
||||
|
||||
void SetPrimitiveTopology(PRIMITIVE_TOPOLOGY topology);
|
||||
void SetPSTextureCube(ITexture2D* texture, int slot);
|
||||
void DrawIndexed(int offset, int length);
|
||||
|
||||
void SetVertexShader(IShader* shader);
|
||||
void SetPixelShader(IShader* shader);
|
||||
|
||||
void SetPSTexture(ITexture2D* texture, int slot);
|
||||
void SetVSTexture(ITexture2D* texture, int slot);
|
||||
|
||||
void UnbindResourcesPS();
|
||||
|
||||
void Draw(int vertexCount, int vertexOffset);
|
||||
|
||||
IBlendState* CreateBlendState(bool blendEnable, bool atocEnable, BLEND_OP blendOperation, BLEND_SRC srcBlend, BLEND_SRC dstBlend, uint8 colorMask);
|
||||
|
||||
void SetBlendState(IBlendState* state);
|
||||
|
||||
IDepthStencilState* CreateDSState(bool zEnable, bool zWrite, COMPARISON_FUNC zFunc);
|
||||
|
||||
IDepthStencilState* CreateDSState(bool zEnable, bool zWrite, COMPARISON_FUNC zFunc, bool stencil, int stencilMask, int stencilFunc, int stencilFail, int depthFail, int depthFailBack,int stencilPass);
|
||||
|
||||
void SetDepthStencilState(IDepthStencilState* state, UINT sref = 0);
|
||||
|
||||
void SetScissorRectangle(const LifeMath::Rect2i& rect);
|
||||
|
||||
void SetViewport(const LifeMath::Rect2i& rect);
|
||||
|
||||
ITexture2D* CreateRenderTargetCube(int size, int format);
|
||||
|
||||
ITexture2D* CreateDepthTargetCube(int width, int format);
|
||||
|
||||
void SetPSTextureNULL(int slot);
|
||||
|
||||
void SetPSTextureSampler(ITextureSampler* sampler, int slot);
|
||||
|
||||
ITextureSampler* CreateTextureSampler(ISamplerDescription* desc);
|
||||
|
||||
void SetColorTarget(ITexture2D* colorTarget);
|
||||
void SetDepthTarget(ITexture2D* depthTarget);
|
||||
|
||||
void VerticalBlur(ITexture2D* src, ITexture2D* dst, int numSamples);
|
||||
|
||||
void SetPSTexture(ITexture2D* texture, ITexture2D* texture2, int start, int count);
|
||||
|
||||
IShader* CompileUserShaderPS(char* data);
|
||||
|
||||
IVertexBuffer11* testVb;
|
||||
|
||||
IRasterizerState* CreateRasterizerState(FILL_MODE mode);
|
||||
|
||||
void DrawIndexed(int offset, int length, int baseVertex);
|
||||
|
||||
void SetRasterizerState(IRasterizerState* state);
|
||||
|
||||
void SetTargets(ITexture2D** colorTargets, int targetCount, ITexture2D* depthTarget);
|
||||
|
||||
void UnbindRenderTargets();
|
||||
|
||||
void SetVertexBuffer(IVertexBuffer** vb, int count);
|
||||
|
||||
void DrawIndexedInstanced(int offset, int length, int instanceCnt);
|
||||
|
||||
void DrawIndexedInstanced(int offset, int length, int baseVertex, int instanceCnt);
|
||||
|
||||
void SetViewport(const LifeMath::Rect2i& rect, float minDepth, float maxDepth);
|
||||
|
||||
IRasterizerState* CreateRasterizerState(FILL_MODE mode, CULL_MODE cmode);
|
||||
|
||||
void DownSample2x2(ITexture2D* src, ITexture2D* dst, ITexture2D* depth);
|
||||
void BlurGaussH(ITexture2D* src, ITexture2D* dst, ITexture2D* depth);
|
||||
void BlurGaussV(ITexture2D* src, ITexture2D* dst, ITexture2D* depth);
|
||||
|
||||
void BeginCleanup();
|
||||
void EndCleanup();
|
||||
|
||||
void ClearRenderTarget(ITexture2D* tex, LifeMath::float4* color);
|
||||
void ClearDepthStencil(ITexture2D* tex, float zValue, int stencilValue);
|
||||
void ClearDepthStencil(ITexture2D* tex, int flag, float zValue, int stencilValue);
|
||||
|
||||
int GetDisplayModes(LifeCore::DisplayMode** modeList);
|
||||
|
||||
ISwapChain* CreateSwapChain(LifeCore::IRenderWindow* window);
|
||||
private:
|
||||
|
||||
IShader* ds2x2;
|
||||
IConstantBuffer* ds2x2cb;
|
||||
|
||||
IDXGIAdapter* pDXGIAdapter;
|
||||
IDXGIDevice* pDXGIDevice;
|
||||
IDXGIOutput* pDXGIOutput;
|
||||
|
||||
ID3D11RasterizerState* rState;
|
||||
ID3D11Device* g_pDevice;
|
||||
ID3D11DeviceContext* g_pDeviceContext;
|
||||
//IDXGISwapChain* g_pSwapChain;
|
||||
|
||||
//ID3D11RenderTargetView* g_pBackBuffer;
|
||||
//ID3D11DepthStencilView* g_pDepthBuffer;
|
||||
|
||||
//ID3D11RenderTargetView* currentBackBuffer;
|
||||
//ID3D11DepthStencilView* currentDepthBuffer;
|
||||
|
||||
D3D_FEATURE_LEVEL g_pFeatureLevel;
|
||||
D3D_DRIVER_TYPE g_driverType;
|
||||
ID3D11Buffer* fsQuadBuffer;
|
||||
ID3D11PixelShader* psQuad;
|
||||
ID3D11VertexShader* vsQuad;
|
||||
ID3D11InputLayout* fsQuadLayout;
|
||||
ID3D11SamplerState* samplerLinear;
|
||||
ID3D11SamplerState* samplerPoint;
|
||||
//ID3D11Texture2D* pBuffer;
|
||||
//ID3D11Texture2D* dBuf;
|
||||
//Camera* cam;
|
||||
|
||||
ID3D11PixelShader* psVerticalBlur;
|
||||
|
||||
IConstantBuffer* vbBuffer;
|
||||
|
||||
IDXGIFactory* pFactory;
|
||||
};
|
||||
}
|
||||
#endif // RendererDX11_h__
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "render/RendererSoftware.h"
|
||||
|
||||
#include "vfs/fs_win/IFSContentProvider.h"
|
||||
#include "LString.h"
|
||||
#include "vfs/IFile.h"
|
||||
#include <log/CLog.h>
|
||||
#include "render/software/IConstantBufferS.h"
|
||||
#include "render/IMaterial.h"
|
||||
#include "render/software/IDepthStencilStateS.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user