Successful DirectX context through GLFW, praise Gaben!

This commit is contained in:
2015-10-12 14:31:48 +02:00
parent 16ecdb76d3
commit a782e6b40a
16 changed files with 564 additions and 6 deletions
+34
View File
@@ -0,0 +1,34 @@
#ifndef DD_STATICSYSTEM_H__
#define DD_STATICSYSTEM_H__
#include <unordered_map>
namespace dd
{
class StaticSystem
{
private:
StaticSystem();
public:
template <typename T>
static T* Get()
{
return static_cast<T*>(Instances.at(typeid(T).hash_code()));
}
template <typename T>
static void Set(T* ptr)
{
Instances[typeid(T).hash_code()] = static_cast<void*>(ptr);
}
private:
static std::unordered_map<size_t, void*> Instances;
};
}
#endif
+2 -2
View File
@@ -29,7 +29,7 @@ public:
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
job.Viewport = Rectangle(Left(), Top(), Width, Height);
job.TextureID = m_FadeTexture->ResourceID;
job.DiffuseTexture = *m_FadeTexture;
job.DiffuseTexture = m_FadeTexture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
job.Name = Name();
rq.GUI.Add(job);
@@ -41,7 +41,7 @@ public:
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
job.Viewport = Rectangle(Left(), Top(), Width, Height);
job.TextureID = m_Texture->ResourceID;
job.DiffuseTexture = *m_Texture;
job.DiffuseTexture = m_Texture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
job.Name = Name();
rq.GUI.Add(job);
+4
View File
@@ -27,7 +27,11 @@
// OpenGL
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#define NOMINMAX
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>
#include <glext.h>
#include "Core/Util/GLError.h"
@@ -0,0 +1,30 @@
#ifndef Model_h__
#define Model_h__
#include <string>
#include <d3d11.h>
#include "Rendering/RawModel.h"
#include "Rendering/Renderer.h"
#include "Core/StaticSystem.h"
namespace dd
{
class Model : public RawModel
{
friend class ResourceManager;
private:
Model(std::string fileName);
public:
~Model();
ID3D11Buffer* VertexBuffer;
unsigned int NumVertices;
};
}
#endif // Model_h__
@@ -0,0 +1,71 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DD_RENDERER_H__
#define DD_RENDERER_H__
#include <d3d11.h>
#pragma comment (lib, "d3d11.lib")
#include <DirectXTK/SimpleMath.h>
using namespace DirectX::SimpleMath;
//#pragma comment (lib, "DirectXTK.lib")
#include "Rendering/BaseRenderer.h"
#include "Core/StaticSystem.h"
namespace dd
{
class Model;
class ShaderProgram;
class Renderer : public BaseRenderer
{
public:
~Renderer();
void Initialize() override;
void Draw(RenderQueueCollection& rq) override;
IDXGISwapChain* m_SwapChain = nullptr;
ID3D11Device* m_Device = nullptr;
ID3D11DeviceContext* m_DeviceContext = nullptr;
ID3D11RenderTargetView* m_BackBuffer = nullptr;
ID3D11DepthStencilView* m_DepthBuffer = nullptr;
private:
struct ConstantBufferStruct
{
Matrix MVP;
Matrix ModelMatrix;
Matrix ViewMatrix;
Matrix ProjectionMatrix;
Matrix InverseTransposeViewModel;
Vector3 LightPosition;
} constantBufferStruct;
ShaderProgram* shaderProgram = nullptr;
const Model* testModel = nullptr;
ID3D11Buffer* constantBuffer = nullptr;
DirectX::SimpleMath::Matrix GLMtoDX(glm::mat4 m);
};
}
#endif // Renderer_h__
@@ -0,0 +1,41 @@
#ifndef ShaderProgram_h__
#define ShaderProgram_h__
#include <string>
#include <d3d11.h>
#include <d3dcompiler.h>
#pragma comment (lib, "D3DCompiler.lib")
#include "Core/StaticSystem.h"
#include "Rendering/Renderer.h"
namespace dd
{
class ShaderProgram
{
public:
ShaderProgram();
~ShaderProgram();
void CompileVertexShader(std::wstring filename);
void CompilePixelShader(std::wstring filename);
HRESULT CreateInputLayout(D3D11_INPUT_ELEMENT_DESC* ied, UINT numElements);
ID3D11InputLayout* GetInputLayout() const { return m_InputLayout; }
void Bind();
void Unbind();
private:
ID3D10Blob* m_VertexShaderBlob;
ID3D11VertexShader* m_VertexShader;
ID3D10Blob* m_PixelShaderBlob;
ID3D11PixelShader* m_PixelShader;
ID3D11InputLayout* m_InputLayout;
};
}
#endif // ShaderProgram_h__
@@ -0,0 +1,49 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Texture_h__
#define Texture_h__
#include <string>
#include <unordered_map>
#include <cstdio>
#include "Core/ResourceManager.h"
#include "Rendering/PNG.h"
namespace dd
{
class Texture : public Resource
{
friend class ResourceManager;
private:
Texture(std::string path);
public:
~Texture();
unsigned int Width = 0;
unsigned int Height = 0;
};
}
#endif // Texture_h__
+1 -1
View File
@@ -96,4 +96,4 @@ private:
}
#endif // Model_h__
#endif
+2
View File
@@ -29,6 +29,8 @@
namespace dd
{
class Model;
class Texture;
class RenderQueue;
struct RenderJob