Added instanced drawing to the GBuffer
This commit is contained in:
parent
ba19742bfe
commit
f422d1d138
@ -129,6 +129,7 @@
|
|||||||
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
|
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
|
||||||
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
|
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
|
||||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<Profile>true</Profile>
|
||||||
</Link>
|
</Link>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||||
@ -173,6 +174,7 @@
|
|||||||
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
|
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
|
||||||
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
|
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
|
||||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<Profile>true</Profile>
|
||||||
</Link>
|
</Link>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
<Command>cd "$(SolutionDir)NFPackCreator\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && move "$(SolutionDir)NFPackCreator\AssetBuild\*.nfpack" "$(OutDir)assets\"</Command>
|
||||||
|
@ -24,7 +24,7 @@ void MainState::onEnter() {
|
|||||||
for (int x = 0; x < 10; x++) {
|
for (int x = 0; x < 10; x++) {
|
||||||
for (int y = 0; y < 10; y++) {
|
for (int y = 0; y < 10; y++) {
|
||||||
entities.push_back(new nf::Entity);
|
entities.push_back(new nf::Entity);
|
||||||
entities.back()->create(ap["spec.obj"]);
|
entities.back()->create(ap["2mats.obj"]);
|
||||||
entities.back()->setPosition(5.0 + x * 2.1, 0.05, -5.0 + y * 2.1);
|
entities.back()->setPosition(5.0 + x * 2.1, 0.05, -5.0 + y * 2.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ void main() {
|
|||||||
normals = hasNormTex[matNum] ? normalize(tbn * (texture(normalTexture[matNum], texCoord).xyz * 2.0 - 1.0)) : normal;
|
normals = hasNormTex[matNum] ? normalize(tbn * (texture(normalTexture[matNum], texCoord).xyz * 2.0 - 1.0)) : normal;
|
||||||
diffuse = hasDiffuseTex[matNum] ? texture(diffuseTexture[matNum], texCoord).rgb : diffuseColor[matNum];
|
diffuse = hasDiffuseTex[matNum] ? texture(diffuseTexture[matNum], texCoord).rgb : diffuseColor[matNum];
|
||||||
specular.r = specPower[matNum];
|
specular.r = specPower[matNum];
|
||||||
specular.g = hasSpecTex[matNum] ? texture(specularTexture[matNum], texCoord).r : 1.0;
|
specular.g = hasSpecTex[matNum] ? texture(specularTexture[matNum], texCoord).r : 0.2;
|
||||||
specular.b = 1.0;
|
specular.b = 1.0;
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ layout(location = 2) in vec3 normals;
|
|||||||
layout(location = 3) in vec3 tangent;
|
layout(location = 3) in vec3 tangent;
|
||||||
layout(location = 4) in int matN;
|
layout(location = 4) in int matN;
|
||||||
|
|
||||||
uniform mat4 model;
|
uniform mat4 model[60];
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
uniform mat4 proj;
|
uniform mat4 proj;
|
||||||
|
|
||||||
@ -17,10 +17,10 @@ out mat3 tbn;
|
|||||||
flat out int matNum;
|
flat out int matNum;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 world = model * vec4(pos, 1.0);
|
vec4 world = model[gl_InstanceID] * vec4(pos, 1.0);
|
||||||
fragPos = world.xyz;
|
fragPos = world.xyz;
|
||||||
texCoord = texCoords;
|
texCoord = texCoords;
|
||||||
mat3 normalMat = transpose(inverse(mat3(model)));
|
mat3 normalMat = transpose(inverse(mat3(model[gl_InstanceID])));
|
||||||
vec3 t = normalize(normalMat * tangent);
|
vec3 t = normalize(normalMat * tangent);
|
||||||
vec3 n = normalize(normalMat * normals);
|
vec3 n = normalize(normalMat * normals);
|
||||||
normal = n;
|
normal = n;
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
layout(location = 0) in vec3 pos;
|
layout(location = 0) in vec3 pos;
|
||||||
|
|
||||||
uniform mat4 lightSpace;
|
uniform mat4 lightSpace;
|
||||||
uniform mat4 model;
|
uniform mat4 model[60];
|
||||||
|
|
||||||
out vec3 texCoord;
|
out vec3 texCoord;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = lightSpace * model * vec4(pos, 1.0);
|
gl_Position = lightSpace * model[gl_InstanceID] * vec4(pos, 1.0);
|
||||||
}
|
}
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
layout(location = 0) in vec3 pos;
|
layout(location = 0) in vec3 pos;
|
||||||
|
|
||||||
uniform mat4 model;
|
uniform mat4 model[60];
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = model * vec4(pos, 1.0);
|
gl_Position = model[gl_InstanceID] * vec4(pos, 1.0);
|
||||||
}
|
}
|
@ -94,7 +94,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>GLEW_STATIC;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NFENGINE; GLEW_STATIC;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
||||||
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
||||||
@ -120,7 +120,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>GLEW_STATIC;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NFENGINE; GLEW_STATIC;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
||||||
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
||||||
@ -146,7 +146,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>GLEW_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NFENGINE; GLEW_STATIC;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
||||||
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
||||||
@ -172,7 +172,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>GLEW_STATIC;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NFENGINE; GLEW_STATIC;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
||||||
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
||||||
|
@ -71,22 +71,23 @@ namespace nf {
|
|||||||
|
|
||||||
void Entity::render(Shader* shader, bool onlyDepth) {
|
void Entity::render(Shader* shader, bool onlyDepth) {
|
||||||
shader->bind();
|
shader->bind();
|
||||||
setModelMatrix(shader);
|
glm::mat4 model = getModelMatrix();
|
||||||
m_model->render(shader, onlyDepth);
|
shader->setUniform("model[0]", model);
|
||||||
|
m_model->render(shader, onlyDepth, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Model* Entity::getModel() const {
|
Model* Entity::getModel() const {
|
||||||
return m_model;
|
return m_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::setModelMatrix(Shader* shader) {
|
const glm::mat4 Entity::getModelMatrix() {
|
||||||
glm::mat4 model(1.0f);
|
glm::mat4 model(1.0f);
|
||||||
model = glm::translate(model, glm::vec3(m_position.x, m_position.y, m_position.z));
|
model = glm::translate(model, glm::vec3(m_position.x, m_position.y, m_position.z));
|
||||||
model = glm::rotate(model, glm::radians((float)m_rotation.x), glm::vec3(1.0, 0.0, 0.0));
|
model = glm::rotate(model, glm::radians((float)m_rotation.x), glm::vec3(1.0, 0.0, 0.0));
|
||||||
model = glm::rotate(model, glm::radians((float)m_rotation.y), glm::vec3(0.0, 1.0, 0.0));
|
model = glm::rotate(model, glm::radians((float)m_rotation.y), glm::vec3(0.0, 1.0, 0.0));
|
||||||
model = glm::rotate(model, glm::radians((float)m_rotation.z), glm::vec3(0.0, 0.0, 1.0));
|
model = glm::rotate(model, glm::radians((float)m_rotation.z), glm::vec3(0.0, 0.0, 1.0));
|
||||||
model = glm::scale(model, glm::vec3(m_scale.x, m_scale.y, m_scale.z));
|
model = glm::scale(model, glm::vec3(m_scale.x, m_scale.y, m_scale.z));
|
||||||
shader->setUniform("model", model);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::destroy() {
|
void Entity::destroy() {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
#include "Model.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
@ -44,8 +45,29 @@ namespace nf {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
for (Entity* curr : entites)
|
for (Entity* curr : entites) {
|
||||||
curr->render(shader);
|
m_modelsToDraw[curr->getModel()].push_back(curr->getModelMatrix());
|
||||||
|
}
|
||||||
|
for (auto& curr : m_modelsToDraw) {
|
||||||
|
std::vector<glm::mat4>& mats = curr.second;
|
||||||
|
std::string pos;
|
||||||
|
unsigned int modelsRemaining = mats.size();
|
||||||
|
while (modelsRemaining != 0) {
|
||||||
|
unsigned int modelCount;
|
||||||
|
if (modelsRemaining > 60)
|
||||||
|
modelCount = 60;
|
||||||
|
else
|
||||||
|
modelCount = modelsRemaining;
|
||||||
|
modelsRemaining -= modelCount;
|
||||||
|
for (unsigned int i = 0; i < modelCount; i++) {
|
||||||
|
pos = std::to_string(i) + "]";
|
||||||
|
shader->setUniform(m_modelString + pos, mats[i]);
|
||||||
|
}
|
||||||
|
curr.first->render(shader, false, modelCount);
|
||||||
|
mats.erase(mats.begin(), mats.begin() + modelCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_modelsToDraw.clear();
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
//TODO: Blit depth buffer for transparent objects later
|
//TODO: Blit depth buffer for transparent objects later
|
||||||
|
@ -310,12 +310,12 @@ namespace nf {
|
|||||||
m_ib = new IndexBuffer(&vboIndices[0], vboIndices.size());
|
m_ib = new IndexBuffer(&vboIndices[0], vboIndices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::render(Shader* shader, bool onlyDepth) {
|
void Model::render(Shader* shader, bool onlyDepth, unsigned int count) {
|
||||||
m_vao->bind();
|
m_vao->bind();
|
||||||
m_ib->bind();
|
m_ib->bind();
|
||||||
if (!onlyDepth)
|
if (!onlyDepth)
|
||||||
bindMaterials(shader);
|
bindMaterials(shader);
|
||||||
glDrawElements(GL_TRIANGLES, m_ib->getCount(), GL_UNSIGNED_INT, nullptr);
|
glDrawElementsInstanced(GL_TRIANGLES, m_ib->getCount(), GL_UNSIGNED_INT, nullptr, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::bindMaterials(Shader* shader) {
|
void Model::bindMaterials(Shader* shader) {
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#include "Assets.h"
|
#include "Assets.h"
|
||||||
#include "NFObject.h"
|
#include "NFObject.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
|
#ifdef NFENGINE
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
class Shader;
|
class Shader;
|
||||||
@ -22,13 +25,14 @@ namespace nf {
|
|||||||
void setScale(double x, double y, double z);
|
void setScale(double x, double y, double z);
|
||||||
void setScale(const Vec3& scale);
|
void setScale(const Vec3& scale);
|
||||||
|
|
||||||
void render(Shader* shader, bool onlyDepth = false);
|
void render(Shader* shader, bool onlyDepth);
|
||||||
Model* getModel() const;
|
Model* getModel() const;
|
||||||
|
#ifdef NFENGINE
|
||||||
|
const glm::mat4 getModelMatrix();
|
||||||
|
#endif
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
~Entity();
|
~Entity();
|
||||||
private:
|
private:
|
||||||
void setModelMatrix(Shader* shader);
|
|
||||||
|
|
||||||
bool m_constructed;
|
bool m_constructed;
|
||||||
Model* m_model;
|
Model* m_model;
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "glm\glm.hpp"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
class Entity;
|
class Entity;
|
||||||
|
class Model;
|
||||||
class Shader;
|
class Shader;
|
||||||
|
|
||||||
class GBuffer {
|
class GBuffer {
|
||||||
@ -19,7 +22,9 @@ namespace nf {
|
|||||||
unsigned int m_FBO;
|
unsigned int m_FBO;
|
||||||
std::array<unsigned int, 4> m_textures;
|
std::array<unsigned int, 4> m_textures;
|
||||||
unsigned int m_depth;
|
unsigned int m_depth;
|
||||||
|
|
||||||
unsigned int m_width, m_height;
|
unsigned int m_width, m_height;
|
||||||
|
|
||||||
|
std::unordered_map<Model*, std::vector<glm::mat4>> m_modelsToDraw;
|
||||||
|
const std::string m_modelString = "model[";
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ namespace nf {
|
|||||||
public:
|
public:
|
||||||
Model(AModel* model);
|
Model(AModel* model);
|
||||||
|
|
||||||
void render(Shader* shader, bool onlyDepth);
|
void render(Shader* shader, bool onlyDepth, unsigned int count);
|
||||||
void bindMaterials(Shader* shader);
|
void bindMaterials(Shader* shader);
|
||||||
|
|
||||||
bool isBaseAsset();
|
bool isBaseAsset();
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
#include "Renderer.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
#include "IntroGamestate.h"
|
#include "IntroGamestate.h"
|
||||||
@ -18,155 +20,3 @@
|
|||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
|
|
||||||
namespace nf {
|
|
||||||
class Drawable;
|
|
||||||
class Shader;
|
|
||||||
class Model;
|
|
||||||
class GBuffer;
|
|
||||||
class AudioEngine;
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
public:
|
|
||||||
Renderer(Application* app);
|
|
||||||
|
|
||||||
void setFade(bool in, bool out, bool noText);
|
|
||||||
bool isFadeOutComplete();
|
|
||||||
|
|
||||||
void render(Entity& in);
|
|
||||||
void render(UIElement& in);
|
|
||||||
void render(Light& in);
|
|
||||||
void render(Cubemap& in);
|
|
||||||
|
|
||||||
void doFrame(Camera* camera, double dT);
|
|
||||||
|
|
||||||
~Renderer();
|
|
||||||
private:
|
|
||||||
void renderShadowMaps(unsigned int count);
|
|
||||||
|
|
||||||
void loadBaseAssets();
|
|
||||||
void createShadowMaps();
|
|
||||||
|
|
||||||
Application* m_app;
|
|
||||||
|
|
||||||
HDC m_hdc;
|
|
||||||
HGLRC m_hglrc;
|
|
||||||
|
|
||||||
AssetPack m_baseAP;
|
|
||||||
|
|
||||||
GBuffer* m_gBuffer;
|
|
||||||
|
|
||||||
unsigned int m_shadowMapFBO;
|
|
||||||
int m_directionalDepthTexSize;
|
|
||||||
int m_pointDepthTexSize;
|
|
||||||
std::vector<unsigned int> m_directionalShadowMaps;
|
|
||||||
std::vector<unsigned int> m_pointShadowMaps;
|
|
||||||
unsigned int m_texSlots;
|
|
||||||
|
|
||||||
std::vector<Light*> m_lights;
|
|
||||||
std::vector<Entity*> m_lGame;
|
|
||||||
Cubemap* m_cubemap;
|
|
||||||
std::vector<UIElement*> m_lUI;
|
|
||||||
Shader* m_gBufferShader;
|
|
||||||
Shader* m_lightingShader;
|
|
||||||
Shader* m_textShader;
|
|
||||||
Shader* m_uiTextureShader;
|
|
||||||
Shader* m_cubemapShader;
|
|
||||||
Shader* m_fadeShader;
|
|
||||||
Shader* m_directionalShadowShader;
|
|
||||||
Shader* m_pointShadowShader;
|
|
||||||
|
|
||||||
bool m_fadeIn, m_fadeOut;
|
|
||||||
bool m_fadeNoText;
|
|
||||||
bool m_fadeOutComplete;
|
|
||||||
Text m_loadingText;
|
|
||||||
|
|
||||||
VertexArray* m_quadVAO;
|
|
||||||
IndexBuffer* m_quadIB;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Application {
|
|
||||||
public:
|
|
||||||
Application(Config& conf);
|
|
||||||
Application() = delete;
|
|
||||||
Application(Application& other) = delete;
|
|
||||||
|
|
||||||
void setWindowIcon(HANDLE hIcon);
|
|
||||||
void setWindowCursor(HCURSOR hCursor);
|
|
||||||
AudioEngine* getAudioEngine() const;
|
|
||||||
void addState(Gamestate* state, const std::string& stateName);
|
|
||||||
void addDefaultState(const std::string& stateName);
|
|
||||||
const std::string& getDefaultState();
|
|
||||||
void run();
|
|
||||||
bool isCustomWindowIcon();
|
|
||||||
void changeState(const std::string& stateName);
|
|
||||||
Gamestate* getCurrentState();
|
|
||||||
void showWindow(bool show);
|
|
||||||
const HWND& getWindow();
|
|
||||||
void changeConfig(const Config& in);
|
|
||||||
const Config& getConfig() const;
|
|
||||||
int getFPS() const;
|
|
||||||
bool isKeyHeld(unsigned int code);
|
|
||||||
bool isKeyPressed(unsigned int code);
|
|
||||||
bool isMouse(unsigned int code);
|
|
||||||
void trackMouse(bool track);
|
|
||||||
void getMouseDiff(int& x, int& y);
|
|
||||||
Vec2 getMousePos();
|
|
||||||
static Application* getApp();
|
|
||||||
|
|
||||||
void quit();
|
|
||||||
~Application();
|
|
||||||
private:
|
|
||||||
void registerWindowClass();
|
|
||||||
RECT getWindowRect() const;
|
|
||||||
void calculateNewWindowPos(int& x, int& y);
|
|
||||||
void toggleFullscreen();
|
|
||||||
void updateMouse();
|
|
||||||
void runMainGameThread();
|
|
||||||
void doStateChange();
|
|
||||||
static void setApp(Application* app);
|
|
||||||
|
|
||||||
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
||||||
|
|
||||||
static Application* currentApp;
|
|
||||||
Config m_currentConfig;
|
|
||||||
bool m_running;
|
|
||||||
bool m_quit;
|
|
||||||
HINSTANCE m_hInst;
|
|
||||||
LPCWSTR m_wclassName;
|
|
||||||
HWND m_window;
|
|
||||||
bool m_customWindowIconSet;
|
|
||||||
LONG m_defaultWindowStyle;
|
|
||||||
unsigned int m_altWidth, m_altHeight;
|
|
||||||
|
|
||||||
std::chrono::duration<double> m_fpsDuration;
|
|
||||||
double m_deltaTime;
|
|
||||||
std::chrono::steady_clock::time_point m_fpsClock1 = std::chrono::steady_clock::now();
|
|
||||||
std::chrono::steady_clock::time_point m_fpsClock2 = m_fpsClock1;
|
|
||||||
const int m_targetFPS = 60;
|
|
||||||
const double m_minFrametime = 1.0 / m_targetFPS;
|
|
||||||
int m_FPS;
|
|
||||||
|
|
||||||
//Inactive states to potentially be active during the Application's lifetime
|
|
||||||
//Mapped to const char* to be referenced later in the frontend
|
|
||||||
std::unordered_map<std::string, Gamestate*> m_states;
|
|
||||||
Gamestate* m_sIntro;
|
|
||||||
std::string m_defaultState;
|
|
||||||
bool m_defaultStateAdded;
|
|
||||||
Gamestate* m_currentState;
|
|
||||||
bool m_stateChange;
|
|
||||||
std::string m_nextState;
|
|
||||||
|
|
||||||
//Array of booleans that represent keyboard and mouse input minus the scrollwheel
|
|
||||||
std::array<bool, 164> m_keysPressed;
|
|
||||||
unsigned int m_mouseX, m_mouseY;
|
|
||||||
bool m_trackingMouse;
|
|
||||||
bool m_mouseTrackFirst;
|
|
||||||
int m_mouseDiffX, m_mouseDiffY;
|
|
||||||
|
|
||||||
//Renderer object to use OpenGL to render the current state
|
|
||||||
Renderer* m_renderer;
|
|
||||||
|
|
||||||
AudioEngine* m_audio;
|
|
||||||
};
|
|
||||||
}
|
|
Reference in New Issue
Block a user