GL - merge with graphics api. Lobby and game state.

This commit is contained in:
Linda Andersson 2013-12-09 09:23:39 +01:00
commit 38a1602d3f
35 changed files with 515 additions and 72 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

233
Bin/Content/crate.obj Normal file
View File

@ -0,0 +1,233 @@
# This file uses centimeters as units for non-parametric coordinates.
mtllib crate.mtl
g default
v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000
v -0.500000 0.500000 0.500000
v 0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 0.500000 -0.500000
v -0.500000 -0.500000 -0.500000
v 0.500000 -0.500000 -0.500000
v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000
v 0.500000 0.500000 0.500000
v -0.500000 0.500000 0.500000
v 0.500000 0.500000 -0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 -0.500000 -0.500000
v -0.500000 -0.500000 -0.500000
v -0.479379 0.522314 0.479379
v 0.479379 0.522314 0.479379
v 0.479379 0.522314 -0.479379
v -0.479379 0.522314 -0.479379
v -0.470939 -0.528599 -0.470939
v 0.470939 -0.528599 -0.470939
v 0.470939 -0.528599 0.470939
v -0.470939 -0.528599 0.470939
v 0.520103 -0.460610 -0.460610
v 0.520103 -0.460610 0.460610
v 0.520103 0.460610 -0.460610
v 0.520103 0.460610 0.460610
v -0.522559 -0.464751 -0.464751
v -0.522559 -0.464751 0.464751
v -0.522559 0.464751 0.464751
v -0.522559 0.464751 -0.464751
v -0.460954 -0.460954 0.522335
v 0.460954 -0.460954 0.522335
v 0.460954 0.460954 0.522335
v -0.460954 0.460954 0.522335
v -0.466507 0.466507 -0.525017
v 0.466507 0.466507 -0.525017
v 0.466507 -0.466507 -0.525017
v -0.466507 -0.466507 -0.525017
vt 0.995838 0.004695
vt 0.999640 -0.003712
vt 0.003809 -0.000160
vt -0.000796 1.000526
vt 0.003809 0.003892
vt 0.999640 0.995671
vt 0.003809 0.007944
vt 0.999640 0.999723
vt 0.003809 1.003774
vt 0.999640 1.003774
vt 0.995035 0.004695
vt 0.995035 1.000526
vt 0.000007 0.004695
vt 0.000007 1.000526
vt 0.999640 0.007944
vt -0.000796 0.004695
vt 0.003809 0.999723
vt 0.003809 -0.003712
vt 0.999640 0.003892
vt 0.003809 0.995671
vt 0.999640 0.992119
vt 0.999640 -0.000160
vt 0.003809 0.992119
vt 0.995838 1.000526
vt 0.003809 -0.003712
vt 0.999640 -0.003712
vt 0.999640 0.992119
vt 0.003809 0.992119
vt 0.003809 -0.000160
vt 0.999640 -0.000160
vt 0.999640 0.995671
vt 0.003809 0.995671
vt 0.003809 0.003892
vt 0.999640 0.003892
vt 0.999640 0.999723
vt 0.003809 0.999723
vt 0.003809 0.007944
vt 0.999640 0.007944
vt 0.999640 1.003774
vt 0.003809 1.003774
vt -0.000796 0.004695
vt 0.995035 0.004695
vt 0.995035 1.000526
vt -0.000796 1.000526
vt 0.000007 0.004695
vt 0.995838 0.004695
vt 0.995838 1.000526
vt 0.000007 1.000526
vt 0.003809 -0.000160
vt 0.999640 -0.000160
vt 0.999640 0.995671
vt 0.003809 0.995671
vt 0.003809 0.007944
vt 0.999640 0.007944
vt 0.999640 1.003774
vt 0.003809 1.003774
vt -0.000796 0.004695
vt 0.995035 0.004695
vt 0.995035 1.000526
vt -0.000796 1.000526
vt 0.000007 0.004695
vt 0.995838 0.004695
vt 0.995838 1.000526
vt 0.000007 1.000526
vt 0.003809 -0.003712
vt 0.999640 -0.003712
vt 0.999640 0.992119
vt 0.003809 0.992119
vt 0.003809 0.003892
vt 0.999640 0.003892
vt 0.999640 0.999723
vt 0.003809 0.999723
vn -0.031209 -0.033799 0.998941
vn 0.033799 -0.031209 0.998941
vn -0.033799 0.031209 0.998941
vn 0.031209 0.033799 0.998941
vn -0.030245 0.999045 0.031527
vn 0.031527 0.999045 0.030245
vn -0.031527 0.999045 -0.030245
vn 0.030245 0.999045 -0.031527
vn -0.034614 0.037052 -0.998714
vn 0.037051 0.034614 -0.998714
vn -0.037051 -0.034614 -0.998714
vn 0.034614 -0.037052 -0.998714
vn -0.038824 -0.998397 -0.041174
vn 0.041174 -0.998397 -0.038824
vn -0.041174 -0.998397 0.038824
vn 0.038824 -0.998397 0.041174
vn 0.999134 -0.030589 0.028224
vn 0.999134 -0.028224 -0.030589
vn 0.999134 0.028224 0.030589
vn 0.999134 0.030589 -0.028224
vn -0.998933 -0.033811 -0.031470
vn -0.998933 -0.031470 0.033811
vn -0.998933 0.031470 -0.033811
vn -0.998933 0.033811 0.031470
vn 0.577350 0.577350 -0.577350
vn 0.577350 -0.577350 -0.577350
vn -0.577350 0.577350 -0.577350
vn -0.577350 -0.577350 -0.577350
vn 0.577350 -0.577350 0.577350
vn -0.577350 -0.577350 0.577350
vn 0.577350 0.577350 0.577350
vn -0.577350 0.577350 0.577350
vn -0.608285 0.469952 0.639637
vn 0.633500 0.454555 0.626145
vn 0.657522 0.474071 -0.585595
vn -0.626276 0.491669 -0.605013
vn -0.608373 -0.534484 -0.586694
vn 0.635292 -0.520408 -0.570596
vn 0.616200 -0.500955 0.607735
vn -0.589957 -0.516183 0.620891
s 1
g meshCrate
usemtl matCrateSG
f 33/65/1 34/66/2 36/68/3
f 36/68/3 34/66/2 35/67/4
f 17/49/5 18/50/6 20/52/7
f 20/52/7 18/50/6 19/51/8
f 37/69/9 38/70/10 40/72/11
f 40/72/11 38/70/10 39/71/12
f 21/53/13 22/54/14 24/56/15
f 24/56/15 22/54/14 23/55/16
f 26/57/17 25/58/18 28/60/19
f 28/60/19 25/58/18 27/59/20
f 29/61/21 30/62/22 32/64/23
f 32/64/23 30/62/22 31/63/24
s 7
f 1/25/25 3/28/26 2/26/27
f 2/26/27 3/28/26 4/27/28
f 3/29/26 5/32/29 4/30/28
f 4/30/28 5/32/29 6/31/30
f 5/33/29 7/36/31 6/34/30
f 6/34/30 7/36/31 8/35/32
f 7/37/31 1/40/25 8/38/32
f 8/38/32 1/40/25 2/39/27
f 2/41/27 4/44/28 8/42/32
f 8/42/32 4/44/28 6/43/30
f 7/45/31 5/48/29 1/46/25
f 1/46/25 5/48/29 3/47/26
s 1
f 12/3/33 11/22/34 17/49/5
f 17/49/5 11/22/34 18/50/6
f 11/22/34 13/6/35 18/50/6
f 18/50/6 13/6/35 19/51/8
f 13/6/35 14/20/36 19/51/8
f 19/51/8 14/20/36 20/52/7
f 14/20/36 12/3/33 20/52/7
f 20/52/7 12/3/33 17/49/5
f 16/7/37 15/15/38 21/53/13
f 21/53/13 15/15/38 22/54/14
f 15/15/38 10/10/39 22/54/14
f 22/54/14 10/10/39 23/55/16
f 10/10/39 9/9/40 23/55/16
f 23/55/16 9/9/40 24/56/15
f 9/9/40 16/7/37 24/56/15
f 24/56/15 16/7/37 21/53/13
f 10/16/39 15/11/38 26/57/17
f 26/57/17 15/11/38 25/58/18
f 15/11/38 13/12/35 25/58/18
f 25/58/18 13/12/35 27/59/20
f 13/12/35 11/4/34 27/59/20
f 27/59/20 11/4/34 28/60/19
f 11/4/34 10/16/39 28/60/19
f 28/60/19 10/16/39 26/57/17
f 16/13/37 9/1/40 29/61/21
f 29/61/21 9/1/40 30/62/22
f 9/1/40 12/24/33 30/62/22
f 30/62/22 12/24/33 31/63/24
f 12/24/33 14/14/36 31/63/24
f 31/63/24 14/14/36 32/64/23
f 14/14/36 16/13/37 32/64/23
f 32/64/23 16/13/37 29/61/21
f 9/18/40 10/2/39 33/65/1
f 33/65/1 10/2/39 34/66/2
f 10/2/39 11/21/34 34/66/2
f 34/66/2 11/21/34 35/67/4
f 11/21/34 12/23/33 35/67/4
f 35/67/4 12/23/33 36/68/3
f 12/23/33 9/18/40 36/68/3
f 36/68/3 9/18/40 33/65/1
f 14/5/36 13/19/35 37/69/9
f 37/69/9 13/19/35 38/70/10
f 13/19/35 15/8/38 38/70/10
f 38/70/10 15/8/38 39/71/12
f 15/8/38 16/17/37 39/71/12
f 39/71/12 16/17/37 40/72/11
f 16/17/37 14/5/36 40/72/11
f 40/72/11 14/5/36 37/69/9

