Moved rendering code outside of the sandbox update function, renderer instance is now rendering the cube ( although colour is still missing but should be something simple)
This commit is contained in:
parent
b03b82272f
commit
cbbdafcb3e
@ -16,6 +16,8 @@
|
||||
#include "Scene.h"
|
||||
#include "PerfCounter.h"
|
||||
|
||||
|
||||
extern BarinkEngine::Renderer renderer;
|
||||
extern void Start();
|
||||
extern void Update();
|
||||
extern void ImmediateGraphicsDraw();
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "Buffer.h"
|
||||
#include "Mesh.h"
|
||||
#include "Material.h"
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace BarinkEngine {
|
||||
|
||||
@ -18,6 +19,7 @@ namespace BarinkEngine {
|
||||
GpuBuffer elementBuffer;
|
||||
VertexArray vertexarray;
|
||||
|
||||
|
||||
const Mesh* mesh;
|
||||
const Material* material;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "BarinkEngine.h"
|
||||
|
||||
EngineStatistics* ES;
|
||||
|
||||
BarinkEngine::Renderer renderer;
|
||||
int main(int argc, char* argv[]) {
|
||||
// Setup performance sampler
|
||||
PerfomanceSamplerInit();
|
||||
@ -10,7 +10,7 @@ int main(int argc, char* argv[]) {
|
||||
// Startup services
|
||||
BarinkWindow MainWindow = BarinkWindow(800, 600);
|
||||
|
||||
BarinkEngine::Renderer renderer = BarinkEngine::Renderer();
|
||||
renderer = BarinkEngine::Renderer();
|
||||
InputSystem = BarinkEngine::InputManager();
|
||||
|
||||
InputSystem.attach(&MainWindow);
|
||||
@ -44,9 +44,9 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
GUISystem.Render();
|
||||
|
||||
|
||||
|
||||
MainWindow.SwapBuffers();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,15 +19,14 @@ void BarinkEngine::GPU_Bucket::Upload(const Mesh& renderable) {
|
||||
vertexBuffer.Bind(false);
|
||||
vertexBuffer.setBufferData((void*)&renderable.vertices[0], renderable.vertices.size() * sizeof(BarinkEngine::Vertex), false);
|
||||
|
||||
if (renderable.elements.empty() == false) {
|
||||
elementBuffer.createBuffer();
|
||||
elementBuffer.Bind(true);
|
||||
elementBuffer.setBufferData((void*)&renderable.elements[0], renderable.elements.size() * sizeof(unsigned int), true);
|
||||
}
|
||||
|
||||
vertexarray.AttachAttribute(0, 3, sizeof(Vertex));
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)offsetof(BarinkEngine::Vertex, vertices));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
vertexBuffer.Unbind(false);
|
||||
|
@ -14,10 +14,9 @@ BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string
|
||||
|
||||
std::cout << "[DEBUG]: Loaded "<< meshes.size() << " meshes!" << std::endl;
|
||||
|
||||
|
||||
// create a renderable (per mesh ?? )
|
||||
root->renderable = new Renderable();
|
||||
root->renderable->mesh = &(meshes[0]);
|
||||
root->renderable->mesh = new Mesh(meshes[0]);
|
||||
|
||||
return root;
|
||||
|
||||
|
@ -1,12 +1,8 @@
|
||||
#include "Graphics/Renderer.h"
|
||||
|
||||
|
||||
BarinkEngine::Renderer::Renderer()
|
||||
{
|
||||
models = std::vector<GPU_Bucket*>();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
}
|
||||
|
||||
BarinkEngine::Renderer::~Renderer()
|
||||
@ -25,7 +21,7 @@ BarinkEngine::Renderer::~Renderer()
|
||||
void BarinkEngine::Renderer::Render()
|
||||
{
|
||||
// This creation of the projection and camera is somewhat wastefull
|
||||
Camera cam = Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||
Camera cam = Camera(glm::vec3(8.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||
|
||||
|
||||
@ -40,7 +36,14 @@ void BarinkEngine::Renderer::Render()
|
||||
std::cout << "No material attached!" << std::endl;
|
||||
}
|
||||
else {
|
||||
model->material->shader.Use();
|
||||
model->material->Apply();
|
||||
|
||||
model->material->shader.setUniformVec3("Color", model->material->Color);
|
||||
model->material->shader.setUniformMat4("M", glm::mat4());
|
||||
model->material->shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
model->material->shader.setUniformMat4("P", projection);
|
||||
|
||||
}
|
||||
|
||||
// Update perf counters
|
||||
@ -54,9 +57,10 @@ void BarinkEngine::Renderer::Render()
|
||||
);
|
||||
model->vertexarray.Unbind();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -72,6 +76,6 @@ void BarinkEngine::Renderer::Submit(Renderable* model)
|
||||
|
||||
bucket->Upload(*model->mesh);
|
||||
|
||||
models.push_back(bucket); // Maybe push a GPU packet or something instead
|
||||
models.push_back(bucket);
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ const std::string fragmentShaderSource = "../build/SandboxApplication/Debug/test
|
||||
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
|
||||
|
||||
Scene* Level1;
|
||||
BarinkEngine::Renderer* renderer;
|
||||
BarinkEngine::SceneObject* cube;
|
||||
/*
|
||||
* Runs once at startup
|
||||
@ -51,9 +50,8 @@ void Start() {
|
||||
memset(code, '\0', 254);
|
||||
|
||||
// TODO: Move to runtime/ Engine
|
||||
renderer = new BarinkEngine::Renderer();
|
||||
// NOTE: Submits should later be done through walking the sceneTree
|
||||
renderer->Submit(cube->renderable);
|
||||
renderer.Submit(cube->renderable);
|
||||
|
||||
|
||||
}
|
||||
@ -67,16 +65,16 @@ void ImmediateGraphicsDraw() {
|
||||
|
||||
// Show ImGui demo such that I can easily look
|
||||
// at possible GUI elements to use
|
||||
ImGui::ShowDemoWindow();
|
||||
// ImGui::ShowDemoWindow();
|
||||
|
||||
// Show internal BarinkEngine stats
|
||||
ShowStats();
|
||||
|
||||
// Show different tooling for this specific sandbox
|
||||
// CameraTool(cam);
|
||||
ScriptingTool(code);
|
||||
//ScriptingTool(code);
|
||||
|
||||
SceneExplorer(*Level1, "Scene Explorer");
|
||||
//SceneExplorer(*Level1, "Scene Explorer");
|
||||
|
||||
}
|
||||
|
||||
@ -87,8 +85,6 @@ void ImmediateGraphicsDraw() {
|
||||
void Update()
|
||||
{
|
||||
|
||||
renderer->Render();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -97,6 +93,5 @@ void Update()
|
||||
*/
|
||||
void Stop() {
|
||||
delete MI;
|
||||
delete renderer;
|
||||
delete shader;
|
||||
}
|
Loading…
Reference in New Issue
Block a user