Danbias/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp

177 lines
4.1 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;
}
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-07 15:52:07 +01:00
Render::Resources::Init();
2013-11-26 15:33:05 +01:00
Render::Preparations::Basic::SetViewPort();
2014-02-07 15:52:07 +01:00
Render::DefaultRenderer::cube = API::CreateModel(L"box.dan");
Render::DefaultRenderer::cube2 = API::CreateModel(L"box2.dan");
2013-11-26 13:44:58 +01:00
return API::Sucsess;
}
void API::SetProjection(Math::Float4x4& projection)
{
Projection = projection;
}
void API::SetView(Math::Float4x4& view)
{
View = view;
}
void API::NewFrame()
2013-11-26 13:44:58 +01:00
{
if(Lights.size())
{
2014-02-07 15:52:07 +01:00
Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size());
}
else
{
2014-02-07 15:52:07 +01:00
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-07 15:52:07 +01:00
Render::DefaultRenderer::RenderScene(models,count, View, Projection);
2013-11-26 13:44:58 +01:00
}
void API::RenderModel(Model::Model& m)
{
2014-02-07 15:52:07 +01:00
Render::DefaultRenderer::RenderScene(&m,1, View, Projection);
}
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-01-27 14:24:13 +01:00
m->AnimationPlaying = -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;
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-07 15:52:07 +01:00
DeleteModel(Render::DefaultRenderer::cube);
DeleteModel(Render::DefaultRenderer::cube2);
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()
{
Render::Rendering::Gui::BeginRender();
}
void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size)
{
2014-02-07 13:47:09 +01:00
Render::Rendering::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size);
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);
}
2013-11-26 13:44:58 +01:00
}
}