BIN
Bin/Content/tex_crate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -175,7 +175,7 @@ namespace DanBias
{
inputObj->Update();
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
state = m_data->gameClientState->Update();
state = m_data->gameClientState->Update(deltaTime, inputObj);
if(state != Client::GameClientState::ClientState_Same)
{
@ -221,6 +221,8 @@ namespace DanBias
HRESULT DanBiasGame::CleanUp()
{
delete m_data->gameClientState;
delete m_data;
return S_OK;
}

View File

@ -1,4 +1,7 @@
#pragma once
#define NOMINMAX
#include "L_inputClass.h"
namespace DanBias
{
namespace Client
@ -18,7 +21,7 @@ public:
GameClientState(void);
virtual ~GameClientState(void);
virtual bool Init() = 0;
virtual ClientState Update() = 0;
virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0;
virtual bool Render() = 0;
virtual bool Release() = 0;
};

View File

@ -1,6 +1,15 @@
#include "GameState.h"
#include "DllInterfaces/GFXAPI.h"
using namespace DanBias::Client;
struct GameState::myData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
Oyster::Graphics::Model::Model *model;
}privData;
GameState::GameState(void)
{
}
@ -11,16 +20,33 @@ GameState::~GameState(void)
}
bool GameState::Init()
{
// load models
privData = new myData();
privData->model = Oyster::Graphics::API::CreateModel(L"crate");
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
Oyster::Graphics::API::SetProjection(privData->proj);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
}
GameClientState::ClientState GameState::Update()
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
{
if(KeyInput->IsKeyPressed(DIK_L))
return ClientState_Lobby;
// send key input to server.
return ClientState_Same;
}
bool GameState::Render()
{
Oyster::Graphics::API::NewFrame(Oyster::Math3D::Float4x4::null, Oyster::Math3D::Float4x4::null);
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj);
Oyster::Graphics::API::NewFrame();
//Oyster::Graphics::API::RenderModel(*(privData->model));
Oyster::Graphics::API::EndFrame();
return true;
}

