Engine tweaks + DefferedVertexDefinition

This commit is contained in:
lanariel 2013-11-26 09:09:35 +01:00
parent abed0157ec
commit 973aadac2d
16 changed files with 183 additions and 127 deletions

View File

@ -1,19 +1,18 @@
#include "Buffer.h"
#include "Core.h"
using namespace Oyster::Graphics;
Buffer::Buffer()
Core::Buffer::Buffer()
{
mBuffer = NULL;
}
Buffer::~Buffer()
Core::Buffer::~Buffer()
{
SAFE_RELEASE(mBuffer);
}
HRESULT Buffer::Apply(UINT32 misc) const
HRESULT Core::Buffer::Apply(UINT32 misc) const
{
HRESULT hr = S_OK;
@ -59,7 +58,7 @@ HRESULT Buffer::Apply(UINT32 misc) const
return hr;
}
HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc)
HRESULT Core::Buffer::Init(const BUFFER_INIT_DESC& initDesc)
{
D3D11_BUFFER_DESC bufferDesc;
@ -154,13 +153,13 @@ HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc)
if(FAILED(hr))
{
MessageBox(NULL, L"Unable to create buffer.", L"Slenda Error", MB_ICONERROR | MB_OK);
//MessageBox(NULL, L"Unable to create buffer.", L"Slenda Error", MB_ICONERROR | MB_OK);
}
return hr;
}
void* Buffer::Map()
void* Core::Buffer::Map()
{
void* ret = NULL;
if(mUsage == BUFFER_CPU_WRITE || mUsage == BUFFER_CPU_READ || mUsage == BUFFER_CPU_WRITE_DISCARD)
@ -192,17 +191,17 @@ void* Buffer::Map()
}
void Buffer::Unmap()
void Core::Buffer::Unmap()
{
Core::deviceContext->Unmap( mBuffer, 0 );
}
Buffer::operator ID3D11Buffer *()
Core::Buffer::operator ID3D11Buffer *()
{
return this->mBuffer;
}
Buffer::operator const ID3D11Buffer *() const
Core::Buffer::operator const ID3D11Buffer *() const
{
return this->mBuffer;
}

View File

@ -1,79 +0,0 @@
#pragma once
#ifndef CoreBuffer
#define CoreBuffer
#include "CoreIncludes.h"
namespace Oyster
{
namespace Graphics
{
class Buffer
{
public:
enum BUFFER_TYPE
{
VERTEX_BUFFER,
INDEX_BUFFER,
CONSTANT_BUFFER_VS,
CONSTANT_BUFFER_GS,
CONSTANT_BUFFER_PS,
CONSTANT_BUFFER_CS,
STRUCTURED_BUFFER,
BUFFER_TYPE_COUNT
};
enum BUFFER_USAGE
{
BUFFER_DEFAULT,
BUFFER_STREAM_OUT_TARGET,
BUFFER_CPU_WRITE,
BUFFER_CPU_WRITE_DISCARD,
BUFFER_CPU_READ,
BUFFER_USAGE_COUNT,
BUFFER_USAGE_IMMUTABLE
};
struct BUFFER_INIT_DESC
{
BUFFER_TYPE Type;
UINT32 NumElements;
UINT32 ElementSize;
BUFFER_USAGE Usage;
void* InitData;
BUFFER_INIT_DESC()
{
InitData = NULL;
Usage = BUFFER_DEFAULT;
}
};
protected:
ID3D11Buffer* mBuffer;
BUFFER_TYPE mType;
BUFFER_USAGE mUsage;
UINT32 mElementSize;
UINT32 mElementCount;
public:
Buffer();
virtual ~Buffer();
HRESULT Init(const BUFFER_INIT_DESC& initDesc);
void* Map();
void Unmap();
operator ID3D11Buffer*();
operator const ID3D11Buffer*() const;
HRESULT Apply(UINT32 misc = 0) const;
ID3D11Buffer* GetBufferPointer();
UINT32 GetVertexSize();
UINT32 GetElementCount();
};
}
}
#endif

View File

