Danbias/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp

204 lines
4.8 KiB
C++
Raw Normal View History

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"
#include "../FileLoader/GeneralLoader.h"
#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
{
namespace
{
Math::Float4x4 View;
Math::Float4x4 Projection;
std::vector<Definitions::Pointlight> Lights;
2014-02-10 13:59:45 +01:00
float deltaTime;
}
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)
{
Projection = projection;
}
2014-02-10 16:22:23 +01:00
void API::SetView(const Math::Float4x4& view)
{
View = view;
}
void API::NewFrame()
2013-11-26 13:44:58 +01:00
{
if(Lights.size())
{
Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size());
}
else
{
Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0);
}
2013-11-26 13:44:58 +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)
{
2014-02-10 13:59:45 +01:00
Render::DefaultRenderer::RenderScene(m,1, View, Projection, deltaTime);
}
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;
}
//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
Model::ModelInfo* mi = (Model::ModelInfo*)m->info;
2014-01-20 16:36:25 +01:00
if(!mi || mi->Vertices->GetBufferPointer() == NULL)
{
delete m;
2014-02-14 14:27:38 +01:00
Core::loader.ReleaseResource(mi);
delete mi;
return NULL;
}
2013-11-26 15:33:05 +01:00
return m;
}
void API::DeleteModel(Model::Model* model)
{
if(model==NULL)
return;
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);
}
void API::Clean()
{
2014-02-11 13:29:19 +01:00
DeleteTexture(Render::Resources::Gui::Text::Font);
SAFE_DELETE(Core::viewPort);
2014-01-31 16:29:50 +01:00
Core::loader.Clean();
Oyster::Graphics::Core::PipelineManager::Clean();
2014-02-07 15:52:07 +01:00
Oyster::Graphics::Render::Resources::Clean();
SAFE_RELEASE(Core::depthStencil);
SAFE_RELEASE(Core::depthStencilUAV);
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
}
void API::AddLight(Definitions::Pointlight light)
{
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);
}
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;
return (float)m->Animation.AnimationPlaying->duration;
2014-02-10 13:59:45 +01:00
}
void API::Update(float dt)
{
deltaTime = dt;
}
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
}
}