View File

@ -6,11 +6,14 @@ namespace Client
{
class GameState : public GameClientState
{
private:
struct myData;
myData* privData;
public:
GameState(void);
~GameState(void);
bool Init();
GameClientState::ClientState Update();
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput);
bool Render();
bool Release();
};

View File

@ -3,12 +3,13 @@
#include "OysterMath.h"
using namespace DanBias::Client;
struct myData
struct LobbyState::myData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
Oyster::Graphics::Model::Model *model;
}data;
}privData;
LobbyState::LobbyState(void)
@ -19,29 +20,40 @@ LobbyState::LobbyState(void)
LobbyState::~LobbyState(void)
{
Oyster::Graphics::API::DeleteModel(privData->model);
Oyster::Graphics::API::Clean();
}
bool LobbyState::Init()
{
data.model = Oyster::Graphics::API::CreateModel(L"crate");
// load models
privData = new myData();
privData->model = Oyster::Graphics::API::CreateModel(L"crate");
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1);
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 100);
data.view = Oyster::Math3D::ViewMatrix_LookAtDirection(dir, up, pos);
data.proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 10);
return true;
}
GameClientState::ClientState LobbyState::Update()
GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput)
{
//if( startGame)
// return ClientState_Game;
if( KeyInput->IsKeyPressed(DIK_Q))
return ClientState_Game;
return ClientState_Same;
}
bool LobbyState::Render()
{
Oyster::Graphics::API::NewFrame(data.view, data.proj);
Oyster::Graphics::API::RenderScene(data.model,1);
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj);
Oyster::Graphics::API::NewFrame();
Oyster::Graphics::API::RenderModel(*(privData->model));
Oyster::Graphics::API::EndFrame();
return true;
}