@ -6,7 +6,6 @@
#include "CoreIncludes.h"
#include <sstream>
#include "Buffer.h"
#include "OysterMath.h"
namespace Oyster
@ -35,6 +34,72 @@ namespace Oyster
static D3D11_VIEWPORT* viewPort;
static Oyster::Math::Float2 resolution;
class Buffer
{
public:
enum BUFFER_TYPE
{
VERTEX_BUFFER,
INDEX_BUFFER,
CONSTANT_BUFFER_VS,
CONSTANT_BUFFER_GS,
CONSTANT_BUFFER_PS,
CONSTANT_BUFFER_CS,
STRUCTURED_BUFFER,
BUFFER_TYPE_COUNT
};
enum BUFFER_USAGE
{
BUFFER_DEFAULT,
BUFFER_STREAM_OUT_TARGET,
BUFFER_CPU_WRITE,
BUFFER_CPU_WRITE_DISCARD,
BUFFER_CPU_READ,
BUFFER_USAGE_COUNT,
BUFFER_USAGE_IMMUTABLE
};
struct BUFFER_INIT_DESC
{
BUFFER_TYPE Type;
UINT32 NumElements;
UINT32 ElementSize;
BUFFER_USAGE Usage;
void* InitData;
BUFFER_INIT_DESC()
{
InitData = NULL;
Usage = BUFFER_DEFAULT;
}
};
protected:
ID3D11Buffer* mBuffer;
BUFFER_TYPE mType;
BUFFER_USAGE mUsage;
UINT32 mElementSize;
UINT32 mElementCount;
public:
Buffer();
virtual ~Buffer();
HRESULT Init(const BUFFER_INIT_DESC& initDesc);
void* Map();
void Unmap();
operator ID3D11Buffer*();
operator const ID3D11Buffer*() const;
HRESULT Apply(UINT32 misc = 0) const;
ID3D11Buffer* GetBufferPointer();
UINT32 GetVertexSize();
UINT32 GetElementCount();
};
class ShaderManager

View File

@ -19,6 +19,18 @@ namespace Oyster
Oyster::Math::Matrix V;
Oyster::Math::Matrix P;
};
struct FinalVertex
{
Oyster::Math::Float3 pos;
Oyster::Math::Float2 uv;
Oyster::Math::Float3 normal;
Oyster::Math::Float3 tangent;
Oyster::Math::Float3 biTangent;
Oyster::Math::Float4 boneIndex;
Oyster::Math::Float4 boneWeights;
};
}
}
}

View File

@ -19,11 +19,11 @@ public:
State Init(HWND Window, bool MSAA_Quality, bool Fullscreen);
//! @brief from Oyster::Math Float4x4, expects corect methods
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection);
static void RenderScene(Oyster::Graphics::Render::Model* models, int count);
static void RenderScene(Oyster::Graphics::Model::Model* models, int count);
static void EndFrame();
static Oyster::Graphics::Render::Model* CreateModel(std::wstring filename);
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);
static void DeleteModel(Oyster::Graphics::Model::Model* model);
static State SetOptions(Option);
};

View File

@ -1,6 +1,5 @@
#include "OBJReader.h"
#include "..\Definitions\GraphicalDefinition.h"
#include "..\Core\Buffer.h"
#include <sstream>
#include <fstream>
@ -96,17 +95,17 @@ void OBJReader::readOBJFile( std::wstring fileName )
inStream.close();
}
Oyster::Graphics::Render::ModelInfo* OBJReader::toModel()
Oyster::Graphics::Model::ModelInfo* OBJReader::toModel()
{
Oyster::Graphics::Buffer* b = new Oyster::Graphics::Buffer();
Oyster::Graphics::Buffer::BUFFER_INIT_DESC desc;
Oyster::Graphics::Render::ModelInfo* modelInfo = new Oyster::Graphics::Render::ModelInfo();
Oyster::Graphics::Core::Buffer* b = new Oyster::Graphics::Core::Buffer();
Oyster::Graphics::Core::Buffer::BUFFER_INIT_DESC desc;
Oyster::Graphics::Model::ModelInfo* modelInfo = new Oyster::Graphics::Model::ModelInfo();
desc.ElementSize = 32;
desc.InitData = &this->_myOBJ[0];
desc.NumElements = this->_myOBJ.size();
desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
desc.Usage = Oyster::Graphics::Buffer::BUFFER_DEFAULT;
desc.Type = Oyster::Graphics::Core::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
desc.Usage = Oyster::Graphics::Core::Buffer::BUFFER_DEFAULT;
HRESULT hr = S_OK;
hr = b->Init(desc);

View File

@ -49,7 +49,7 @@ class OBJReader
~OBJReader();
void readOBJFile( std::wstring fileName);
Oyster::Graphics::Render::ModelInfo* toModel();
Oyster::Graphics::Model::ModelInfo* toModel();
};
#endif

View File

