diff --git a/src/dawn/display/Color.hpp b/src/dawn/display/Color.hpp index d3b35051..d1beac16 100644 --- a/src/dawn/display/Color.hpp +++ b/src/dawn/display/Color.hpp @@ -1,24 +1,26 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawnlibs.hpp" - -namespace Dawn { - struct Color { - float_t r, g, b, a; - }; - - #define COLOR_WHITE { 1, 1, 1, 1 } - #define COLOR_RED { 1, 0, 0, 1 } - #define COLOR_GREEN { 0, 255, 0, 1 } - #define COLOR_BLUE { 0, 0, 255, 1 } - #define COLOR_BLACK { 0, 0, 0, 1 } - #define COLOR_MAGENTA { 1, 0, 1, 1 } - #define COLOR_CORNFLOWER_BLUE { 0.39215686274f, 0.58431372549f, 0.9294117647f, 1.0f } - #define COLOR_WHITE_TRANSPARENT { 1, 1, 1, 0 } - #define COLOR_BLACK_TRANSPARENT { 0, 0, 0, 0 } - #define COLOR_TRANSPARENT COLOR_BLACK_TRANSPARENT +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" + +namespace Dawn { + struct Color { + float_t r, g, b, a; + }; + + #define COLOR_WHITE { 1, 1, 1, 1 } + #define COLOR_RED { 1, 0, 0, 1 } + #define COLOR_GREEN { 0, 255, 0, 1 } + #define COLOR_BLUE { 0, 0, 255, 1 } + #define COLOR_BLACK { 0, 0, 0, 1 } + #define COLOR_MAGENTA { 1, 0, 1, 1 } + #define COLOR_DARK_GREY { 0.2f, 0.2f, 0.2f, 1 } + #define COLOR_LIGHT_GREY { 0.8f, 0.8f, 0.8f, 1 } + #define COLOR_CORNFLOWER_BLUE { 0.39215686274f, 0.58431372549f, 0.9294117647f, 1.0f } + #define COLOR_WHITE_TRANSPARENT { 1, 1, 1, 0 } + #define COLOR_BLACK_TRANSPARENT { 0, 0, 0, 0 } + #define COLOR_TRANSPARENT COLOR_BLACK_TRANSPARENT } \ No newline at end of file diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 49d74803..46c593ed 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -166,21 +166,24 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) { // Debug Lines #if DAWN_DEBUG_BUILD Mesh lineMesh; - int32_t lineIndex = 0; - lineMesh.createBuffers( - scene->debugLines.size() * SCENE_DEBUG_LINE_VERTICE_COUNT, - scene->debugLines.size() * SCENE_DEBUG_LINE_INDICE_COUNT - ); - auto itDebugLine = scene->debugLines.begin(); - while(itDebugLine != scene->debugLines.end()) { - auto item = itDebugLine->createShaderItem( - &lineMesh, - &lineIndex, - camera, - &this->renderManager->simpleShader + if(scene->debugLines.size() > 0) { + int32_t lineIndex = 0; + lineMesh.createBuffers( + scene->debugLines.size() * SCENE_DEBUG_LINE_VERTICE_COUNT, + scene->debugLines.size() * SCENE_DEBUG_LINE_INDICE_COUNT ); - shaderPassItems.push_back(item); - ++itDebugLine; + auto itDebugLine = scene->debugLines.begin(); + while(itDebugLine != scene->debugLines.end()) { + auto item = itDebugLine->createShaderItem( + &lineMesh, + &lineIndex, + camera, + &this->renderManager->simpleShader + ); + shaderPassItems.push_back(item); + itDebugLine = scene->debugLines.erase(itDebugLine); + lineIndex++; + } } #endif diff --git a/src/dawn/scene/Scene.cpp b/src/dawn/scene/Scene.cpp index 2f680928..a2815628 100644 --- a/src/dawn/scene/Scene.cpp +++ b/src/dawn/scene/Scene.cpp @@ -26,6 +26,11 @@ void Scene::update() { ++it; } this->itemsNotInitialized.clear(); + + #if DAWN_DEBUG_BUILD + this->debugGrid(); + this->debugOrigin(); + #endif // TODO: Cleanup old scene items diff --git a/src/dawn/scene/Scene.hpp b/src/dawn/scene/Scene.hpp index b54e9c7e..0e286fc4 100644 --- a/src/dawn/scene/Scene.hpp +++ b/src/dawn/scene/Scene.hpp @@ -136,6 +136,8 @@ namespace Dawn { std::vector debugLines; void debugLine(struct SceneDebugLine line); void debugCube(struct SceneDebugCube cube); + void debugOrigin(); + void debugGrid(); #endif /** diff --git a/src/dawn/scene/components/example/ExampleSpin.cpp b/src/dawn/scene/components/example/ExampleSpin.cpp index eeaff8a9..87454629 100644 --- a/src/dawn/scene/components/example/ExampleSpin.cpp +++ b/src/dawn/scene/components/example/ExampleSpin.cpp @@ -29,13 +29,11 @@ ExampleSpin::ExampleSpin(SceneItem *item) : getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate); } - void ExampleSpin::onUnpausedUpdate() { auto quat = this->transform->getLocalRotation(); quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0)); quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0)); quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1)); - this->transform->setLocalRotation(quat); } diff --git a/src/dawn/scene/debug/SceneDebugLine.cpp b/src/dawn/scene/debug/SceneDebugLine.cpp index 88d0e8c7..ba32e711 100644 --- a/src/dawn/scene/debug/SceneDebugLine.cpp +++ b/src/dawn/scene/debug/SceneDebugLine.cpp @@ -17,20 +17,19 @@ struct ShaderPassItem SceneDebugLine::createShaderItem( SimpleTexturedShader *shader ) { struct ShaderPassItem item; - item.priority = SCENE_DEBUG_LINE_PRIORITY; + item.priority = this->priority; item.shaderProgram = &shader->program; item.colorValues[shader->program.paramColor] = this->color; - item.matrixValues[shader->program.paramModel] = this->translation; + item.matrixValues[shader->program.paramModel] = this->transform; item.matrixValues[shader->program.paramView] = camera->transform->getWorldTransform(); item.matrixValues[shader->program.paramProjection] = camera->projection; item.boolValues[shader->program.paramHasTexture] = false; - item.renderFlags = 0x00; - auto i = *lineIndex; item.mesh = mesh; item.drawMode = MESH_DRAW_MODE_LINES; + item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND | RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST; item.start = i * SCENE_DEBUG_LINE_INDICE_COUNT; item.count = SCENE_DEBUG_LINE_INDICE_COUNT; @@ -50,8 +49,6 @@ struct ShaderPassItem SceneDebugLine::createShaderItem( indices, SCENE_DEBUG_LINE_INDICE_COUNT ); - - (*lineIndex)++; return item; } @@ -66,7 +63,7 @@ void Scene::debugCube(struct SceneDebugCube cube) { struct SceneDebugLine line; line.color = cube.color; - line.translation = cube.translation; + line.transform = cube.transform; // Bottom Face line.v0 = glm::vec3(min.x, min.y, min.z), line.v1 = glm::vec3(max.x, min.y, min.z); @@ -97,4 +94,42 @@ void Scene::debugCube(struct SceneDebugCube cube) { this->debugLine(line); line.v0 = glm::vec3(max.x, min.y, max.z), line.v1 = glm::vec3(max.x, max.y, max.z); this->debugLine(line); +} + +void Scene::debugOrigin() { + struct SceneDebugLine line; + line.v1 = glm::vec3(1, 0, 0), line.color = COLOR_RED; + this->debugLine(line); + line.v1 = glm::vec3(0, 1, 0), line.color = COLOR_GREEN; + this->debugLine(line); + line.v1 = glm::vec3(0, 0, 1), line.color = COLOR_BLUE; + this->debugLine(line); +} + +void Scene::debugGrid() { + float_t s = 10.0f; + float_t t = 1.0f; + + struct SceneDebugLine line; + line.color = COLOR_LIGHT_GREY; + line.color.a = 0.2f; + + line.v0 = glm::vec3(-s, 0, -s), line.v1 = glm::vec3(s, 0, -s); + this->debugLine(line); + line.v0 = glm::vec3(-s, 0, -s), line.v1 = glm::vec3(-s, 0, s); + this->debugLine(line); + line.v0 = glm::vec3(s, 0, -s), line.v1 = glm::vec3(s, 0, s); + this->debugLine(line); + line.v0 = glm::vec3(-s, 0, s), line.v1 = glm::vec3(s, 0, s); + this->debugLine(line); + + for(float_t x = -s+t; x < s; x += t) { + line.v0 = glm::vec3(x, 0, -s), line.v1 = glm::vec3(x, 0, s); + this->debugLine(line); + } + + for(float_t z = -s+t; z < s; z += t) { + line.v0 = glm::vec3(-s, 0, z), line.v1 = glm::vec3(s, 0, z); + this->debugLine(line); + } } \ No newline at end of file diff --git a/src/dawn/scene/debug/SceneDebugLine.hpp b/src/dawn/scene/debug/SceneDebugLine.hpp index a0bf9b77..af42b57f 100644 --- a/src/dawn/scene/debug/SceneDebugLine.hpp +++ b/src/dawn/scene/debug/SceneDebugLine.hpp @@ -10,7 +10,7 @@ #define SCENE_DEBUG_LINE_VERTICE_COUNT 2 #define SCENE_DEBUG_LINE_INDICE_COUNT 2 -#define SCENE_DEBUG_LINE_PRIORITY 100 +#define SCENE_DEBUG_LINE_PRIORITY 1 namespace Dawn { class SimpleTexturedShader; @@ -20,14 +20,16 @@ namespace Dawn { glm::vec3 min; glm::vec3 max; struct Color color = COLOR_RED; - glm::mat4 translation = glm::mat4(1.0f); + glm::mat4 transform = glm::mat4(1.0f); }; struct SceneDebugLine { glm::vec3 v0 = glm::vec3(0, 0, 0); glm::vec3 v1 = glm::vec3(1, 1, 1); struct Color color = COLOR_RED; - glm::mat4 translation = glm::mat4(1.0f); + glm::mat4 transform = glm::mat4(1.0f); + int32_t priority = SCENE_DEBUG_LINE_PRIORITY; + /** * Creates a renderable shader item for this debug line. diff --git a/src/dawntictactoe/components/TicTacToeGame.cpp b/src/dawntictactoe/components/TicTacToeGame.cpp index 859734cd..bb27893c 100644 --- a/src/dawntictactoe/components/TicTacToeGame.cpp +++ b/src/dawntictactoe/components/TicTacToeGame.cpp @@ -11,7 +11,6 @@ using namespace Dawn; TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {} void TicTacToeGame::onStart() { - std::cout << "Test" << std::endl; this->tiles = getScene()->findComponents(); getScene()->eventSceneUpdate.addListener(this, &TicTacToeGame::onSceneUpdate); diff --git a/src/dawntictactoe/scenes/TicTacToeScene.hpp b/src/dawntictactoe/scenes/TicTacToeScene.hpp index b6bdf535..539d69d7 100644 --- a/src/dawntictactoe/scenes/TicTacToeScene.hpp +++ b/src/dawntictactoe/scenes/TicTacToeScene.hpp @@ -29,7 +29,7 @@ namespace Dawn { camera->orthoLeft = -s * ratio; camera->orthoRight = s * ratio; - // auto cube = SimpleSpinningCubePrefab::create(this); + auto cube = SimpleSpinningCubePrefab::create(this); // TriangleMesh::createTriangleMesh(&cube->meshHost->mesh); // SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16); @@ -44,12 +44,6 @@ namespace Dawn { // tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT); } } - - this->debugCube((struct SceneDebugCube){ - .min = glm::vec3(-0.5f, -0.5f, -0.5f), - .max = glm::vec3(0.5f, 0.5f, 0.5f), - COLOR_BLUE - }); } std::vector getRequiredAssets() override {