View File

@ -4,16 +4,17 @@ namespace DanBias
{
namespace Client
{
struct myData;
class LobbyState : public GameClientState
{
private:
struct myData;
myData* privData;
public:
LobbyState(void);
~LobbyState(void);
bool Init();
ClientState Update();
ClientState Update(float deltaTime, InputClass* KeyInput);
bool Render();
bool Release();
};};};

View File

@ -71,7 +71,9 @@ void Game::Update(keyInput keyPressed, float pitch, float yaw)
}
void Game::Render()
{
Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj());
Oyster::Graphics::API::SetView(camera->View());
Oyster::Graphics::API::SetProjection(camera->Proj());
Oyster::Graphics::API::NewFrame();
player->Render();
box->Render();
}

View File

@ -120,11 +120,12 @@ void OysterResource::Clean()
//Remove all the references
while (!OResource::Release(i->second));
const wchar_t* temp = i->second->GetResourceFilename();
std::wstring temp = i->second->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}
resourcePrivate.resources.clear();
}
void OysterResource::ReleaseResource(const OHRESOURCE& resourceData)
{
@ -133,7 +134,7 @@ void OysterResource::ReleaseResource(const OHRESOURCE& resourceData)
{
if(OResource::Release(t))
{
const wchar_t* temp = t->GetResourceFilename();
std::wstring temp = t->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}
@ -146,7 +147,7 @@ void OysterResource::ReleaseResource(const wchar_t filename[])
{
if(OResource::Release(t))
{
const wchar_t* temp = t->GetResourceFilename();
std::wstring temp = t->GetResourceFilename();
delete resourcePrivate.resources[temp];
resourcePrivate.resources.erase(temp);
}

View File

@ -17,7 +17,7 @@ std::wstring GetErrorMessage(int errorCode)
LPWSTR lpMessage;
std::wstring retVal(L"Succesful");
DWORD bufLen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS ,
DWORD bufLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS ,
NULL,
errorCode ,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) ,

View File

@ -33,6 +33,7 @@ namespace Oyster
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
D3D_FEATURE_LEVEL featureLevelsToTry[] =
{

View File

@ -279,7 +279,7 @@ namespace Oyster
void Core::ShaderManager::Clean()
{
for(int i = 0; i < VData.size(); ++i)
for(int i = 0; i < (int)VData.size(); ++i)
{
delete[] VData[i].data;
}

View File

@ -4,11 +4,18 @@
#include "../Render/Rendering/Render.h"
#include "../FileLoader/ObjReader.h"
#include "../../Misc/Resource/OysterResource.h"
#include "../FileLoader/GeneralLoader.h"
namespace Oyster
{
namespace Graphics
{
namespace
{
Math::Float4x4 View;
Math::Float4x4 Projection;
}
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
{
Core::resolution = resulotion;
@ -26,16 +33,31 @@ namespace Oyster
return API::Sucsess;
}
void API::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection)
void API::SetProjection(Math::Float4x4& projection)
{
Projection = projection;
}
void API::SetView(Math::Float4x4& view)
{
View = view;
}
void API::NewFrame()
{
Render::Rendering::Basic::NewFrame(View, Projection);
}
void API::RenderScene(Model::Model* models, int count)
void API::RenderScene(Model::Model models[], int count)
{
Render::Rendering::Basic::RenderScene(models,count);
}
void API::RenderModel(Model::Model& m)
{
Render::Rendering::Basic::RenderScene(&m,1);
}
void API::EndFrame()
{
Render::Rendering::Basic::EndFrame();
@ -52,9 +74,7 @@ namespace Oyster
m->WorldMatrix = Oyster::Math::Float4x4::identity;
m->Visible = true;
OBJReader or;
or.readOBJFile(filename);
m->info = or.toModel();
m->info = Oyster::Resource::OysterResource::LoadResource(filename.c_str(),Oyster::Graphics::Loading::LoadOBJ);
return m;
}
@ -63,7 +83,7 @@ namespace Oyster
{
Model::ModelInfo* info = (Model::ModelInfo*)model->info;
delete model;
info->Vertices->~Buffer();
Oyster::Resource::OysterResource::ReleaseResource((Oyster::Resource::OHRESOURCE)info);
}
void API::Clean()
@ -72,6 +92,14 @@ namespace Oyster
Oyster::Resource::OysterResource::Clean();
Oyster::Graphics::Core::ShaderManager::Clean();
Oyster::Graphics::Render::Resources::Clean();
SAFE_RELEASE(Core::depthStencil);
SAFE_RELEASE(Core::backBufferRTV);
SAFE_RELEASE(Core::backBufferUAV);
SAFE_RELEASE(Core::swapChain);
SAFE_RELEASE(Core::deviceContext);
SAFE_RELEASE(Core::device);
}
}
}

View File

@ -4,10 +4,10 @@
#include "OysterMath.h"
#include <Windows.h>
#if defined GFX_DLL_EXPORT
#ifdef GFX_DLL_EXPORT
#define GFX_DLL_USAGE __declspec(dllexport)
#else
#define GFX_DLL_USAGE __declspec(dllimport)
#define GFX_DLL_USAGE
#endif
namespace Oyster
@ -28,9 +28,14 @@ namespace Oyster
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion);
static void Clean();
//! @brief from Oyster::Math Float4x4, expects corect methods
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection);
static void RenderScene(Oyster::Graphics::Model::Model* models, int count);
static void SetView(Oyster::Math::Float4x4& View);
static void SetProjection(Oyster::Math::Float4x4& Projection);
//! @brief will internally use last values from SetView and SetProjection
static void NewFrame();
static void RenderScene(Oyster::Graphics::Model::Model models[], int count);
static void RenderModel(Oyster::Graphics::Model::Model& model);
static void EndFrame();
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);