@ -2,22 +2,16 @@
#ifndef Mesh_h
#define Mesh_h
#include "ModelInfo.h"
namespace Oyster
{
namespace Graphics
{
namespace Render
namespace Model
{
struct Model
{
void* const info;
//ModelInfo* info;
void* data;
int size;
void* info;
Oyster::Math::Float4x4 WorldMatrix;
bool Visible;
};
}

View File

@ -3,19 +3,18 @@
#define MODELINFO_h
#include "..\Core\CoreIncludes.h"
#include "..\Core\Buffer.h"
#include "..\Core\Core.h"
namespace Oyster
{
namespace Graphics
{
namespace Render
namespace Model
{
struct ModelInfo
{
std::vector<ID3D11ShaderResourceView*> Material;
Buffer *Vertices,*Indecies;
Core::Buffer *Vertices,*Indecies;
bool Indexed;
int VertexCount;
};

View File

@ -1,6 +1,7 @@
#include "Render.h"
#include "../Resources/Resources.h"
#include "../../Definitions/GraphicalDefinition.h"
#include "../../Model/ModelInfo.h"
namespace Oyster
{
@ -28,27 +29,30 @@ namespace Oyster
Resources::VPData.Apply();
}
void Basic::RenderScene(Model* models, int count)
void Basic::RenderScene(Model::Model* models, int count)
{
for(int i = 0; i < count; ++i)
{
if(models[i].Visible)
{
void* data = Resources::ModelData.Map();
memcpy(data,&(models[i].data),64);
memcpy(data,&(models[i].WorldMatrix),64);
Resources::ModelData.Unmap();
//Set Materials :: NONE
models[i].info->Vertices->Apply();
if(models[i].info->Indexed)
Model
::ModelInfo* info = (Model::ModelInfo*)models[i].info;
info->Vertices->Apply();
if(info->Indexed)
{
models[i].info->Indecies->Apply();
Oyster::Graphics::Core::deviceContext->DrawIndexed(models[i].info->VertexCount,0,0);
info->Indecies->Apply();
Oyster::Graphics::Core::deviceContext->DrawIndexed(info->VertexCount,0,0);
}
else
{
Oyster::Graphics::Core::deviceContext->Draw(models[i].info->VertexCount,0);
Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0);
}
}
}

View File

@ -17,7 +17,7 @@ namespace Oyster
public:
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection);
static void RenderScene(Model* models, int count);
static void RenderScene(Model::Model* models, int count);
static void EndFrame();
};
}

View File

@ -11,6 +11,7 @@ const std::wstring PixelRed = L"DebugPixel";
typedef Oyster::Graphics::Core::ShaderManager::ShaderType ShaderType;
typedef Oyster::Graphics::Core::ShaderManager::Get GetShader;
typedef Oyster::Graphics::Core::ShaderManager Shader;
typedef Oyster::Graphics::Core::Buffer Buffer;
namespace Oyster
{
@ -99,7 +100,6 @@ namespace Oyster
obj.RenderStates.Rasterizer = rs;
#pragma endregion
return Core::Init::Sucsess;
}
}

View File

@ -16,8 +16,8 @@ namespace Oyster
{
public:
static Core::ShaderManager::ShaderEffect obj;
static Buffer ModelData;
static Buffer VPData;
static Core::Buffer ModelData;
static Core::Buffer VPData;
static Core::Init::State Init();
};

View File

@ -0,0 +1,25 @@
struct VertexOut
{
float4 pos : SV_POSITION;
float4 ViewPos: POSITION;
float2 UV : TEXCOORD;
float4 normal : NORMAL;
};
struct PixelOut
{
float4 Diffuse3Glow1 : SV_TARGET0;
float4 Normal3Specular1 : SV_TARGET1;
float4 VPos : SV_TARGET2;
};
Texture2D Diffuse;
Texture2D Specular;
PixelOut main(VertexOut input)
{
PixelOut output;
output.Diffuse3Glow1 = float4(1.0f, 0.0f, 0.0f, 1.0f);
output.Normal3Specular1 = float4(input.normal, 1.0f);
return output;
}

View File

@ -0,0 +1,37 @@
cbuffer PerFrame : register(b0)
{
matrix View;
float4x4 Projection;
matrix VP;
}
cbuffer PerModel : register(b1)
{
matrix World;
}
struct VertexIn
{
float3 pos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
};
struct VertexOut
{
float4 pos : SV_POSITION;
float4 ViewPos: POSITION;
float2 UV : TEXCOORD;
float4 normal : NORMAL;
};
VertexOut main( VertexIn input )
{
VertexOut output;
matrix WV = mul(View, World);
output.ViewPos = mul(WV, float4(input.pos,1));
output.pos = mul(Projection, output.ViewPos);
output.UV = input.UV;
output.normal = float4(input.normal, 0);
return output;
}

View File

@ -19,7 +19,7 @@
//--------------------------------------------------------------------------------------
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
Oyster::Graphics::Render::Model* m = new Oyster::Graphics::Render::Model();
Oyster::Graphics::Model::Model* m = new Oyster::Graphics::Model::Model();
Oyster::Math::Float4x4 V;
Oyster::Math::Float4x4 P;
@ -178,7 +178,8 @@ HRESULT InitDirect3D()
#pragma region Obj
OBJReader or;
or.readOBJFile(L"bth.obj");
m->info = or.toModel();
m->info = (void*)or.toModel();
m->Visible=true;
#pragma endregion
//*((Oyster::Math::Matrix)m->data) = Oyster::Math::Matrix::identity;