Danbias/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp

145 lines
3.3 KiB
C++
Raw Normal View History

2013-11-26 13:44:58 +01:00
#include "GFXAPI.h"
#include "../Core/Core.h"
#include "../Render/Resources/Debug.h"
#include "../Render/Resources/Deffered.h"
2013-11-26 13:44:58 +01:00
#include "../Render/Rendering/Render.h"
2013-11-26 15:33:05 +01:00
#include "../FileLoader/ObjReader.h"
2014-01-31 16:29:50 +01:00
//#include "../../Misc/Resource/OysterResource.h"
#include "../../Misc/Resource/ResourceManager.h"
#include "../FileLoader/GeneralLoader.h"
#include "../Model/ModelInfo.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;
}
Render::Resources::Deffered::Init();
2013-11-26 15:33:05 +01:00
Render::Preparations::Basic::SetViewPort();
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())
{
Render::Rendering::Basic::NewFrame(View, Projection, &Lights[0], (int)Lights.size());
}
else
{
Render::Rendering::Basic::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-01-08 07:01:59 +01:00
Render::Rendering::Basic::RenderScene(models,count, View, Projection);
2013-11-26 13:44:58 +01:00
}
void API::RenderModel(Model::Model& m)
{
2014-01-08 07:01:59 +01:00
Render::Rendering::Basic::RenderScene(&m,1, View, Projection);
}
2013-11-26 15:33:05 +01:00
void API::EndFrame()
{
Render::Rendering::Basic::EndFrame();
}
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()
{
SAFE_DELETE(Core::viewPort);
2014-01-31 16:29:50 +01:00
Core::loader.Clean();
Oyster::Graphics::Core::PipelineManager::Clean();
Oyster::Graphics::Render::Resources::Deffered::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()
{
Render::Resources::Deffered::InitShaders();
return State::Sucsess;
}
#endif
2013-11-26 13:44:58 +01:00
}
}