View File

@ -27,7 +27,8 @@ namespace Oyster
void UnloadShaderD(void* loadedData);
void LoadShaderD(const wchar_t filename[], Oyster::Resource::CustomData& out);
void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type);
void UnloadOBJ(void* loadedData);
void LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out);
}
}
}

View File

@ -1,6 +1,7 @@
#include "GeneralLoader.h"
#include "..\Core\Dx11Includes.h"
#include "..\Core\Core.h"
#include "ObjReader.h"
HRESULT CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
ID3D11DeviceContext* d3dContext,
@ -35,6 +36,30 @@ void Oyster::Graphics::Loading::UnloadTexture(void* data)
SAFE_RELEASE(srv);
}
void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out)
{
OBJReader obj;
obj.readOBJFile(filename);
Model::ModelInfo* info;
info = obj.toModel();
out.loadedData = info;
out.resourceUnloadFnc = Oyster::Graphics::Loading::UnloadOBJ;
}
void Oyster::Graphics::Loading::UnloadOBJ(void* data)
{
Model::ModelInfo* info = (Model::ModelInfo*) data;
SAFE_DELETE(info->Vertices);
if(info->Indexed)
{
SAFE_DELETE(info->Indecies);
}
for(int i =0;i<info->Material.size();++i)
{
Oyster::Resource::OysterResource::ReleaseResource(info->Material[i]);
}
delete info;
}
#include <wrl.h>
#include <memory>

