Functioning basic renderer for models
This commit is contained in:
+1
-1
Submodule assets updated: 6b30aa83cf...1edc2d9b73
@@ -6,6 +6,7 @@
|
||||
#include "../Core/Util/Rectangle.h"
|
||||
#include "Camera.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Model.h"
|
||||
|
||||
class IRenderer
|
||||
{
|
||||
|
||||
@@ -13,6 +13,8 @@ class Skeleton;
|
||||
class Texture;
|
||||
class RenderQueue;
|
||||
|
||||
//TODO: Render: Remove obsolete RenderJobs and fix standard values on variables.
|
||||
|
||||
struct RenderJob
|
||||
{
|
||||
friend class RenderQueue;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "ShaderProgram.h"
|
||||
//TODO: Temp resourceManager
|
||||
#include "../Core/ResourceManager.h"
|
||||
|
||||
class Renderer : public IRenderer
|
||||
{
|
||||
@@ -13,10 +15,18 @@ public:
|
||||
virtual void Draw(RenderQueueCollection& rq) override;
|
||||
|
||||
private:
|
||||
//----------------------Variables----------------------//
|
||||
RenderQueueCollection m_TempRQ;
|
||||
Texture* m_ErrorTexture;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
void InitializeShaders();
|
||||
//TODO: Render: Remove ModelsToDraw from Renderer.
|
||||
void ModelsToDraw();
|
||||
void EnqueueModel(Model* model);
|
||||
|
||||
|
||||
//--------------------ShaderPrograms-------------------//
|
||||
ShaderProgram m_BasicForwardProgram;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../Core/Util/Logging.h"
|
||||
// OpenGL
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#include "Util/GLError.h"
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../OpenGL.h"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Shader
|
||||
{
|
||||
|
||||
@@ -6,14 +6,15 @@ void Renderer::Initialize()
|
||||
|
||||
// Create default camera
|
||||
m_DefaultCamera = new ::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera;
|
||||
}
|
||||
|
||||
glfwSwapInterval(m_VSYNC);
|
||||
|
||||
m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
InitializeShaders();
|
||||
ModelsToDraw();
|
||||
}
|
||||
|
||||
void Renderer::InitializeWindow()
|
||||
@@ -64,10 +65,81 @@ void Renderer::InitializeShaders()
|
||||
m_BasicForwardProgram.Link();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Renderer::ModelsToDraw()
|
||||
{
|
||||
Model *m = ResourceManager::Load<Model>("Models/translation_widget.obj");
|
||||
EnqueueModel(m);
|
||||
}
|
||||
|
||||
void Renderer::EnqueueModel(Model* model)
|
||||
{
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{
|
||||
ModelJob job;
|
||||
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
|
||||
job.DiffuseTexture = texGroup.Texture.get();
|
||||
job.NormalTexture = texGroup.NormalMap.get();
|
||||
job.SpecularTexture = texGroup.SpecularMap.get();
|
||||
job.Model = model;
|
||||
job.StartIndex = texGroup.StartIndex;
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.ModelMatrix = model->m_Matrix;
|
||||
//job.ModelMatrix = modelMatrix * model->m_Matrix; TODO: Render: Make sure modelMatrix work
|
||||
//job.Color = modelComponent->Color; TODO: Render: Take color from kd in .mtl or a value from modelcomponent.
|
||||
job.Color = glm::vec4(1.f);
|
||||
|
||||
//TODO: Render: Skeleton animations
|
||||
//if (model->m_Skeleton != nullptr && animationComponent != nullptr) {
|
||||
// job.Skeleton = model->m_Skeleton;
|
||||
// job.AnimationName = animationComponent->Name;
|
||||
// job.AnimationTime = animationComponent->Time;
|
||||
// job.NoRootMotion = animationComponent->NoRootMotion;
|
||||
//}
|
||||
|
||||
m_TempRQ.Forward.Add(job);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
//TODO: Render: Clean up draw code
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
for (auto &job : m_TempRQ.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
GLuint ShaderHandle = m_BasicForwardProgram.GetHandle();
|
||||
|
||||
m_BasicForwardProgram.Bind();
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(1)));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||
|
||||
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
|
||||
}
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
Game::Game(int argc, char* argv[])
|
||||
{
|
||||
ResourceManager::RegisterType<ConfigFile>("ConfigFile");
|
||||
ResourceManager::RegisterType<Model>("Model");
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
|
||||
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
LOG_LEVEL = static_cast<_LOG_LEVEL>(m_Config->Get<int>("Debug.LogLevel", 1));
|
||||
@@ -49,6 +51,7 @@ void Game::Tick()
|
||||
m_InputManager->Update(dt);
|
||||
m_EventBroker->Swap();
|
||||
|
||||
//TODO: Render: This is not used, but will be used later when we dont add models to RQ in renderer.
|
||||
RenderQueueCollection rq;
|
||||
m_Renderer->Draw(rq);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user