Sped up application load time by Enginestatistics allocation from heap to stack, Colour and rotation render test
This commit is contained in:
parent
cbbdafcb3e
commit
463a9ff307
@ -3,36 +3,36 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
struct EngineStatistics {
|
struct EngineStatistics {
|
||||||
long long lastSampleTime;
|
|
||||||
float frameTime;
|
float frameTime;
|
||||||
uint32_t verts;
|
uint32_t verts;
|
||||||
uint32_t DC;
|
uint32_t DC;
|
||||||
|
|
||||||
|
long long lastSampleTime;
|
||||||
long long frames;
|
long long frames;
|
||||||
long long FPS;
|
long long FPS;
|
||||||
};
|
};
|
||||||
extern EngineStatistics* ES;
|
extern EngineStatistics ES;
|
||||||
|
|
||||||
inline void PerfomanceSamplerInit(){
|
inline void PerfomanceSamplerInit(){
|
||||||
ES = new EngineStatistics();
|
|
||||||
ES->frames = 0;
|
ES.frames = 0;
|
||||||
ES->lastSampleTime = 0;
|
ES.lastSampleTime = 0;
|
||||||
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
ES.lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SamplePerformance(void) {
|
inline void SamplePerformance(void) {
|
||||||
ES->frames++;
|
ES.frames++;
|
||||||
ES->DC = 0;
|
ES.DC = 0;
|
||||||
ES->verts = 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 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) {
|
if (MilliSecondsPast >= 1000) {
|
||||||
|
|
||||||
ES->frameTime = (float)1000 / ES->frames;
|
ES.frameTime = (float)1000 / ES.frames;
|
||||||
ES->FPS = ES->frames;
|
ES.FPS = ES.frames;
|
||||||
ES->frames = 0;
|
ES.frames = 0;
|
||||||
ES->lastSampleTime = now;
|
ES.lastSampleTime = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +41,12 @@ inline void SamplePerformance(void) {
|
|||||||
inline void ShowStats() {
|
inline void ShowStats() {
|
||||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||||
|
|
||||||
ImGui::Text("FPS: %i", ES->FPS);
|
ImGui::Text("FPS: %i", ES.FPS);
|
||||||
ImGui::Text("Frame Time: %f", ES->frameTime);
|
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||||||
ImGui::Text("Verts: %i", ES->verts);
|
ImGui::Text("Verts: %i", ES.verts);
|
||||||
ImGui::Text("Draw Calls: %i", ES->DC);
|
ImGui::Text("Draw Calls: %i", ES.DC);
|
||||||
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include "BarinkEngine.h"
|
#include "BarinkEngine.h"
|
||||||
|
|
||||||
EngineStatistics* ES;
|
EngineStatistics ES;
|
||||||
BarinkEngine::Renderer renderer;
|
BarinkEngine::Renderer renderer;
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// Setup performance sampler
|
// Setup performance sampler
|
||||||
@ -12,6 +12,8 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
renderer = BarinkEngine::Renderer();
|
renderer = BarinkEngine::Renderer();
|
||||||
InputSystem = BarinkEngine::InputManager();
|
InputSystem = BarinkEngine::InputManager();
|
||||||
|
ES = EngineStatistics();
|
||||||
|
|
||||||
|
|
||||||
InputSystem.attach(&MainWindow);
|
InputSystem.attach(&MainWindow);
|
||||||
|
|
||||||
@ -55,7 +57,6 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
|
|
||||||
// Shutdown Services
|
// Shutdown Services
|
||||||
delete ES;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,14 @@ BarinkEngine::Renderer::~Renderer()
|
|||||||
// glDeleteBuffers(1, &UV_id);
|
// glDeleteBuffers(1, &UV_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Angle = 0.0;
|
||||||
|
|
||||||
void BarinkEngine::Renderer::Render()
|
void BarinkEngine::Renderer::Render()
|
||||||
{
|
{
|
||||||
// This creation of the projection and camera is somewhat wastefull
|
// 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);
|
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
||||||
|
Angle += 0.0001f;
|
||||||
|
|
||||||
for (auto model : models) {
|
for (auto model : models) {
|
||||||
// Push matrices etc ....
|
// Push matrices etc ....
|
||||||
@ -40,15 +42,17 @@ void BarinkEngine::Renderer::Render()
|
|||||||
model->material->Apply();
|
model->material->Apply();
|
||||||
|
|
||||||
model->material->shader.setUniformVec3("Color", model->material->Color);
|
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("V", cam.GetViewMatrix());
|
||||||
model->material->shader.setUniformMat4("P", projection);
|
model->material->shader.setUniformMat4("P", projection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update perf counters
|
// Update perf counters
|
||||||
ES->verts = model->mesh->vertices.size();
|
ES.verts = model->mesh->vertices.size();
|
||||||
ES->DC++;
|
ES.DC++;
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES,
|
glDrawElements(GL_TRIANGLES,
|
||||||
static_cast<unsigned int>(model->mesh->elements.size()),
|
static_cast<unsigned int>(model->mesh->elements.size()),
|
||||||
|
@ -7,5 +7,5 @@ uniform sampler2D Texture;
|
|||||||
|
|
||||||
|
|
||||||
void main(){
|
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);
|
||||||
}
|
}
|
@ -38,8 +38,9 @@ void Start() {
|
|||||||
|
|
||||||
// Create a cube node
|
// 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 = new Material(*shader);
|
||||||
|
cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
// What is in cube now ??
|
// What is in cube now ??
|
||||||
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
|
std::cout << "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user