View File

@ -95,7 +95,7 @@ void OBJReader::readOBJFile( std::wstring fileName )
inStream.close();
Mat = Oyster::Resource::OysterResource::LoadResource((fileName + L".jpg").c_str(),Oyster::Graphics::Loading::LoadTexture);
Mat = Oyster::Resource::OysterResource::LoadResource((fileName + L".png").c_str(),Oyster::Graphics::Loading::LoadTexture);
}
Oyster::Graphics::Model::ModelInfo* OBJReader::toModel()

View File

@ -10,6 +10,8 @@ namespace Oyster
{
namespace Loading
{
void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type);
void UnloadShaderP(void* loadedData)
{
ID3D11PixelShader* ps = ((ID3D11PixelShader*)loadedData);
@ -165,14 +167,16 @@ namespace Oyster
data.data = new char[data.size];
memcpy(data.data,Shader->GetBufferPointer(),data.size);
#else
std::ifstream stream;
stream.open(filename, std::ifstream::in | std::ifstream::binary);
if(stream.good())
{
stream.seekg(0, std::ios::end);
sd.size = size_t(stream.tellg());
sd.data = new char[sd.size];
data.size = size_t(stream.tellg());
data.data = new char[data.size];
stream.seekg(0, std::ios::beg);
stream.read(&sd.data[0], sd.size);
stream.read(&data.data[0], data.size);
stream.close();
}
else
@ -180,7 +184,6 @@ namespace Oyster
memset(&out,0,sizeof(out));
return;
}
#endif
out.loadedData = Core::ShaderManager::CreateShader(data, Core::ShaderManager::ShaderType(type));
}

View File

@ -109,6 +109,7 @@
</ProjectReference>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -124,12 +125,13 @@
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
@ -143,12 +145,14 @@
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<EnableDebuggingInformation>true</EnableDebuggingInformation>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
@ -162,6 +166,8 @@
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)..\Bin\Content\Shaders\%(Filename).cso</ObjectFileOutput>
<EnableDebuggingInformation>true</EnableDebuggingInformation>
<ShaderModel>5.0</ShaderModel>
</FxCompile>
</ItemDefinitionGroup>
<ItemGroup>
@ -172,7 +178,7 @@
<ClCompile Include="DllInterfaces\GFXAPI.cpp" />
<ClCompile Include="FileLoader\ObjReader.cpp" />
<ClCompile Include="FileLoader\ShaderLoader.cpp" />
<ClCompile Include="FileLoader\TextureLoader.cpp" />
<ClCompile Include="FileLoader\ModelLoader.cpp" />
<ClCompile Include="Render\Preparations\BasicPreparations.cpp" />
<ClCompile Include="Render\Rendering\BasicRender.cpp" />
<ClCompile Include="Render\Resources\Resources.cpp" />
@ -264,6 +270,8 @@
<ItemGroup>
<None Include="Shader\HLSL\Deffered Shaders\GatherGBuffer\GBufferHeader.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\Defines.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\LightCalc.hlsli" />
<None Include="Shader\HLSL\Deffered Shaders\Render\PosManipulation.hlsli" />
<None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -2,6 +2,8 @@
#include "../Resources/Resources.h"
#include "../../Definitions/GraphicalDefinition.h"
#include "../../Model/ModelInfo.h"
#include <map>
#include <vector>
namespace Oyster
{
@ -60,7 +62,8 @@ namespace Oyster
}
void Basic::EndFrame()
{
Core::swapChain->Present(0,0);
IDXGISwapChain* chain = Core::swapChain;
chain->Present(0,0);
}
}
}

