2013-11-26 13:44:58 +01:00
|
|
|
#include "GFXAPI.h"
|
|
|
|
#include "../Core/Core.h"
|
2014-02-07 15:52:07 +01:00
|
|
|
#include "../Render/Resources.h"
|
|
|
|
#include "../Render/DefaultRenderer.h"
|
2013-11-26 15:33:05 +01:00
|
|
|
#include "../FileLoader/ObjReader.h"
|
2014-01-31 16:29:50 +01:00
|
|
|
#include "../../Misc/Resource/ResourceManager.h"
|
2013-12-05 14:56:34 +01:00
|
|
|
#include "../FileLoader/GeneralLoader.h"
|
2014-01-16 09:30:01 +01:00
|
|
|
#include "../Model/ModelInfo.h"
|
2014-02-07 15:52:07 +01:00
|
|
|
#include "../Render/GuiRenderer.h"
|
2014-01-08 07:01:59 +01:00
|
|
|
#include <vld.h>
|
2013-11-26 13:44:58 +01:00
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Graphics
|
|
|
|
{
|
2013-12-05 14:56:34 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
Math::Float4x4 View;
|
|
|
|
Math::Float4x4 Projection;
|
2014-02-10 16:08:03 +01:00
|
|
|
std::vector<Definitions::Pointlight> Lights;
|
2014-02-10 13:59:45 +01:00
|
|
|
float deltaTime;
|
2013-12-05 14:56:34 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 15:33:05 +01:00
|
|
|
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
|
2013-11-26 13:44:58 +01:00
|
|
|
{
|
2013-11-26 15:33:05 +01:00
|
|
|
Core::resolution = resulotion;
|
|
|
|
|
2013-11-26 13:44:58 +01:00
|
|
|
if(Core::Init::FullInit(Window, MSAA_Quality, Fullscreen) == Core::Init::Fail)
|
|
|
|
{
|
|
|
|
return API::Fail;
|
|
|
|
}
|
2014-02-11 13:29:19 +01:00
|
|
|
Render::Resources::Gui::Text::Font = (ID3D11ShaderResourceView*)API::CreateTexture(L"font_generic.png");
|
2014-02-07 15:52:07 +01:00
|
|
|
Render::Resources::Init();
|
2013-11-26 15:33:05 +01:00
|
|
|
|
|
|
|
Render::Preparations::Basic::SetViewPort();
|
2013-11-26 13:44:58 +01:00
|
|
|
return API::Sucsess;
|
|
|
|
}
|
|
|
|
|
2014-02-10 16:22:23 +01:00
|
|
|
void API::SetProjection(const Math::Float4x4& projection)
|
2013-12-05 14:56:34 +01:00
|
|
|
{
|
|
|
|
Projection = projection;
|
|
|
|
}
|
|
|
|
|
2014-02-10 16:22:23 +01:00
|
|
|
void API::SetView(const Math::Float4x4& view)
|
2013-12-05 14:56:34 +01:00
|
|
|
{
|
|
|
|
View = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void API::NewFrame()
|
2013-11-26 13:44:58 +01:00
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
if(Lights.size())
|
|
|
|
{
|
2014-02-12 08:24:24 +01:00
|
|
|
Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size());
|
2013-12-18 20:28:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-12 08:24:24 +01:00
|
|
|
Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0);
|
2013-12-18 20:28:06 +01:00
|
|
|
}
|
2013-11-26 13:44:58 +01:00
|
|
|
}
|
|
|
|
|
2013-12-05 14:56:34 +01:00
|
|
|
void API::RenderScene(Model::Model models[], int count)
|
2013-11-26 13:44:58 +01:00
|
|
|
{
|
2014-02-10 13:59:45 +01:00
|
|
|
Render::DefaultRenderer::RenderScene(models,count, View, Projection, deltaTime);
|
2013-11-26 13:44:58 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:59:45 +01:00
|
|
|
void API::RenderModel(Model::Model* m)
|
2013-12-05 14:56:34 +01:00
|
|
|
{
|
2014-02-10 13:59:45 +01:00
|
|
|
Render::DefaultRenderer::RenderScene(m,1, View, Projection, deltaTime);
|
2013-12-05 14:56:34 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 15:33:05 +01:00
|
|
|
void API::EndFrame()
|
|
|
|
{
|
2014-02-07 15:52:07 +01:00
|
|
|
Render::DefaultRenderer::EndFrame();
|
2013-11-26 15:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
API::State API::SetOptions(API::Option option)
|
|
|
|
{
|
2014-01-31 16:29:50 +01:00
|
|
|
Core::modelPath = option.modelPath;
|
|
|
|
Core::texturePath = option.texturePath;
|
2013-11-26 15:33:05 +01:00
|
|
|
return API::Sucsess;
|
|
|
|
}
|
|
|
|
|
2014-01-16 09:30:01 +01:00
|
|
|
//returns null for invalid filenames
|
2013-11-26 15:33:05 +01:00
|
|
|
Model::Model* API::CreateModel(std::wstring filename)
|
|
|
|
{
|
|
|
|
Model::Model* m = new Model::Model();
|
|
|
|
m->WorldMatrix = Oyster::Math::Float4x4::identity;
|
|
|
|
m->Visible = true;
|
2014-02-10 13:59:45 +01:00
|
|
|
m->Animation.AnimationPlaying = NULL;
|
2014-02-12 16:21:46 +01:00
|
|
|
m->Tint = Math::Float3(1);
|
2014-01-31 16:29:50 +01:00
|
|
|
m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN);
|
2013-11-26 15:33:05 +01:00
|
|
|
|
2014-01-16 09:30:01 +01:00
|
|
|
Model::ModelInfo* mi = (Model::ModelInfo*)m->info;
|
2014-01-20 16:36:25 +01:00
|
|
|
if(!mi || mi->Vertices->GetBufferPointer() == NULL)
|
2014-01-16 09:30:01 +01:00
|
|
|
{
|
2014-01-17 09:05:18 +01:00
|
|
|
delete m;
|
2014-02-14 14:27:38 +01:00
|
|
|
Core::loader.ReleaseResource(mi);
|
|
|
|
delete mi;
|
2014-01-16 09:30:01 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-26 15:33:05 +01:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void API::DeleteModel(Model::Model* model)
|
|
|
|
{
|
2014-01-16 09:30:01 +01:00
|
|
|
if(model==NULL)
|
|
|
|
return;
|
2013-11-29 10:25:27 +01:00
|
|
|
Model::ModelInfo* info = (Model::ModelInfo*)model->info;
|
2013-11-26 15:33:05 +01:00
|
|
|
delete model;
|
2014-01-31 16:29:50 +01:00
|
|
|
Core::loader.ReleaseResource(info);
|
2013-11-29 10:25:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void API::Clean()
|
|
|
|
{
|
2014-02-11 13:29:19 +01:00
|
|
|
DeleteTexture(Render::Resources::Gui::Text::Font);
|
2013-11-29 10:25:27 +01:00
|
|
|
SAFE_DELETE(Core::viewPort);
|
2014-01-31 16:29:50 +01:00
|
|
|
Core::loader.Clean();
|
2013-12-18 20:28:06 +01:00
|
|
|
Oyster::Graphics::Core::PipelineManager::Clean();
|
2014-02-07 15:52:07 +01:00
|
|
|
Oyster::Graphics::Render::Resources::Clean();
|
2013-12-05 14:56:34 +01:00
|
|
|
|
|
|
|
SAFE_RELEASE(Core::depthStencil);
|
2013-12-18 20:28:06 +01:00
|
|
|
SAFE_RELEASE(Core::depthStencilUAV);
|
2013-12-05 14:56:34 +01:00
|
|
|
SAFE_RELEASE(Core::backBufferRTV);
|
|
|
|
SAFE_RELEASE(Core::backBufferUAV);
|
|
|
|
|
|
|
|
SAFE_RELEASE(Core::swapChain);
|
|
|
|
SAFE_RELEASE(Core::deviceContext);
|
|
|
|
SAFE_RELEASE(Core::device);
|
2013-11-26 15:33:05 +01:00
|
|
|
}
|
2013-12-18 20:28:06 +01:00
|
|
|
|
2014-02-10 16:08:03 +01:00
|
|
|
void API::AddLight(Definitions::Pointlight light)
|
2013-12-18 20:28:06 +01:00
|
|
|
{
|
|
|
|
Lights.push_back(light);
|
|
|
|
}
|
|
|
|
|
|
|
|
void API::ClearLights()
|
|
|
|
{
|
|
|
|
Lights.clear();
|
|
|
|
}
|
2014-01-08 07:01:59 +01:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
API::State API::ReloadShaders()
|
|
|
|
{
|
2014-02-07 15:52:07 +01:00
|
|
|
Render::Resources::InitShaders();
|
2014-01-08 07:01:59 +01:00
|
|
|
return State::Sucsess;
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-05 16:54:57 +01:00
|
|
|
|
|
|
|
API::Option API::GetOption()
|
|
|
|
{
|
|
|
|
Option o;
|
|
|
|
o.BytesUsed = Core::UsedMem;
|
|
|
|
o.modelPath = Core::modelPath;
|
|
|
|
o.texturePath = Core::texturePath;
|
|
|
|
return o;
|
|
|
|
}
|
2014-02-07 11:52:51 +01:00
|
|
|
|
|
|
|
void API::StartGuiRender()
|
|
|
|
{
|
2014-02-11 13:29:19 +01:00
|
|
|
Render::Gui::Begin2DRender();
|
2014-02-07 11:52:51 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 16:27:53 +01:00
|
|
|
void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color)
|
2014-02-07 11:52:51 +01:00
|
|
|
{
|
2014-02-12 09:24:37 +01:00
|
|
|
Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color);
|
2014-02-07 11:52:51 +01:00
|
|
|
}
|
2014-02-07 13:15:38 +01:00
|
|
|
|
|
|
|
API::Texture API::CreateTexture(std::wstring filename)
|
|
|
|
{
|
|
|
|
return Core::loader.LoadResource((Core::texturePath + filename).c_str(),Oyster::Graphics::Loading::LoadTexture, Oyster::Graphics::Loading::UnloadTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void API::DeleteTexture(API::Texture tex)
|
|
|
|
{
|
|
|
|
Core::loader.ReleaseResource(tex);
|
|
|
|
}
|
2014-02-10 11:53:44 +01:00
|
|
|
|
|
|
|
float API::PlayAnimation(Model::Model* m, std::wstring name,bool looping)
|
|
|
|
{
|
2014-02-14 14:27:38 +01:00
|
|
|
if(m==NULL)
|
|
|
|
return 0;
|
2014-02-10 13:59:45 +01:00
|
|
|
m->Animation.AnimationPlaying = &(*m->info->Animations.find(name)).second;
|
|
|
|
m->Animation.AnimationTime=0;
|
|
|
|
m->Animation.LoopAnimation = looping;
|
2014-02-12 08:24:24 +01:00
|
|
|
return (float)m->Animation.AnimationPlaying->duration;
|
2014-02-10 13:59:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void API::Update(float dt)
|
|
|
|
{
|
|
|
|
deltaTime = dt;
|
2014-02-10 11:53:44 +01:00
|
|
|
}
|
2014-02-11 13:29:19 +01:00
|
|
|
|
|
|
|
void API::StartTextRender()
|
|
|
|
{
|
|
|
|
Render::Gui::Begin2DTextRender();
|
|
|
|
}
|
|
|
|
|
2014-02-13 16:27:53 +01:00
|
|
|
void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color)
|
2014-02-11 13:29:19 +01:00
|
|
|
{
|
2014-02-13 16:27:53 +01:00
|
|
|
Render::Gui::RenderText(text, Pos, Size, FontSize, color);
|
2014-02-11 13:29:19 +01:00
|
|
|
}
|
2013-11-26 13:44:58 +01:00
|
|
|
}
|
|
|
|
}
|