Sped up application load time by Enginestatistics allocation from heap to stack, Colour and rotation render test

This commit is contained in:
Nigel Barink 2022-10-09 21:13:24 +02:00
parent cbbdafcb3e
commit 463a9ff307
5 changed files with 35 additions and 27 deletions

View File

@ -3,36 +3,36 @@
#include <imgui.h>
struct EngineStatistics {
long long lastSampleTime;
float frameTime;
uint32_t verts;
uint32_t DC;
long long lastSampleTime;
long long frames;
long long FPS;
};
extern EngineStatistics* ES;
extern EngineStatistics ES;
inline void PerfomanceSamplerInit(){
ES = new EngineStatistics();
ES->frames = 0;
ES->lastSampleTime = 0;
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
ES.frames = 0;
ES.lastSampleTime = 0;
ES.lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
inline void SamplePerformance(void) {
ES->frames++;
ES->DC = 0;
ES->verts = 0;
ES.frames++;
ES.DC = 0;
ES.verts = 0;
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
unsigned long long MilliSecondsPast = now - ES.lastSampleTime;
if (MilliSecondsPast >= 1000) {
ES->frameTime = (float)1000 / ES->frames;
ES->FPS = ES->frames;
ES->frames = 0;
ES->lastSampleTime = now;
ES.frameTime = (float)1000 / ES.frames;
ES.FPS = ES.frames;
ES.frames = 0;
ES.lastSampleTime = now;
}
}
@ -41,10 +41,12 @@ inline void SamplePerformance(void) {
inline void ShowStats() {
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
ImGui::Text("FPS: %i", ES->FPS);
ImGui::Text("Frame Time: %f", ES->frameTime);
ImGui::Text("Verts: %i", ES->verts);
ImGui::Text("Draw Calls: %i", ES->DC);
ImGui::Text("FPS: %i", ES.FPS);
ImGui::Text("Frame Time: %f", ES.frameTime);
ImGui::Text("Verts: %i", ES.verts);
ImGui::Text("Draw Calls: %i", ES.DC);
ImGui::End();
}

View File

@ -1,6 +1,6 @@
#include "BarinkEngine.h"
EngineStatistics* ES;
EngineStatistics ES;
BarinkEngine::Renderer renderer;
int main(int argc, char* argv[]) {
// Setup performance sampler
@ -12,6 +12,8 @@ int main(int argc, char* argv[]) {
renderer = BarinkEngine::Renderer();
InputSystem = BarinkEngine::InputManager();
ES = EngineStatistics();
InputSystem.attach(&MainWindow);
@ -55,7 +57,6 @@ int main(int argc, char* argv[]) {
// Shutdown Services
delete ES;
return 0;
}

View File

@ -18,12 +18,14 @@ BarinkEngine::Renderer::~Renderer()
// glDeleteBuffers(1, &UV_id);
}
float Angle = 0.0;
void BarinkEngine::Renderer::Render()
{
// This creation of the projection and camera is somewhat wastefull
Camera cam = Camera(glm::vec3(8.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
Camera cam = Camera(glm::vec3(16.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);
Angle += 0.0001f;
for (auto model : models) {
// Push matrices etc ....
@ -40,15 +42,17 @@ void BarinkEngine::Renderer::Render()
model->material->Apply();
model->material->shader.setUniformVec3("Color", model->material->Color);
model->material->shader.setUniformMat4("M", glm::mat4());
model->material->shader.setUniformMat4("M", glm::rotate(glm::mat4(), Angle, glm::vec3(0.5f, 0.5f, 0.0f)));
model->material->shader.setUniformMat4("V", cam.GetViewMatrix());
model->material->shader.setUniformMat4("P", projection);
}
// Update perf counters
ES->verts = model->mesh->vertices.size();
ES->DC++;
ES.verts = model->mesh->vertices.size();
ES.DC++;
glDrawElements(GL_TRIANGLES,
static_cast<unsigned int>(model->mesh->elements.size()),

View File

@ -7,5 +7,5 @@ uniform sampler2D Texture;
void main(){
FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f);
FragColor = vec4(1.0f, 0.0f, 0.0f , 1.0f); // mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 1.0f);
}

View File

@ -38,8 +38,9 @@ void Start() {
// Create a cube node
cube = MI->Import("../build/SandboxApplication/Debug/Models/Cube.obj");
cube = MI->Import("../build/SandboxApplication/Debug/Models/cube.obj");
cube->renderable->material = new Material(*shader);
cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
// What is in cube now ??
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;