View File

@ -3,7 +3,8 @@
// /Bin/Executable/Tester ->
// /Code/OysterGraphics/Shader/HLSL
const std::wstring PathFromExeToHlsl = L"..\\..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\";
const std::wstring PathFromExeToCso = L"..\\Content\\Shaders\\";
const std::wstring PathFromExeToHlsl = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\";
const std::wstring VertexTransformDebug = L"TransformDebugVertex";
const std::wstring VertexDebug = L"DebugVertex";
const std::wstring PixelRed = L"DebugPixel";
@ -42,6 +43,12 @@ namespace Oyster
#else
/** Load Vertex Shader with Precompiled */
Core::ShaderManager::Init(PathFromExeToCso + L"DebugCameraVertex.cso",ShaderType::Vertex, VertexTransformDebug);
Core::ShaderManager::Init(PathFromExeToCso + L"DebugVertex.cso",ShaderType::Vertex, VertexDebug);
/** Load Pixel Shader with Precompiled */
Core::ShaderManager::Init(PathFromExeToCso + L"DebugPixel.cso",ShaderType::Pixel, PixelRed);
Core::ShaderManager::Init(PathFromExeToCso + L"TextureDebug.cso",ShaderType::Pixel, PixelTexture);
#endif
#pragma endregion
@ -152,10 +159,9 @@ namespace Oyster
void Resources::Clean()
{
Resources::ModelData.~Buffer();
Resources::VPData.~Buffer();
for(int i = 0; i < obj.CBuffers.Vertex.size(); ++i)
{
//SAFE_RELEASE(obj.CBuffers.Vertex[i]);
obj.CBuffers.Vertex[i]->~Buffer();
}
for(int i = 0; i < obj.CBuffers.Pixel.size(); ++i)
{

View File

@ -1,7 +1,31 @@
#ifndef DEFINES
#define DEFINES
struct PointLight
{
float3 Pos;
float Radius;
float4 PosRadius;
float4 ColorBright;
};
float3 Color;
struct DiffSpec
{
float3 Diffuse;
float3 Specular;
};
cbuffer PointLights : register(b0)
{
PointLight pl;
}
cbuffer LightConstants : register(b1)
{
float4x4 InvProj;
int2 Pixels;
}
Texture2D DiffuseGlow : register(t0);
Texture2D NormalSpec : register(t1);
Texture2D DepthTexture : register(t2);
#endif

View File

@ -0,0 +1,23 @@
#include "Defines.hlsli"
DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
{
DiffSpec output;
float4 normalSpec = NormalSpec[texCoord];
float3 lightVec = pl.PosRadius.xyz - pos.xyz;
float d = length(lightVec);
lightVec = lightVec/d;
float diffFactor = max(dot(lightVec, normalSpec.xyz), 0.0f);
float3 v = reflect(-lightVec, normalSpec.xyz);
float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w);
//Check att later
float att = (max(d-pl.PosRadius.w,0)/pow(pl.PosRadius.w,2));
//fix Ilum calcs instead of PhongBlinn
output.Diffuse = pl.ColorBright.w * att * diffFactor * pl.ColorBright.xyz;
output.Specular = pl.ColorBright.w * att * specFactor * pl.ColorBright.xyz;
if(diffFactor == 0)
output.Specular * 0;
return output;
}

View File

@ -1,11 +1,16 @@
#include "Defines.hlsli"
#include "LightCalc.hlsli"
#include "PosManipulation.hlsli"
//todo
//LightCulling
//Calc Diff + Spec
//Calc Ambience
//Write Glow
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
float3 ViewPos = ToVpos(DTid.xy);
//DiffSpec LightCalc(pl, float3 pos)
}

View File

@ -0,0 +1,21 @@
#include "Defines.hlsli"
//assumes ProperfloatTexCoords
float3 ToVpos(float2 texCoord)
{
//Get proper UV
float2 UV = float2(texCoord) / float2(Pixels);
float4 ViewPos;
// Get the depth value for this pixel
ViewPos.z= DepthTexture[texCoord].x;
//Get X/w
ViewPos.x = UV.x * 2 - 1;
//Get Y/w
ViewPos.y = 1 - 2 * UV.y;
ViewPos.w = 1;
//Un project
ViewPos = mul(ViewPos, InvProj);
return ViewPos.xyz / ViewPos.w;
}

View File

@ -18,6 +18,7 @@
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
Oyster::Graphics::Model::Model* m = NULL;
Oyster::Graphics::Model::Model* m2 = NULL;
Oyster::Math::Float4x4 V;
Oyster::Math::Float4x4 P;
@ -41,7 +42,7 @@ HRESULT InitDirect3D();
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
BOOL b = SetDllDirectoryW(L"..\\..\\DLL");
BOOL b = SetDllDirectoryW(L"..\\DLL");
typedef struct tagLOADPARMS32
{
LPSTR lpEnvAddress; // address of environment strings
@ -92,6 +93,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
}
Oyster::Graphics::API::DeleteModel(m);
Oyster::Graphics::API::DeleteModel(m2);
Oyster::Graphics::API::Clean();
return (int) msg.wParam;
}
@ -186,11 +188,15 @@ HRESULT InitDirect3D()
#pragma endregion
#pragma region Obj
m = Oyster::Graphics::API::CreateModel(L"orca");
m = Oyster::Graphics::API::CreateModel(L"crate");
m2 = Oyster::Graphics::API::CreateModel(L"crate");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
#pragma endregion
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
Oyster::Graphics::API::SetProjection(P);
P.Invert();
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
V = Oyster::Math3D::InverseOrientationMatrix(V);
@ -203,14 +209,17 @@ HRESULT Update(float deltaTime)
{
angle += Oyster::Math::pi/30000;
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,0,1)*-angle,Oyster::Math::Float3(0,4,0),Oyster::Math::Float3::null);
return S_OK;
}
HRESULT Render(float deltaTime)
{
Oyster::Graphics::API::NewFrame(V,P);
Oyster::Graphics::API::SetView(V);
Oyster::Graphics::API::NewFrame();
Oyster::Graphics::API::RenderScene(m,1);
Oyster::Graphics::API::RenderModel(*m);
Oyster::Graphics::API::RenderModel(*m2);
Oyster::Graphics::API::EndFrame();

View File

@ -69,7 +69,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
@ -77,7 +77,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
@ -85,7 +85,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
@ -93,7 +93,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>C:\Program Files (x86)\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Program Files (x86)\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
@ -113,7 +113,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>OysterGraphics_x86D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<ProjectReference>
<LinkLibraryDependencies>
@ -136,7 +136,6 @@
<AdditionalDependencies>OysterGraphics_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<PreventDllBinding>true</PreventDllBinding>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -144,9 +143,9 @@
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\OysterGraphics;..\OysterMath;..\Misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@ -159,7 +158,7 @@
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<PreventDllBinding>true</PreventDllBinding>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<DelayLoadDLLs>OysterGraphics_x86.dll;</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -167,7 +166,7 @@
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -182,7 +181,6 @@
<AdditionalDependencies>OysterGraphics_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)..\Bin\DLL;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<PreventDllBinding>true</PreventDllBinding>
<DelayLoadDLLs>OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemGroup>