BIt more cleanup.
This commit is contained in:
		@@ -4,7 +4,7 @@
 | 
				
			|||||||
// https://opensource.org/licenses/MIT
 | 
					// https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "util/flag.hpp"
 | 
					#include "display/RenderTarget.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST FLAG_DEFINE(0)
 | 
					#define RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST FLAG_DEFINE(0)
 | 
				
			||||||
#define RENDER_MANAGER_RENDER_FLAG_BLEND FLAG_DEFINE(1)
 | 
					#define RENDER_MANAGER_RENDER_FLAG_BLEND FLAG_DEFINE(1)
 | 
				
			||||||
@@ -13,7 +13,6 @@ namespace Dawn {
 | 
				
			|||||||
  class DawnGame;
 | 
					  class DawnGame;
 | 
				
			||||||
  class RenderPipeline;
 | 
					  class RenderPipeline;
 | 
				
			||||||
  class ShaderManager;
 | 
					  class ShaderManager;
 | 
				
			||||||
  class RenderTarget;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  class IRenderManager : public std::enable_shared_from_this<IRenderManager> {
 | 
					  class IRenderManager : public std::enable_shared_from_this<IRenderManager> {
 | 
				
			||||||
    protected:
 | 
					    protected:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,19 +23,19 @@ void RenderPipeline::init(const std::weak_ptr<RenderManager> renderManager) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void RenderPipeline::render() {
 | 
					void RenderPipeline::render() {
 | 
				
			||||||
  auto rm = renderManager.lock();
 | 
					  auto rm = renderManager.lock();
 | 
				
			||||||
  assertNotNull(rm, "RenderPipeline::render: RenderManager cannot be null");
 | 
					  assertNotNull(rm, "RenderManager cannot be null");
 | 
				
			||||||
  auto game = rm->game.lock();
 | 
					  auto game = rm->game.lock();
 | 
				
			||||||
  assertNotNull(game, "RenderPipeline::render: Game cannot be null");
 | 
					  assertNotNull(game, "Game cannot be null");
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if(game->scene != nullptr) {
 | 
					  if(game->scene != nullptr) {
 | 
				
			||||||
    renderScene(game->scene);
 | 
					    renderScene(game->scene);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
 | 
					void RenderPipeline::renderScene(const std::shared_ptr<Scene> scene) {
 | 
				
			||||||
  assertNotNull(scene, "RenderPipeline::renderScene: Scene cannot be null");
 | 
					  assertNotNull(scene, "Scene cannot be null");
 | 
				
			||||||
  auto rm = renderManager.lock();
 | 
					  auto rm = renderManager.lock();
 | 
				
			||||||
  assertNotNull(rm, "RenderPipeline::renderScene: RenderManager cannot be null");
 | 
					  assertNotNull(rm, "RenderManager cannot be null");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Render subscenes first.
 | 
					  // Render subscenes first.
 | 
				
			||||||
  auto subSceneControllers = scene->findComponents<SubSceneController>();
 | 
					  auto subSceneControllers = scene->findComponents<SubSceneController>();
 | 
				
			||||||
@@ -47,7 +47,10 @@ void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
 | 
				
			|||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if((*itSubScene)->onlyUpdateUnpaused && scene->game.lock()->timeManager.isPaused) {
 | 
					    if(
 | 
				
			||||||
 | 
					      (*itSubScene)->onlyUpdateUnpaused &&
 | 
				
			||||||
 | 
					      scene->game.lock()->timeManager.isPaused
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
      ++itSubScene;
 | 
					      ++itSubScene;
 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -85,14 +88,17 @@ void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
 | 
				
			|||||||
  renderSceneCamera(scene, backBufferCamera);
 | 
					  renderSceneCamera(scene, backBufferCamera);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared_ptr<Camera> camera) {
 | 
					void RenderPipeline::renderSceneCamera(
 | 
				
			||||||
 | 
					  const std::shared_ptr<Scene> scene,
 | 
				
			||||||
 | 
					  const std::shared_ptr<Camera> camera
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  auto rm = renderManager.lock();
 | 
					  auto rm = renderManager.lock();
 | 
				
			||||||
  assertNotNull(rm, "RenderPipeline::renderSceneCamera: RenderManager cannot be null");
 | 
					  assertNotNull(rm, "RenderManager cannot be null");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<struct ShaderPassItem>::iterator itPassItem;
 | 
					  std::vector<struct ShaderPassItem>::iterator itPassItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  assertNotNull(scene, "RenderPipeline::renderSceneCamera: Scene cannot be null");
 | 
					  assertNotNull(scene, "Scene cannot be null");
 | 
				
			||||||
  assertNotNull(camera, "RenderPipeline::renderSceneCamera: Camera cannot be null");
 | 
					  assertNotNull(camera, "Camera cannot be null");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Create a new render ID. Long story short this is a really dirty way of 
 | 
					  // Create a new render ID. Long story short this is a really dirty way of 
 | 
				
			||||||
  // not sending parameters to shaders more than we need.
 | 
					  // not sending parameters to shaders more than we need.
 | 
				
			||||||
@@ -100,7 +106,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // Get the render target.
 | 
					  // Get the render target.
 | 
				
			||||||
  auto renderTarget = camera->getRenderTarget();
 | 
					  auto renderTarget = camera->getRenderTarget();
 | 
				
			||||||
  assertNotNull(renderTarget, "RenderPipeline::renderSceneCamera: Camera must have a render target");
 | 
					  assertNotNull(renderTarget, "Camera must have a render target");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Update shader parameter buffers with current knowledge
 | 
					  // Update shader parameter buffers with current knowledge
 | 
				
			||||||
  struct RenderPipelineShaderBufferData shaderBufferData;
 | 
					  struct RenderPipelineShaderBufferData shaderBufferData;
 | 
				
			||||||
@@ -177,7 +183,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared
 | 
				
			|||||||
    auto itTextureSlot = item.textureSlots.begin();
 | 
					    auto itTextureSlot = item.textureSlots.begin();
 | 
				
			||||||
    while(itTextureSlot != item.textureSlots.end()) {
 | 
					    while(itTextureSlot != item.textureSlots.end()) {
 | 
				
			||||||
      // Assert texture isn't null, just don't include it.
 | 
					      // Assert texture isn't null, just don't include it.
 | 
				
			||||||
      assertNotNull(itTextureSlot->second, "RenderPipeline::renderSceneCamera: Texture cannot be null (omit texture instead)");
 | 
					      assertNotNull(itTextureSlot->second, "Texture cannot be null (omit)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if(boundTextures[itTextureSlot->first] != itTextureSlot->second) {
 | 
					      if(boundTextures[itTextureSlot->first] != itTextureSlot->second) {
 | 
				
			||||||
        itTextureSlot->second->bind(itTextureSlot->first);
 | 
					        itTextureSlot->second->bind(itTextureSlot->first);
 | 
				
			||||||
@@ -231,7 +237,9 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    auto itBuffer = item.parameterBuffers.begin();
 | 
					    auto itBuffer = item.parameterBuffers.begin();
 | 
				
			||||||
    while(itBuffer != item.parameterBuffers.end()) {
 | 
					    while(itBuffer != item.parameterBuffers.end()) {
 | 
				
			||||||
      item.shader->setParameterBuffer(itBuffer->first, boundBuffers[itBuffer->first]);
 | 
					      item.shader->setParameterBuffer(
 | 
				
			||||||
 | 
					        itBuffer->first, boundBuffers[itBuffer->first]
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
      ++itBuffer;
 | 
					      ++itBuffer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ namespace Dawn {
 | 
				
			|||||||
       * 
 | 
					       * 
 | 
				
			||||||
       * @param scene Scene to render.
 | 
					       * @param scene Scene to render.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      virtual void renderScene(std::shared_ptr<Scene> scene);
 | 
					      virtual void renderScene(const std::shared_ptr<Scene> scene);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Render a specific camera on a specific scene.
 | 
					       * Render a specific camera on a specific scene.
 | 
				
			||||||
@@ -55,8 +55,8 @@ namespace Dawn {
 | 
				
			|||||||
       * @param camera Camera within the scene to render.
 | 
					       * @param camera Camera within the scene to render.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      virtual void renderSceneCamera(
 | 
					      virtual void renderSceneCamera(
 | 
				
			||||||
        std::shared_ptr<Scene> scene,
 | 
					        const std::shared_ptr<Scene> scene,
 | 
				
			||||||
        std::shared_ptr<Camera> camera
 | 
					        const std::shared_ptr<Camera> camera
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,7 @@ namespace Dawn {
 | 
				
			|||||||
       * 
 | 
					       * 
 | 
				
			||||||
       * @param color Color to use for the clear operation.
 | 
					       * @param color Color to use for the clear operation.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      virtual void setClearColor(struct Color color) = 0;
 | 
					      virtual void setClearColor(const struct Color color) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Request the existing data in the render target to be cleared out. We
 | 
					       * Request the existing data in the render target to be cleared out. We
 | 
				
			||||||
@@ -57,7 +57,7 @@ namespace Dawn {
 | 
				
			|||||||
       * 
 | 
					       * 
 | 
				
			||||||
       * @param clearFlags Flags to request what is going to be cleared.
 | 
					       * @param clearFlags Flags to request what is going to be cleared.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      virtual void clear(flag8_t clearFlags) = 0;
 | 
					      virtual void clear(const flag8_t clearFlags) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Bind the render target for rendering to. The proceeding render requests
 | 
					       * Bind the render target for rendering to. The proceeding render requests
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,12 +4,13 @@
 | 
				
			|||||||
// https://opensource.org/licenses/MIT
 | 
					// https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Tileset.hpp"
 | 
					#include "Tileset.hpp"
 | 
				
			||||||
 | 
					#include "assert/assert.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Tile Tileset::getTile(int32_t tile) {
 | 
					struct Tile Tileset::getTile(const int32_t tile) {
 | 
				
			||||||
  assertTrue(tile >= 0, "Tileset::getTile: Tile must be greater than or equal to 0");
 | 
					  assertTrue(tile >= 0, "Tile must be greater than or equal to 0");
 | 
				
			||||||
  assertTrue(tile < this->tiles.size(), "Tileset::getTile: Tile is out of bounds");
 | 
					  assertTrue(tile < this->tiles.size(), "Tile is out of bounds");
 | 
				
			||||||
  return this->tiles[tile];
 | 
					  return this->tiles[tile];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,25 +18,10 @@ TilesetGrid::TilesetGrid() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TilesetGrid::TilesetGrid(
 | 
					 | 
				
			||||||
  Texture *texture,
 | 
					 | 
				
			||||||
  int32_t columns,
 | 
					 | 
				
			||||||
  int32_t rows
 | 
					 | 
				
			||||||
) : TilesetGrid(
 | 
					 | 
				
			||||||
  columns, rows,
 | 
					 | 
				
			||||||
  texture->getWidth(), texture->getHeight(),
 | 
					 | 
				
			||||||
  0, 0,
 | 
					 | 
				
			||||||
  0, 0
 | 
					 | 
				
			||||||
) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TilesetGrid::TilesetGrid(
 | 
					TilesetGrid::TilesetGrid(
 | 
				
			||||||
  Texture &texture,
 | 
					  Texture &texture,
 | 
				
			||||||
  int32_t columns,
 | 
					  const int32_t columns,
 | 
				
			||||||
  int32_t rows
 | 
					  const int32_t rows
 | 
				
			||||||
) : TilesetGrid(
 | 
					) : TilesetGrid(
 | 
				
			||||||
  columns, rows,
 | 
					  columns, rows,
 | 
				
			||||||
  texture.getWidth(), texture.getHeight(),
 | 
					  texture.getWidth(), texture.getHeight(),
 | 
				
			||||||
@@ -46,25 +32,25 @@ TilesetGrid::TilesetGrid(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TilesetGrid::TilesetGrid(
 | 
					TilesetGrid::TilesetGrid(
 | 
				
			||||||
  int32_t columns,
 | 
					  const int32_t columns,
 | 
				
			||||||
  int32_t rows,
 | 
					  const int32_t rows,
 | 
				
			||||||
  int32_t w,
 | 
					  const int32_t w,
 | 
				
			||||||
  int32_t h,
 | 
					  const int32_t h,
 | 
				
			||||||
  int32_t gapX,
 | 
					  const int32_t gapX,
 | 
				
			||||||
  int32_t gapY,
 | 
					  const int32_t gapY,
 | 
				
			||||||
  int32_t borderX,
 | 
					  const int32_t borderX,
 | 
				
			||||||
  int32_t borderY
 | 
					  const int32_t borderY
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertTrue(columns >= 1, "TilesetGrid::TilesetGrid: Columns must be greater than or equal to 1");
 | 
					  assertTrue(columns >= 1, "Columns must be greater than or equal to 1");
 | 
				
			||||||
  assertTrue(rows >= 1, "TilesetGrid::TilesetGrid: Rows must be greater than or equal to 1");
 | 
					  assertTrue(rows >= 1, "Rows must be greater than or equal to 1");
 | 
				
			||||||
  assertTrue(w >= 1, "TilesetGrid::TilesetGrid: Width must be greater than or equal to 1");
 | 
					  assertTrue(w >= 1, "Width must be greater than or equal to 1");
 | 
				
			||||||
  assertTrue(h >= 1, "TilesetGrid::TilesetGrid: Height must be greater than or equal to 1");
 | 
					  assertTrue(h >= 1, "Height must be greater than or equal to 1");
 | 
				
			||||||
  assertTrue(gapX >= 0, "TilesetGrid::TilesetGrid: GapX must be greater than or equal to 0");
 | 
					  assertTrue(gapX >= 0, "GapX must be greater than or equal to 0");
 | 
				
			||||||
  assertTrue(gapY >= 0, "TilesetGrid::TilesetGrid: GapY must be greater than or equal to 0");
 | 
					  assertTrue(gapY >= 0, "GapY must be greater than or equal to 0");
 | 
				
			||||||
  assertTrue(borderX >= 0, "TilesetGrid::TilesetGrid: BorderX must be greater than or equal to 0");
 | 
					  assertTrue(borderX >= 0, "BorderX must be greater than or equal to 0");
 | 
				
			||||||
  assertTrue(borderY >= 0, "TilesetGrid::TilesetGrid: BorderY must be greater than or equal to 0");
 | 
					  assertTrue(borderY >= 0, "BorderY must be greater than or equal to 0");
 | 
				
			||||||
  assertTrue(w >= (columns + (gapX * columns) + borderX + borderX), "TilesetGrid::TilesetGrid: Width is too small");
 | 
					  assertTrue(w >= (columns + (gapX * columns) + borderX + borderX), "Width is too small");
 | 
				
			||||||
  assertTrue(h >= (rows + (gapY * rows) + borderY + borderY), "TilesetGrid::TilesetGrid: Height is too small");
 | 
					  assertTrue(h >= (rows + (gapY * rows) + borderY + borderY), "Height is too small");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->rows = rows;
 | 
					  this->rows = rows;
 | 
				
			||||||
  this->columns = columns;
 | 
					  this->columns = columns;
 | 
				
			||||||
@@ -74,12 +60,12 @@ TilesetGrid::TilesetGrid(
 | 
				
			|||||||
  this->divY = (h - (borderY * 2) - (gapY * (rows - 1))) / rows;
 | 
					  this->divY = (h - (borderY * 2) - (gapY * (rows - 1))) / rows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Calculate the division sizes (units)
 | 
					  // Calculate the division sizes (units)
 | 
				
			||||||
  float_t tdivX = (float_t)this->divX / (float_t)w;
 | 
					  const float_t tdivX = (float_t)this->divX / (float_t)w;
 | 
				
			||||||
  float_t tdivY = (float_t)this->divY / (float_t)h;
 | 
					  const float_t tdivY = (float_t)this->divY / (float_t)h;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  struct Tile tile;
 | 
				
			||||||
  for(int32_t y = 0; y < rows; y++) {
 | 
					  for(int32_t y = 0; y < rows; y++) {
 | 
				
			||||||
    for(int32_t x = 0; x < columns; x++) {
 | 
					    for(int32_t x = 0; x < columns; x++) {
 | 
				
			||||||
      struct Tile tile;
 | 
					 | 
				
			||||||
      tile.uv0.x = (borderX + ((float_t)this->divX * x) + (gapX * x)) / w;
 | 
					      tile.uv0.x = (borderX + ((float_t)this->divX * x) + (gapX * x)) / w;
 | 
				
			||||||
      tile.uv1.x = tile.uv0.x + tdivX;
 | 
					      tile.uv1.x = tile.uv0.x + tdivX;
 | 
				
			||||||
          
 | 
					          
 | 
				
			||||||
@@ -90,16 +76,19 @@ TilesetGrid::TilesetGrid(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float_t TilesetGrid::getTileWidth(int32_t tile) {
 | 
					float_t TilesetGrid::getTileWidth(const int32_t tile) {
 | 
				
			||||||
  return this->divX;
 | 
					  return this->divX;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float_t TilesetGrid::getTileHeight(int32_t tile) {
 | 
					float_t TilesetGrid::getTileHeight(const int32_t tile) {
 | 
				
			||||||
  return this->divY;
 | 
					  return this->divY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Tile TilesetGrid::getTileFromGrid(int32_t column, int32_t row) {
 | 
					struct Tile TilesetGrid::getTileFromGrid(
 | 
				
			||||||
  assertTrue(row > 0 && row < this->rows, "TilesetGrid::getTileFromGrid: Row is out of bounds");
 | 
					  const int32_t column,
 | 
				
			||||||
  assertTrue(column > 0 && column < this->columns, "TilesetGrid::getTileFromGrid: Column is out of bounds");
 | 
					  const int32_t row
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
					  assertTrue(row > 0 && row < this->rows, "Row is out of bounds");
 | 
				
			||||||
 | 
					  assertTrue(column > 0 && column < this->columns, "Column is out of bounds");
 | 
				
			||||||
  return this->getTile(row + (column * this->rows));
 | 
					  return this->getTile(row + (column * this->rows));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -5,7 +5,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "dawnlibs.hpp"
 | 
					#include "dawnlibs.hpp"
 | 
				
			||||||
#include "assert/assert.hpp"
 | 
					 | 
				
			||||||
#include "display/Texture.hpp"
 | 
					#include "display/Texture.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Dawn {
 | 
					namespace Dawn {
 | 
				
			||||||
@@ -24,7 +23,7 @@ namespace Dawn {
 | 
				
			|||||||
       * @param tile Tile index to get.
 | 
					       * @param tile Tile index to get.
 | 
				
			||||||
       * @return Tile at that index.
 | 
					       * @return Tile at that index.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      struct Tile getTile(int32_t tile);
 | 
					      struct Tile getTile(const int32_t tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Returns the width of an individual tile.
 | 
					       * Returns the width of an individual tile.
 | 
				
			||||||
@@ -32,7 +31,7 @@ namespace Dawn {
 | 
				
			|||||||
       * @param tile The tile to get the width of.
 | 
					       * @param tile The tile to get the width of.
 | 
				
			||||||
       * @return The tile width.
 | 
					       * @return The tile width.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      virtual float_t getTileWidth(int32_t tile) = 0;
 | 
					      virtual float_t getTileWidth(const int32_t tile) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Returns the height of an individual tile.
 | 
					       * Returns the height of an individual tile.
 | 
				
			||||||
@@ -40,7 +39,7 @@ namespace Dawn {
 | 
				
			|||||||
       * @param tile The tile to get the height of.
 | 
					       * @param tile The tile to get the height of.
 | 
				
			||||||
       * @return The tile height.
 | 
					       * @return The tile height.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      virtual float_t getTileHeight(int32_t tile) = 0;
 | 
					      virtual float_t getTileHeight(const int32_t tile) = 0;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  struct TilesetGrid : public Tileset{
 | 
					  struct TilesetGrid : public Tileset{
 | 
				
			||||||
@@ -62,16 +61,11 @@ namespace Dawn {
 | 
				
			|||||||
       * @param columns Columns in the grid.
 | 
					       * @param columns Columns in the grid.
 | 
				
			||||||
       * @param rows Rows in the grid.
 | 
					       * @param rows Rows in the grid.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      TilesetGrid(Texture *texture, int32_t columns, int32_t rows);
 | 
					      TilesetGrid(
 | 
				
			||||||
 | 
					        Texture &texture,
 | 
				
			||||||
      /**
 | 
					        const int32_t columns,
 | 
				
			||||||
       * Constructs a new Tileset Grid from a texture.
 | 
					        const int32_t rows
 | 
				
			||||||
       * 
 | 
					      );
 | 
				
			||||||
       * @param texture Texture to use.
 | 
					 | 
				
			||||||
       * @param columns Columns in the grid.
 | 
					 | 
				
			||||||
       * @param rows Rows in the grid.
 | 
					 | 
				
			||||||
       */
 | 
					 | 
				
			||||||
      TilesetGrid(Texture &texture, int32_t columns, int32_t rows);
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Constructs a new Tileset Grid.
 | 
					       * Constructs a new Tileset Grid.
 | 
				
			||||||
@@ -86,18 +80,18 @@ namespace Dawn {
 | 
				
			|||||||
       * @param borderY Border at the edge of the grid before the first tiles.
 | 
					       * @param borderY Border at the edge of the grid before the first tiles.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      TilesetGrid(
 | 
					      TilesetGrid(
 | 
				
			||||||
        int32_t columns,
 | 
					        const int32_t columns,
 | 
				
			||||||
        int32_t rows,
 | 
					        const int32_t rows,
 | 
				
			||||||
        int32_t w,
 | 
					        const int32_t w,
 | 
				
			||||||
        int32_t h,
 | 
					        const int32_t h,
 | 
				
			||||||
        int32_t gapX,
 | 
					        const int32_t gapX,
 | 
				
			||||||
        int32_t gapY,
 | 
					        const int32_t gapY,
 | 
				
			||||||
        int32_t borderX,
 | 
					        const int32_t borderX,
 | 
				
			||||||
        int32_t borderY
 | 
					        const int32_t borderY
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      float_t getTileWidth(int32_t tile) override;
 | 
					      float_t getTileWidth(const int32_t tile) override;
 | 
				
			||||||
      float_t getTileHeight(int32_t tile) override;
 | 
					      float_t getTileHeight(const int32_t tile) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Returns the tile at a given grid position.
 | 
					       * Returns the tile at a given grid position.
 | 
				
			||||||
@@ -106,6 +100,6 @@ namespace Dawn {
 | 
				
			|||||||
       * @param row Row (0 indexed) to get the tile of.
 | 
					       * @param row Row (0 indexed) to get the tile of.
 | 
				
			||||||
       * @return Tile at this grid position.
 | 
					       * @return Tile at this grid position.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      struct Tile getTileFromGrid(int32_t column, int32_t row);
 | 
					      struct Tile getTileFromGrid(const int32_t column, const int32_t row);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -5,21 +5,22 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "TrueTypeFaceTexture.hpp"
 | 
					#include "TrueTypeFaceTexture.hpp"
 | 
				
			||||||
#include "util/memory.hpp"
 | 
					#include "util/memory.hpp"
 | 
				
			||||||
 | 
					#include "util/mathutils.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TrueTypeFaceTexture::TrueTypeFaceTexture(
 | 
					TrueTypeFaceTexture::TrueTypeFaceTexture(
 | 
				
			||||||
  FT_Face face,
 | 
					  const FT_Face face,
 | 
				
			||||||
  struct TrueTypeFaceTextureStyle style
 | 
					  const struct TrueTypeFaceTextureStyle style
 | 
				
			||||||
) {
 | 
					) :
 | 
				
			||||||
  assertTrue(style.fontSize < 256, "TrueTypeFaceTexture::TrueTypeFaceTexture: Font size cannot be greater than 256");
 | 
					  face(face),
 | 
				
			||||||
 | 
					  style(style)
 | 
				
			||||||
  this->face = face;
 | 
					{
 | 
				
			||||||
  this->style = style;
 | 
					  assertTrue(style.fontSize < 256, "Font size cannot be greater than 256");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Set freetype font size prior to baking.
 | 
					  // Set freetype font size prior to baking.
 | 
				
			||||||
  if(FT_Set_Pixel_Sizes(face, 0, style.fontSize)) {
 | 
					  if(FT_Set_Pixel_Sizes(face, 0, style.fontSize)) {
 | 
				
			||||||
    assertUnreachable("TrueTypeFaceTexture::TrueTypeFaceTexture: Failed to set font size");
 | 
					    assertUnreachable("Failed to set font size");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  size_t w = 0, h = 0;
 | 
					  size_t w = 0, h = 0;
 | 
				
			||||||
@@ -30,18 +31,20 @@ TrueTypeFaceTexture::TrueTypeFaceTexture(
 | 
				
			|||||||
    // Load the character
 | 
					    // Load the character
 | 
				
			||||||
    auto ret = FT_Load_Char(face, c, ~FT_LOAD_RENDER);
 | 
					    auto ret = FT_Load_Char(face, c, ~FT_LOAD_RENDER);
 | 
				
			||||||
    if(ret) {
 | 
					    if(ret) {
 | 
				
			||||||
      assertUnreachable("TrueTypeFaceTexture::TrueTypeFaceTexture: Failed to load character (0)");
 | 
					      assertUnreachable("Failed to load character (0)");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(face->glyph->bitmap.width == 0 || face->glyph->bitmap.rows == 0) continue;
 | 
					    if(face->glyph->bitmap.width == 0 || face->glyph->bitmap.rows == 0) {
 | 
				
			||||||
 | 
					      continue;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Update the width and height
 | 
					    // Update the width and height
 | 
				
			||||||
    w = mathMax<size_t>(w, face->glyph->bitmap.width);
 | 
					    w = mathMax<size_t>(w, face->glyph->bitmap.width);
 | 
				
			||||||
    h += face->glyph->bitmap.rows;
 | 
					    h += face->glyph->bitmap.rows;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  assertTrue(w > 0, "TrueTypeFaceTexture::TrueTypeFaceTexture: Width cannot be less than or equal to 0");
 | 
					  assertTrue(w > 0, "Width cannot be less than or equal to 0");
 | 
				
			||||||
  assertTrue(h > 0, "TrueTypeFaceTexture::TrueTypeFaceTexture: Height cannot be less than or equal to 0");
 | 
					  assertTrue(h > 0, "Height cannot be less than or equal to 0");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Now buffer pixels to the texture
 | 
					  // Now buffer pixels to the texture
 | 
				
			||||||
  float_t y = 0;
 | 
					  float_t y = 0;
 | 
				
			||||||
@@ -51,20 +54,26 @@ TrueTypeFaceTexture::TrueTypeFaceTexture(
 | 
				
			|||||||
  uint8_t *buffer = (uint8_t *)memoryAllocateEmpty(w * h, sizeof(uint8_t));
 | 
					  uint8_t *buffer = (uint8_t *)memoryAllocateEmpty(w * h, sizeof(uint8_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  size_t offset = 0;
 | 
					  size_t offset = 0;
 | 
				
			||||||
  struct TrueTypeCharacter info;
 | 
					 | 
				
			||||||
  for(c = TRUE_TYPE_CHAR_BEGIN; c < TRUE_TYPE_CHAR_END; c++) {
 | 
					  for(c = TRUE_TYPE_CHAR_BEGIN; c < TRUE_TYPE_CHAR_END; c++) {
 | 
				
			||||||
    // Load the character
 | 
					    // Load the character
 | 
				
			||||||
    if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
 | 
					    if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
 | 
				
			||||||
      assertUnreachable("TrueTypeFaceTexture::TrueTypeFaceTexture: Failed to load character (1)");
 | 
					      assertUnreachable("Failed to load character (1)");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Store the character information
 | 
					    // Store the character information
 | 
				
			||||||
    info.advanceX = (float_t)(face->glyph->advance.x >> 6);
 | 
					    const struct TrueTypeCharacter info = {
 | 
				
			||||||
    info.advanceY = (float_t)(face->glyph->advance.y >> 6);
 | 
					      .advanceX = (float_t)(face->glyph->advance.x >> 6),
 | 
				
			||||||
    info.bitmapSize = glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
 | 
					      .advanceY = (float_t)(face->glyph->advance.y >> 6),
 | 
				
			||||||
    info.bitmapPosition = glm::vec2(face->glyph->bitmap_left, -face->glyph->bitmap_top);
 | 
					      .bitmapSize = glm::vec2(
 | 
				
			||||||
    info.textureY = y;
 | 
					        face->glyph->bitmap.width,
 | 
				
			||||||
    char c2 = (char)c;
 | 
					        face->glyph->bitmap.rows
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					      .bitmapPosition = glm::vec2(
 | 
				
			||||||
 | 
					        face->glyph->bitmap_left,
 | 
				
			||||||
 | 
					        -face->glyph->bitmap_top
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					      .textureY = y
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
    this->characterData[c] = info;
 | 
					    this->characterData[c] = info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Buffer the pixels, oh dear GOD there has to be a more efficient way.
 | 
					    // Buffer the pixels, oh dear GOD there has to be a more efficient way.
 | 
				
			||||||
@@ -75,17 +84,23 @@ TrueTypeFaceTexture::TrueTypeFaceTexture(
 | 
				
			|||||||
        face->glyph->bitmap.width * sizeof(uint8_t)
 | 
					        face->glyph->bitmap.width * sizeof(uint8_t)
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      offset += w * sizeof(uint8_t);
 | 
					      offset += w * sizeof(uint8_t);
 | 
				
			||||||
      assertTrue(offset <= (w * h * sizeof(uint8_t)), "TrueTypeFaceTexture::TrueTypeFaceTexture: Buffer overflow");
 | 
					      assertTrue(offset <= (w * h * sizeof(uint8_t)), "Buffer overflow");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    y += face->glyph->bitmap.rows;
 | 
					    y += face->glyph->bitmap.rows;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->texture.setSize(w, h, TEXTURE_FORMAT_R, TEXTURE_DATA_FORMAT_UNSIGNED_BYTE);
 | 
					  this->texture.setSize(
 | 
				
			||||||
 | 
					    w, h,
 | 
				
			||||||
 | 
					    TEXTURE_FORMAT_R,
 | 
				
			||||||
 | 
					    TEXTURE_DATA_FORMAT_UNSIGNED_BYTE
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
  this->texture.buffer(buffer);
 | 
					  this->texture.buffer(buffer);
 | 
				
			||||||
  memoryFree(buffer);
 | 
					  memoryFree(buffer);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct TrueTypeCharacter TrueTypeFaceTexture::getCharacterData(FT_ULong c) {
 | 
					struct TrueTypeCharacter TrueTypeFaceTexture::getCharacterData(
 | 
				
			||||||
 | 
					  const FT_ULong c
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  return this->characterData[c];
 | 
					  return this->characterData[c];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,10 +4,20 @@
 | 
				
			|||||||
// https://opensource.org/licenses/MIT
 | 
					// https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "display/font/truetype/TrueTypeShared.hpp"
 | 
					#include <ft2build.h>
 | 
				
			||||||
#include "util/mathutils.hpp"
 | 
					#include FT_FREETYPE_H
 | 
				
			||||||
 | 
					#include "util/flag.hpp"
 | 
				
			||||||
#include "display/Texture.hpp"
 | 
					#include "display/Texture.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define TRUE_TYPE_CHAR_BEGIN 0x00
 | 
				
			||||||
 | 
					#define TRUE_TYPE_CHAR_END 0xFF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define TRUE_TYPE_VARIANT_BOLD FLAG_DEFINE(0)
 | 
				
			||||||
 | 
					#define TRUE_TYPE_VARIANT_ITALICS FLAG_DEFINE(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define TRUE_TYPE_DECORATION_STRIKETHROUGH FLAG_DEFINE(0)
 | 
				
			||||||
 | 
					#define TRUE_TYPE_DECORATION_UNDERLINE FLAG_DEFINE(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Dawn {
 | 
					namespace Dawn {
 | 
				
			||||||
  class TrueTypeAsset;
 | 
					  class TrueTypeAsset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,9 +40,9 @@ namespace Dawn {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  class TrueTypeFaceTexture {
 | 
					  class TrueTypeFaceTexture {
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
      FT_Face face;
 | 
					      const FT_Face face;
 | 
				
			||||||
 | 
					      const struct TrueTypeFaceTextureStyle style;
 | 
				
			||||||
      std::map<FT_ULong, struct TrueTypeCharacter> characterData;
 | 
					      std::map<FT_ULong, struct TrueTypeCharacter> characterData;
 | 
				
			||||||
      struct TrueTypeFaceTextureStyle style;
 | 
					 | 
				
			||||||
      Texture texture;
 | 
					      Texture texture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -42,8 +52,8 @@ namespace Dawn {
 | 
				
			|||||||
       * @param style Style that this font has, used for locking.
 | 
					       * @param style Style that this font has, used for locking.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      TrueTypeFaceTexture(
 | 
					      TrueTypeFaceTexture(
 | 
				
			||||||
        FT_Face face,
 | 
					        const FT_Face face,
 | 
				
			||||||
        struct TrueTypeFaceTextureStyle style
 | 
					        const struct TrueTypeFaceTextureStyle style
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -52,12 +62,12 @@ namespace Dawn {
 | 
				
			|||||||
       * @param c Character to get data for.
 | 
					       * @param c Character to get data for.
 | 
				
			||||||
       * @return The Character data for the given character.
 | 
					       * @return The Character data for the given character.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      struct TrueTypeCharacter getCharacterData(FT_ULong c);
 | 
					      struct TrueTypeCharacter getCharacterData(const FT_ULong c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Destroys this true type face texture.
 | 
					       * Destroys this true type face texture.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      ~TrueTypeFaceTexture();
 | 
					      virtual ~TrueTypeFaceTexture();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      friend class TrueTypeAsset;
 | 
					      friend class TrueTypeAsset;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +0,0 @@
 | 
				
			|||||||
// Copyright (c) 2023 Dominic Masters
 | 
					 | 
				
			||||||
// 
 | 
					 | 
				
			||||||
// This software is released under the MIT License.
 | 
					 | 
				
			||||||
// https://opensource.org/licenses/MIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#pragma once
 | 
					 | 
				
			||||||
#include <ft2build.h>
 | 
					 | 
				
			||||||
#include FT_FREETYPE_H
 | 
					 | 
				
			||||||
#include "util/flag.hpp"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define TRUE_TYPE_CHAR_BEGIN 0x00
 | 
					 | 
				
			||||||
#define TRUE_TYPE_CHAR_END 0xFF
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define TRUE_TYPE_VARIANT_BOLD FLAG_DEFINE(0)
 | 
					 | 
				
			||||||
#define TRUE_TYPE_VARIANT_ITALICS FLAG_DEFINE(1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define TRUE_TYPE_DECORATION_STRIKETHROUGH FLAG_DEFINE(0)
 | 
					 | 
				
			||||||
#define TRUE_TYPE_DECORATION_UNDERLINE FLAG_DEFINE(1)
 | 
					 | 
				
			||||||
@@ -8,43 +8,40 @@
 | 
				
			|||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CapsuleMesh::calculateRing(
 | 
					void CapsuleMesh::calculateRing(
 | 
				
			||||||
  int32_t segments,
 | 
					  const int32_t segments,
 | 
				
			||||||
  float_t height,
 | 
					  const float_t height,
 | 
				
			||||||
  float_t radius,
 | 
					  const float_t radius,
 | 
				
			||||||
  float_t dr,
 | 
					  const float_t dr,
 | 
				
			||||||
  float_t y,
 | 
					  const float_t y,
 | 
				
			||||||
  float_t dy,
 | 
					  const float_t dy,
 | 
				
			||||||
  std::vector<glm::vec3> *positions
 | 
					  std::vector<glm::vec3> &positions
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(positions, "CapsuleMesh::calculateRing: positions cannot be null");
 | 
					 | 
				
			||||||
  float_t segIncr = 1.0f / (float_t)(segments - 1);
 | 
					  float_t segIncr = 1.0f / (float_t)(segments - 1);
 | 
				
			||||||
  for(int32_t s = 0; s < segments; s++ ) {
 | 
					  for(int32_t s = 0; s < segments; s++ ) {
 | 
				
			||||||
    float_t x = cosf(MATH_PI * 2 * s * segIncr) * dr;
 | 
					    float_t x = cosf(MATH_PI * 2 * s * segIncr) * dr;
 | 
				
			||||||
    float_t z = sinf(MATH_PI * 2 * s * segIncr) * dr;
 | 
					    float_t z = sinf(MATH_PI * 2 * s * segIncr) * dr;
 | 
				
			||||||
    positions->emplace_back(glm::vec3(radius * x, radius * y + height * dy, radius * z ));
 | 
					    positions.emplace_back(glm::vec3(radius * x, radius * y + height * dy, radius * z ));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CapsuleMesh::create(
 | 
					void CapsuleMesh::create(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  float_t radius,
 | 
					  const float_t radius,
 | 
				
			||||||
  float_t height
 | 
					  const float_t height
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(mesh, "CapsuleMesh::create: Mesh cannot be null");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  std::vector<glm::vec3> positions;
 | 
					  std::vector<glm::vec3> positions;
 | 
				
			||||||
  std::vector<meshindice_t> indices;
 | 
					  std::vector<meshindice_t> indices;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int32_t slices = 12;
 | 
					  const int32_t slices = 12;
 | 
				
			||||||
  int32_t segments = 12;
 | 
					  const int32_t segments = 12;
 | 
				
			||||||
  int32_t ringsBody = slices + 1;
 | 
					  const int32_t ringsBody = slices + 1;
 | 
				
			||||||
  int32_t ringsTotal = slices + ringsBody;
 | 
					  const int32_t ringsTotal = slices + ringsBody;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  positions.reserve(segments * ringsTotal);
 | 
					  positions.reserve(segments * ringsTotal);
 | 
				
			||||||
  indices.reserve((segments - 1) * (ringsTotal - 1) * 6);
 | 
					  indices.reserve((segments - 1) * (ringsTotal - 1) * 6);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  float_t bodyIncr = 1.0f / (float_t)(ringsBody - 1);
 | 
					  const float_t bodyIncr = 1.0f / (float_t)(ringsBody - 1);
 | 
				
			||||||
  float_t ringIncr = 1.0f / (float_t)(slices - 1);
 | 
					  const float_t ringIncr = 1.0f / (float_t)(slices - 1);
 | 
				
			||||||
  for(int32_t r = 0; r < slices / 2; r++) {
 | 
					  for(int32_t r = 0; r < slices / 2; r++) {
 | 
				
			||||||
    calculateRing(
 | 
					    calculateRing(
 | 
				
			||||||
      segments,
 | 
					      segments,
 | 
				
			||||||
@@ -53,7 +50,7 @@ void CapsuleMesh::create(
 | 
				
			|||||||
      sinf(MATH_PI * r * ringIncr),
 | 
					      sinf(MATH_PI * r * ringIncr),
 | 
				
			||||||
      sinf(MATH_PI * (r * ringIncr - 0.5f)),
 | 
					      sinf(MATH_PI * (r * ringIncr - 0.5f)),
 | 
				
			||||||
      -0.5f,
 | 
					      -0.5f,
 | 
				
			||||||
      &positions
 | 
					      positions
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -65,7 +62,7 @@ void CapsuleMesh::create(
 | 
				
			|||||||
      1.0f,
 | 
					      1.0f,
 | 
				
			||||||
      0.0f,
 | 
					      0.0f,
 | 
				
			||||||
      r * bodyIncr - 0.5f,
 | 
					      r * bodyIncr - 0.5f,
 | 
				
			||||||
      &positions
 | 
					      positions
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -77,7 +74,7 @@ void CapsuleMesh::create(
 | 
				
			|||||||
      sinf(MATH_PI * r * ringIncr),
 | 
					      sinf(MATH_PI * r * ringIncr),
 | 
				
			||||||
      sinf(MATH_PI * (r * ringIncr - 0.5f)),
 | 
					      sinf(MATH_PI * (r * ringIncr - 0.5f)),
 | 
				
			||||||
      0.5f,
 | 
					      0.5f,
 | 
				
			||||||
      &positions
 | 
					      positions
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -93,7 +90,7 @@ void CapsuleMesh::create(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mesh->createBuffers(positions.size(), indices.size());
 | 
					  mesh.createBuffers(positions.size(), indices.size());
 | 
				
			||||||
  mesh->bufferPositions(0, positions.data(), positions.size());
 | 
					  mesh.bufferPositions(0, positions.data(), positions.size());
 | 
				
			||||||
  mesh->bufferIndices(0, indices.data(), indices.size());
 | 
					  mesh.bufferIndices(0, indices.data(), indices.size());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -11,20 +11,20 @@ namespace Dawn {
 | 
				
			|||||||
  class CapsuleMesh {
 | 
					  class CapsuleMesh {
 | 
				
			||||||
    protected:
 | 
					    protected:
 | 
				
			||||||
      static void calculateRing(
 | 
					      static void calculateRing(
 | 
				
			||||||
        int32_t segments,
 | 
					        const int32_t segments,
 | 
				
			||||||
        float_t height,
 | 
					        const float_t height,
 | 
				
			||||||
        float_t radius,
 | 
					        const float_t radius,
 | 
				
			||||||
        float_t dr,
 | 
					        const float_t dr,
 | 
				
			||||||
        float_t y,
 | 
					        const float_t y,
 | 
				
			||||||
        float_t dy,
 | 
					        const float_t dy,
 | 
				
			||||||
        std::vector<glm::vec3> *positions
 | 
					        std::vector<glm::vec3> &positions
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
      static void create(
 | 
					      static void create(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        float_t radius,
 | 
					        const float_t radius,
 | 
				
			||||||
        float_t height
 | 
					        const float_t height
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -8,12 +8,12 @@
 | 
				
			|||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void CubeMesh::buffer(
 | 
					void CubeMesh::buffer(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  glm::vec3 pos, glm::vec3 size,
 | 
					  const glm::vec3 pos,
 | 
				
			||||||
  int32_t verticeStart, int32_t indiceStart
 | 
					  const glm::vec3 size,
 | 
				
			||||||
 | 
					  const int32_t verticeStart,
 | 
				
			||||||
 | 
					  const int32_t indiceStart
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(mesh, "CubeMesh::buffer: Mesh cannot be null");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  glm::vec3 positions[CUBE_VERTICE_COUNT] = {
 | 
					  glm::vec3 positions[CUBE_VERTICE_COUNT] = {
 | 
				
			||||||
    pos, 
 | 
					    pos, 
 | 
				
			||||||
    glm::vec3(pos.x+size.x, pos.y, pos.z),
 | 
					    glm::vec3(pos.x+size.x, pos.y, pos.z),
 | 
				
			||||||
@@ -64,7 +64,7 @@ void CubeMesh::buffer(
 | 
				
			|||||||
    verticeStart + 1, verticeStart + 4, verticeStart + 5
 | 
					    verticeStart + 1, verticeStart + 4, verticeStart + 5
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  mesh->bufferPositions(verticeStart, positions, CUBE_VERTICE_COUNT);
 | 
					  mesh.bufferPositions(verticeStart, positions, CUBE_VERTICE_COUNT);
 | 
				
			||||||
  mesh->bufferCoordinates(verticeStart, coordinates, CUBE_VERTICE_COUNT);
 | 
					  mesh.bufferCoordinates(verticeStart, coordinates, CUBE_VERTICE_COUNT);
 | 
				
			||||||
  mesh->bufferIndices(indiceStart, indices, CUBE_INDICE_COUNT);
 | 
					  mesh.bufferIndices(indiceStart, indices, CUBE_INDICE_COUNT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -13,9 +13,11 @@ namespace Dawn {
 | 
				
			|||||||
  class CubeMesh {
 | 
					  class CubeMesh {
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
      static void buffer(
 | 
					      static void buffer(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        glm::vec3 pos, glm::vec3 size,
 | 
					        const glm::vec3 pos,
 | 
				
			||||||
        int32_t verticeStart, int32_t indiceStart
 | 
					        const glm::vec3 size,
 | 
				
			||||||
 | 
					        const int32_t verticeStart,
 | 
				
			||||||
 | 
					        const int32_t indiceStart
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -8,13 +8,15 @@
 | 
				
			|||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QuadMesh::bufferQuadMeshWithZ(
 | 
					void QuadMesh::bufferQuadMeshWithZ(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  glm::vec2 xy0, glm::vec2 uv0,
 | 
					  const glm::vec2 xy0,
 | 
				
			||||||
  glm::vec2 xy1, glm::vec2 uv1,
 | 
					  const glm::vec2 uv0,
 | 
				
			||||||
  float_t z, int32_t verticeStart, int32_t indiceStart
 | 
					  const glm::vec2 xy1,
 | 
				
			||||||
 | 
					  const glm::vec2 uv1,
 | 
				
			||||||
 | 
					  const float_t z,
 | 
				
			||||||
 | 
					  const int32_t verticeStart,
 | 
				
			||||||
 | 
					  const int32_t indiceStart
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(mesh, "QuadMesh::bufferQuadMeshWithZ: Mesh cannot be null");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  glm::vec3 positions[QUAD_VERTICE_COUNT] = {
 | 
					  glm::vec3 positions[QUAD_VERTICE_COUNT] = {
 | 
				
			||||||
    glm::vec3(xy0, z),
 | 
					    glm::vec3(xy0, z),
 | 
				
			||||||
    glm::vec3(xy1.x, xy0.y, z),
 | 
					    glm::vec3(xy1.x, xy0.y, z),
 | 
				
			||||||
@@ -30,16 +32,19 @@ void QuadMesh::bufferQuadMeshWithZ(
 | 
				
			|||||||
    verticeStart + 1, verticeStart + 2, verticeStart + 3
 | 
					    verticeStart + 1, verticeStart + 2, verticeStart + 3
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mesh->bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
 | 
					  mesh.bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
 | 
				
			||||||
  mesh->bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
 | 
					  mesh.bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
 | 
				
			||||||
  mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
 | 
					  mesh.bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QuadMesh::bufferQuadMesh(
 | 
					void QuadMesh::bufferQuadMesh(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  glm::vec2 xy0, glm::vec2 uv0,
 | 
					  const glm::vec2 xy0,
 | 
				
			||||||
  glm::vec2 xy1, glm::vec2 uv1,
 | 
					  const glm::vec2 uv0,
 | 
				
			||||||
  int32_t verticeStart, int32_t indiceStart
 | 
					  const glm::vec2 xy1,
 | 
				
			||||||
 | 
					  const glm::vec2 uv1,
 | 
				
			||||||
 | 
					  const int32_t verticeStart,
 | 
				
			||||||
 | 
					  const int32_t indiceStart
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  QuadMesh::bufferQuadMeshWithZ(
 | 
					  QuadMesh::bufferQuadMeshWithZ(
 | 
				
			||||||
    mesh, xy0, uv0, xy1, uv1, 0, verticeStart, indiceStart
 | 
					    mesh, xy0, uv0, xy1, uv1, 0, verticeStart, indiceStart
 | 
				
			||||||
@@ -47,40 +52,41 @@ void QuadMesh::bufferQuadMesh(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QuadMesh::bufferCoordinates(
 | 
					void QuadMesh::bufferCoordinates(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  glm::vec2 uv0, glm::vec2 uv1,
 | 
					  const glm::vec2 uv0,
 | 
				
			||||||
  int32_t verticeStart
 | 
					  const glm::vec2 uv1,
 | 
				
			||||||
 | 
					  const int32_t verticeStart
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(mesh, "QuadMesh::bufferCoordinates: Mesh cannot be null");
 | 
					 | 
				
			||||||
  glm::vec2 coordinates[QUAD_VERTICE_COUNT] = {
 | 
					  glm::vec2 coordinates[QUAD_VERTICE_COUNT] = {
 | 
				
			||||||
    uv0, glm::vec2(uv1.x, uv0.y),
 | 
					    uv0, glm::vec2(uv1.x, uv0.y),
 | 
				
			||||||
    glm::vec2(uv0.x, uv1.y), uv1
 | 
					    glm::vec2(uv0.x, uv1.y), uv1
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  mesh->bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
 | 
					  mesh.bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QuadMesh::bufferPositions(
 | 
					void QuadMesh::bufferPositions(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  glm::vec2 xy0, glm::vec2 xy1,
 | 
					  const glm::vec2 xy0,
 | 
				
			||||||
  int32_t verticeStart
 | 
					  const glm::vec2 xy1,
 | 
				
			||||||
 | 
					  const int32_t verticeStart
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(mesh, "QuadMesh::bufferPositions: Mesh cannot be null");
 | 
					 | 
				
			||||||
  glm::vec3 positions[QUAD_VERTICE_COUNT] = {
 | 
					  glm::vec3 positions[QUAD_VERTICE_COUNT] = {
 | 
				
			||||||
    glm::vec3(xy0, 0),
 | 
					    glm::vec3(xy0, 0),
 | 
				
			||||||
    glm::vec3(xy1.x, xy0.y, 0),
 | 
					    glm::vec3(xy1.x, xy0.y, 0),
 | 
				
			||||||
    glm::vec3(xy0.x, xy1.y, 0),
 | 
					    glm::vec3(xy0.x, xy1.y, 0),
 | 
				
			||||||
    glm::vec3(xy1, 0)
 | 
					    glm::vec3(xy1, 0)
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  mesh->bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
 | 
					  mesh.bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QuadMesh::initQuadMesh(
 | 
					void QuadMesh::initQuadMesh(
 | 
				
			||||||
  Mesh *mesh,
 | 
					  Mesh &mesh,
 | 
				
			||||||
  glm::vec2 xy0, glm::vec2 uv0,
 | 
					  const glm::vec2 xy0,
 | 
				
			||||||
  glm::vec2 xy1, glm::vec2 uv1,
 | 
					  const glm::vec2 uv0,
 | 
				
			||||||
  float_t z
 | 
					  const glm::vec2 xy1,
 | 
				
			||||||
 | 
					  const glm::vec2 uv1,
 | 
				
			||||||
 | 
					  const float_t z
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  assertNotNull(mesh, "QuadMesh::initQuadMesh: Mesh cannot be null");
 | 
					  mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
 | 
				
			||||||
  mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
 | 
					 | 
				
			||||||
  QuadMesh::bufferQuadMeshWithZ(mesh, xy0, uv0, xy1, uv1, z, 0, 0);
 | 
					  QuadMesh::bufferQuadMeshWithZ(mesh, xy0, uv0, xy1, uv1, z, 0, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -26,10 +26,14 @@ namespace Dawn {
 | 
				
			|||||||
       * @param indiceStart Start indice to buffer to.
 | 
					       * @param indiceStart Start indice to buffer to.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      static void bufferQuadMeshWithZ(
 | 
					      static void bufferQuadMeshWithZ(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        glm::vec2 xy0, glm::vec2 uv0,
 | 
					        const glm::vec2 xy0,
 | 
				
			||||||
        glm::vec2 xy1, glm::vec2 uv1,
 | 
					        const glm::vec2 uv0,
 | 
				
			||||||
        float_t z, int32_t verticeStart, int32_t indiceStart
 | 
					        const glm::vec2 xy1,
 | 
				
			||||||
 | 
					        const glm::vec2 uv1,
 | 
				
			||||||
 | 
					        const float_t z,
 | 
				
			||||||
 | 
					        const int32_t verticeStart,
 | 
				
			||||||
 | 
					        const int32_t indiceStart
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -44,10 +48,13 @@ namespace Dawn {
 | 
				
			|||||||
       * @param indiceStart Start indice to buffer to.
 | 
					       * @param indiceStart Start indice to buffer to.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      static void bufferQuadMesh(
 | 
					      static void bufferQuadMesh(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        glm::vec2 xy0, glm::vec2 uv0,
 | 
					        const glm::vec2 xy0,
 | 
				
			||||||
        glm::vec2 xy1, glm::vec2 uv1,
 | 
					        const glm::vec2 uv0,
 | 
				
			||||||
        int32_t verticeStart, int32_t indiceStart
 | 
					        const glm::vec2 xy1,
 | 
				
			||||||
 | 
					        const glm::vec2 uv1,
 | 
				
			||||||
 | 
					        const int32_t verticeStart,
 | 
				
			||||||
 | 
					        const int32_t indiceStart
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -59,9 +66,10 @@ namespace Dawn {
 | 
				
			|||||||
       * @param verticeStart Start vertice to buffer in to.
 | 
					       * @param verticeStart Start vertice to buffer in to.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      static void bufferCoordinates(
 | 
					      static void bufferCoordinates(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        glm::vec2 uv0, glm::vec2 uv1,
 | 
					        const glm::vec2 uv0,
 | 
				
			||||||
        int32_t verticeStart
 | 
					        const glm::vec2 uv1,
 | 
				
			||||||
 | 
					        const int32_t verticeStart
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -73,9 +81,10 @@ namespace Dawn {
 | 
				
			|||||||
       * @param verticeStart Start vertice to buffer to.
 | 
					       * @param verticeStart Start vertice to buffer to.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      static void bufferPositions(
 | 
					      static void bufferPositions(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        glm::vec2 xy0, glm::vec2 xy1,
 | 
					        const glm::vec2 xy0,
 | 
				
			||||||
        int32_t verticeStart
 | 
					        const glm::vec2 xy1,
 | 
				
			||||||
 | 
					        const int32_t verticeStart
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -89,10 +98,12 @@ namespace Dawn {
 | 
				
			|||||||
       * @param z The Z position of the coordinates.
 | 
					       * @param z The Z position of the coordinates.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      static void initQuadMesh(
 | 
					      static void initQuadMesh(
 | 
				
			||||||
        Mesh *mesh,
 | 
					        Mesh &mesh,
 | 
				
			||||||
        glm::vec2 xy0, glm::vec2 uv0,
 | 
					        const glm::vec2 xy0,
 | 
				
			||||||
        glm::vec2 xy1, glm::vec2 uv1,
 | 
					        const glm::vec2 uv0,
 | 
				
			||||||
        float_t z
 | 
					        const glm::vec2 xy1,
 | 
				
			||||||
 | 
					        const glm::vec2 uv1,
 | 
				
			||||||
 | 
					        const float_t z
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
// 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 {
 | 
					 | 
				
			||||||
  class Mesh;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -136,10 +136,11 @@ namespace Dawn {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return components;
 | 
					        return components;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Destroys a previously initialized Scene.
 | 
					       * Destroys a previously initialized Scene.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      ~Scene();
 | 
					      virtual ~Scene();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      friend class RenderPipeline;
 | 
					      friend class RenderPipeline;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,8 +10,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SceneItemComponent::SceneItemComponent(std::weak_ptr<SceneItem> item) {
 | 
					SceneItemComponent::SceneItemComponent(const std::weak_ptr<SceneItem> item) :
 | 
				
			||||||
  this->item = item;
 | 
					  item(item)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SceneItemComponent::init() {
 | 
					void SceneItemComponent::init() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ namespace Dawn {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  class SceneItemComponent : public StateOwner {
 | 
					  class SceneItemComponent : public StateOwner {
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
      std::weak_ptr<SceneItem> item;
 | 
					      const std::weak_ptr<SceneItem> item;
 | 
				
			||||||
      bool_t hasInitialized = false;
 | 
					      bool_t hasInitialized = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
@@ -70,6 +70,7 @@ namespace Dawn {
 | 
				
			|||||||
      virtual ~SceneItemComponent();
 | 
					      virtual ~SceneItemComponent();
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Fowarded methods
 | 
				
			||||||
  template<class T>
 | 
					  template<class T>
 | 
				
			||||||
  std::shared_ptr<T> _sceneForwardGetComponent(
 | 
					  std::shared_ptr<T> _sceneForwardGetComponent(
 | 
				
			||||||
    std::shared_ptr<SceneItem> item
 | 
					    std::shared_ptr<SceneItem> item
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,11 +32,11 @@ void SimpleRenderTargetQuad::onStart() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Update mesh
 | 
					    // Update mesh
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(
 | 
					    QuadMesh::bufferQuadMesh(
 | 
				
			||||||
      &this->meshHost->mesh,
 | 
					      this->meshHost->mesh,
 | 
				
			||||||
      glm::vec2(0, 0), glm::vec2(0, 0),
 | 
					      glm::vec2(0, 0), glm::vec2(0, 0),
 | 
				
			||||||
      glm::vec2(
 | 
					      glm::vec2(
 | 
				
			||||||
        ((RenderTarget*)this->renderTarget)->getWidth(),
 | 
					        this->renderTarget._realValue->getWidth(),
 | 
				
			||||||
        ((RenderTarget*)this->renderTarget)->getHeight()
 | 
					        this->renderTarget._realValue->getHeight()
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
      glm::vec2(1, 1),
 | 
					      glm::vec2(1, 1),
 | 
				
			||||||
      0, 0
 | 
					      0, 0
 | 
				
			||||||
@@ -49,7 +49,7 @@ void SimpleRenderTargetQuad::onStart() {
 | 
				
			|||||||
      const float_t h
 | 
					      const float_t h
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
      QuadMesh::bufferQuadMesh(
 | 
					      QuadMesh::bufferQuadMesh(
 | 
				
			||||||
        &this->meshHost->mesh,
 | 
					        this->meshHost->mesh,
 | 
				
			||||||
        glm::vec2(0, 0), glm::vec2(0, 0),
 | 
					        glm::vec2(0, 0), glm::vec2(0, 0),
 | 
				
			||||||
        glm::vec2(w, h), glm::vec2(1, 1),
 | 
					        glm::vec2(w, h), glm::vec2(1, 1),
 | 
				
			||||||
        0, 0
 | 
					        0, 0
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,6 @@ CapsuleMeshHost::CapsuleMeshHost(std::weak_ptr<SceneItem> item) :
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void CapsuleMeshHost::onStart() {
 | 
					void CapsuleMeshHost::onStart() {
 | 
				
			||||||
  useEffect([&]{
 | 
					  useEffect([&]{
 | 
				
			||||||
    CapsuleMesh::create(&this->mesh, radius, height);
 | 
					    CapsuleMesh::create(this->mesh, radius, height);
 | 
				
			||||||
  }, { &this->radius, &this->height })();
 | 
					  }, { &this->radius, &this->height })();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -20,6 +20,12 @@ void CubeMeshHost::onStart() {
 | 
				
			|||||||
  );
 | 
					  );
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  useEffect([&]{
 | 
					  useEffect([&]{
 | 
				
			||||||
    CubeMesh::buffer(&this->mesh, glm::vec3(this->size) * -0.5f, this->size, 0, 0);
 | 
					    CubeMesh::buffer(
 | 
				
			||||||
 | 
					      this->mesh,
 | 
				
			||||||
 | 
					      glm::vec3(this->size) * -0.5f,
 | 
				
			||||||
 | 
					      this->size,
 | 
				
			||||||
 | 
					      0,
 | 
				
			||||||
 | 
					      0
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
  }, this->size)();
 | 
					  }, this->size)();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -19,7 +19,7 @@ void QuadMeshHost::onStart() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  useEffect([&]{
 | 
					  useEffect([&]{
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(
 | 
					    QuadMesh::bufferQuadMesh(
 | 
				
			||||||
      &this->mesh,
 | 
					      this->mesh,
 | 
				
			||||||
      glm::vec2(this->xy0),
 | 
					      glm::vec2(this->xy0),
 | 
				
			||||||
      glm::vec2(this->uv0),
 | 
					      glm::vec2(this->uv0),
 | 
				
			||||||
      glm::vec2(this->xy1),
 | 
					      glm::vec2(this->xy1),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,13 @@ std::shared_ptr<SceneItem> ExampleSpin::create(Scene *scene) {
 | 
				
			|||||||
  auto mr = item->addComponent<MeshRenderer>();
 | 
					  auto mr = item->addComponent<MeshRenderer>();
 | 
				
			||||||
  mr->mesh = new Mesh();
 | 
					  mr->mesh = new Mesh();
 | 
				
			||||||
  mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
 | 
					  mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
 | 
				
			||||||
  CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
 | 
					  CubeMesh::buffer(
 | 
				
			||||||
 | 
					    *mr->mesh,
 | 
				
			||||||
 | 
					    glm::vec3(-0.5f, -0.5f, -0.5f),
 | 
				
			||||||
 | 
					    glm::vec3(1, 1, 1),
 | 
				
			||||||
 | 
					    0,
 | 
				
			||||||
 | 
					    0
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
  auto mat = item->addComponent<SimpleTexturedMaterial>();
 | 
					  auto mat = item->addComponent<SimpleTexturedMaterial>();
 | 
				
			||||||
  item->addComponent<ExampleSpin>();
 | 
					  item->addComponent<ExampleSpin>();
 | 
				
			||||||
  return item;
 | 
					  return item;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,49 +60,49 @@ void UIBorder::onStart() {
 | 
				
			|||||||
    glm::vec2 bSize = (glm::vec2)borderSize;
 | 
					    glm::vec2 bSize = (glm::vec2)borderSize;
 | 
				
			||||||
    glm::vec2 iSize = glm::vec2(this->getWidth(), this->getHeight()) - ( bSize * 2.0f );
 | 
					    glm::vec2 iSize = glm::vec2(this->getWidth(), this->getHeight()) - ( bSize * 2.0f );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(0, 0), glm::vec2(0, 0),
 | 
					      glm::vec2(0, 0), glm::vec2(0, 0),
 | 
				
			||||||
      bSize, tSize,
 | 
					      bSize, tSize,
 | 
				
			||||||
      0, 0
 | 
					      0, 0
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(bSize.x, 0), glm::vec2(tSize.x, 0),
 | 
					      glm::vec2(bSize.x, 0), glm::vec2(tSize.x, 0),
 | 
				
			||||||
      glm::vec2(iSize.x + bSize.x, bSize.y), glm::vec2(tSize.x * 2, tSize.y),
 | 
					      glm::vec2(iSize.x + bSize.x, bSize.y), glm::vec2(tSize.x * 2, tSize.y),
 | 
				
			||||||
      QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
 | 
					      QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(iSize.x + bSize.x, 0), glm::vec2(tSize.x + tSize.x, 0),
 | 
					      glm::vec2(iSize.x + bSize.x, 0), glm::vec2(tSize.x + tSize.x, 0),
 | 
				
			||||||
      glm::vec2(this->getWidth(), bSize.y), glm::vec2(1.0f, tSize.y),
 | 
					      glm::vec2(this->getWidth(), bSize.y), glm::vec2(1.0f, tSize.y),
 | 
				
			||||||
      2 * QUAD_VERTICE_COUNT, 2 * QUAD_INDICE_COUNT
 | 
					      2 * QUAD_VERTICE_COUNT, 2 * QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(0, bSize.y), glm::vec2(0, tSize.y),
 | 
					      glm::vec2(0, bSize.y), glm::vec2(0, tSize.y),
 | 
				
			||||||
      bSize + glm::vec2(0, iSize.y), tSize + glm::vec2(0, tSize.y),
 | 
					      bSize + glm::vec2(0, iSize.y), tSize + glm::vec2(0, tSize.y),
 | 
				
			||||||
      3 * QUAD_VERTICE_COUNT, 3 * QUAD_INDICE_COUNT
 | 
					      3 * QUAD_VERTICE_COUNT, 3 * QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      bSize, tSize,
 | 
					      bSize, tSize,
 | 
				
			||||||
      bSize + iSize, tSize + tSize,
 | 
					      bSize + iSize, tSize + tSize,
 | 
				
			||||||
      4 * QUAD_VERTICE_COUNT, 4 * QUAD_INDICE_COUNT
 | 
					      4 * QUAD_VERTICE_COUNT, 4 * QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(iSize.x + bSize.x, bSize.y), tSize + glm::vec2(tSize.x, 0),
 | 
					      glm::vec2(iSize.x + bSize.x, bSize.y), tSize + glm::vec2(tSize.x, 0),
 | 
				
			||||||
      glm::vec2(this->getWidth(), bSize.y + iSize.y), glm::vec2(1.0f, tSize.y + tSize.y),
 | 
					      glm::vec2(this->getWidth(), bSize.y + iSize.y), glm::vec2(1.0f, tSize.y + tSize.y),
 | 
				
			||||||
      5 * QUAD_VERTICE_COUNT, 5 * QUAD_INDICE_COUNT
 | 
					      5 * QUAD_VERTICE_COUNT, 5 * QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(0, iSize.y + bSize.y), glm::vec2(0, tSize.y + tSize.y),
 | 
					      glm::vec2(0, iSize.y + bSize.y), glm::vec2(0, tSize.y + tSize.y),
 | 
				
			||||||
      glm::vec2(bSize.x, this->getHeight()), glm::vec2(tSize.x, 1.0f),
 | 
					      glm::vec2(bSize.x, this->getHeight()), glm::vec2(tSize.x, 1.0f),
 | 
				
			||||||
      6 * QUAD_VERTICE_COUNT, 6 * QUAD_INDICE_COUNT
 | 
					      6 * QUAD_VERTICE_COUNT, 6 * QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      glm::vec2(bSize.x, iSize.y + bSize.y), glm::vec2(tSize.x, tSize.y + tSize.y),
 | 
					      glm::vec2(bSize.x, iSize.y + bSize.y), glm::vec2(tSize.x, tSize.y + tSize.y),
 | 
				
			||||||
      glm::vec2(iSize.x + bSize.x, this->getHeight()), glm::vec2(tSize.x * 2, 1.0f),
 | 
					      glm::vec2(iSize.x + bSize.x, this->getHeight()), glm::vec2(tSize.x * 2, 1.0f),
 | 
				
			||||||
      7 * QUAD_VERTICE_COUNT, 7 * QUAD_INDICE_COUNT
 | 
					      7 * QUAD_VERTICE_COUNT, 7 * QUAD_INDICE_COUNT
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    QuadMesh::bufferQuadMesh(&mesh,
 | 
					    QuadMesh::bufferQuadMesh(mesh,
 | 
				
			||||||
      bSize + iSize, tSize + tSize,
 | 
					      bSize + iSize, tSize + tSize,
 | 
				
			||||||
      glm::vec2(this->getWidth(), this->getHeight()), glm::vec2(1.0f, 1.0f),
 | 
					      glm::vec2(this->getWidth(), this->getHeight()), glm::vec2(1.0f, 1.0f),
 | 
				
			||||||
      8 * QUAD_VERTICE_COUNT, 8 * QUAD_INDICE_COUNT
 | 
					      8 * QUAD_VERTICE_COUNT, 8 * QUAD_INDICE_COUNT
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,21 +50,21 @@ void UIImage::onStart() {
 | 
				
			|||||||
  UIComponent::onStart();
 | 
					  UIComponent::onStart();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  useEvent([&]{
 | 
					  useEvent([&]{
 | 
				
			||||||
    QuadMesh::bufferPositions(&mesh,
 | 
					    QuadMesh::bufferPositions(mesh,
 | 
				
			||||||
      glm::vec2(0, 0),
 | 
					      glm::vec2(0, 0),
 | 
				
			||||||
      glm::vec2(width, height), 0
 | 
					      glm::vec2(width, height), 0
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }, this->eventAlignmentUpdated);
 | 
					  }, this->eventAlignmentUpdated);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  useEffect([&]{
 | 
					  useEffect([&]{
 | 
				
			||||||
    QuadMesh::bufferCoordinates(&mesh, 
 | 
					    QuadMesh::bufferCoordinates(mesh, 
 | 
				
			||||||
      glm::vec2(this->uvs._realValue[0], this->uvs._realValue[1]),
 | 
					      glm::vec2(this->uvs._realValue[0], this->uvs._realValue[1]),
 | 
				
			||||||
      glm::vec2(this->uvs._realValue[2], this->uvs._realValue[3]),
 | 
					      glm::vec2(this->uvs._realValue[2], this->uvs._realValue[3]),
 | 
				
			||||||
      0
 | 
					      0
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }, this->uvs);
 | 
					  }, this->uvs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QuadMesh::initQuadMesh(&mesh, 
 | 
					  QuadMesh::initQuadMesh(mesh, 
 | 
				
			||||||
    glm::vec2(0, 0), glm::vec2(this->uvs._realValue[0], this->uvs._realValue[1]),
 | 
					    glm::vec2(0, 0), glm::vec2(this->uvs._realValue[0], this->uvs._realValue[1]),
 | 
				
			||||||
    glm::vec2(width, height), glm::vec2(this->uvs._realValue[2], this->uvs._realValue[3]),
 | 
					    glm::vec2(width, height), glm::vec2(this->uvs._realValue[2], this->uvs._realValue[3]),
 | 
				
			||||||
    0.0f
 | 
					    0.0f
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -441,7 +441,7 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
 | 
				
			|||||||
    auto vert = itQuad->first;
 | 
					    auto vert = itQuad->first;
 | 
				
			||||||
    auto uvs = itQuad->second;
 | 
					    auto uvs = itQuad->second;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QuadMesh::bufferQuadMeshWithZ(&this->mesh,
 | 
					    QuadMesh::bufferQuadMeshWithZ(this->mesh,
 | 
				
			||||||
      glm::vec2(vert.x, vert.y), glm::vec2(uvs.x, uvs.y),
 | 
					      glm::vec2(vert.x, vert.y), glm::vec2(uvs.x, uvs.y),
 | 
				
			||||||
      glm::vec2(vert.w, vert.z), glm::vec2(uvs.w, uvs.z),
 | 
					      glm::vec2(vert.w, vert.z), glm::vec2(uvs.w, uvs.z),
 | 
				
			||||||
      0.0f,
 | 
					      0.0f,
 | 
				
			||||||
@@ -459,7 +459,7 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
 | 
				
			|||||||
      auto vert = itQuad->first;
 | 
					      auto vert = itQuad->first;
 | 
				
			||||||
      auto uvs = itQuad->second;
 | 
					      auto uvs = itQuad->second;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      QuadMesh::bufferQuadMeshWithZ(&this->meshDecorations,
 | 
					      QuadMesh::bufferQuadMeshWithZ(this->meshDecorations,
 | 
				
			||||||
        glm::vec2(vert.x, vert.y), glm::vec2(uvs.x, uvs.y),
 | 
					        glm::vec2(vert.x, vert.y), glm::vec2(uvs.x, uvs.y),
 | 
				
			||||||
        glm::vec2(vert.w, vert.z), glm::vec2(uvs.w, uvs.z),
 | 
					        glm::vec2(vert.w, vert.z), glm::vec2(uvs.w, uvs.z),
 | 
				
			||||||
        0.0f,
 | 
					        0.0f,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BackBufferRenderTarget::BackBufferRenderTarget(RenderManager &renderManager) :
 | 
					BackBufferRenderTarget::BackBufferRenderTarget() {
 | 
				
			||||||
  renderManager(renderManager)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float_t BackBufferRenderTarget::getScale() {
 | 
					float_t BackBufferRenderTarget::getScale() {
 | 
				
			||||||
@@ -24,23 +22,23 @@ float_t BackBufferRenderTarget::getHeight() {
 | 
				
			|||||||
  return this->height;
 | 
					  return this->height;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BackBufferRenderTarget::setSize(float_t width, float_t height) {
 | 
					void BackBufferRenderTarget::setSize(
 | 
				
			||||||
 | 
					  const float_t width,
 | 
				
			||||||
 | 
					  const float_t height
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  if(this->width == width && this->height == height) return;
 | 
					  if(this->width == width && this->height == height) return;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  // Fixes a new bug that it seems GLFW has introduced.
 | 
					  // Fixes a new bug that it seems GLFW has introduced.
 | 
				
			||||||
  if(width == 0) width = 1;
 | 
					  this->width = width == 0 ? 1 : width;
 | 
				
			||||||
  if(height == 0) height = 1;
 | 
					  this->height = height == 0 ? 1 : height;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  this->width = width;
 | 
					 | 
				
			||||||
  this->height = height;
 | 
					 | 
				
			||||||
  this->eventRenderTargetResized.invoke(*this, width, height);
 | 
					  this->eventRenderTargetResized.invoke(*this, width, height);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BackBufferRenderTarget::setClearColor(struct Color color) {
 | 
					void BackBufferRenderTarget::setClearColor(const struct Color color) {
 | 
				
			||||||
  this->clearColor = color;
 | 
					  this->clearColor = color;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BackBufferRenderTarget::clear(flag8_t clearFlags) {
 | 
					void BackBufferRenderTarget::clear(const flag8_t clearFlags) {
 | 
				
			||||||
  glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
 | 
					  glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
					  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,6 @@ namespace Dawn {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  class BackBufferRenderTarget : public RenderTarget {
 | 
					  class BackBufferRenderTarget : public RenderTarget {
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
      RenderManager &renderManager;
 | 
					 | 
				
			||||||
      float_t width = 1;
 | 
					      float_t width = 1;
 | 
				
			||||||
      float_t height = 1; 
 | 
					      float_t height = 1; 
 | 
				
			||||||
      struct Color clearColor = COLOR_CORNFLOWER_BLUE;
 | 
					      struct Color clearColor = COLOR_CORNFLOWER_BLUE;
 | 
				
			||||||
@@ -23,10 +22,8 @@ namespace Dawn {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Construct the back buffer render target.
 | 
					       * Construct the back buffer render target.
 | 
				
			||||||
       * 
 | 
					 | 
				
			||||||
       * @param renderManager Render Manager for this back buffer target.
 | 
					 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      BackBufferRenderTarget(RenderManager &renderManager);
 | 
					      BackBufferRenderTarget();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Requests to modify the viewport directly. This is mostly to be called
 | 
					       * Requests to modify the viewport directly. This is mostly to be called
 | 
				
			||||||
@@ -38,13 +35,13 @@ namespace Dawn {
 | 
				
			|||||||
       * @param width New width of the back buffer.
 | 
					       * @param width New width of the back buffer.
 | 
				
			||||||
       * @param height New height of the back buffer.
 | 
					       * @param height New height of the back buffer.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      void setSize(float_t width, float_t height);
 | 
					      void setSize(const float_t width, const float_t height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      float_t getScale() override;
 | 
					      float_t getScale() override;
 | 
				
			||||||
      float_t getWidth() override;
 | 
					      float_t getWidth() override;
 | 
				
			||||||
      float_t getHeight() override;
 | 
					      float_t getHeight() override;
 | 
				
			||||||
      void setClearColor(struct Color color) override;
 | 
					      void setClearColor(const struct Color color) override;
 | 
				
			||||||
      void clear(flag8_t clearFlags) override;
 | 
					      void clear(const flag8_t clearFlags) override;
 | 
				
			||||||
      void bind() override;
 | 
					      void bind() override;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -13,7 +13,7 @@ using namespace Dawn;
 | 
				
			|||||||
RenderManager::RenderManager() : IRenderManager() {
 | 
					RenderManager::RenderManager() : IRenderManager() {
 | 
				
			||||||
  renderPipeline = std::make_shared<RenderPipeline>();
 | 
					  renderPipeline = std::make_shared<RenderPipeline>();
 | 
				
			||||||
  shaderManager = std::make_shared<ShaderManager>();
 | 
					  shaderManager = std::make_shared<ShaderManager>();
 | 
				
			||||||
  backBuffer = std::make_shared<BackBufferRenderTarget>(*this);
 | 
					  backBuffer = std::make_shared<BackBufferRenderTarget>();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void RenderManager::init(const std::weak_ptr<DawnGame> game) {
 | 
					void RenderManager::init(const std::weak_ptr<DawnGame> game) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,12 +8,16 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
using namespace Dawn;
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TextureRenderTarget::TextureRenderTarget(float_t width, float_t height) {
 | 
					TextureRenderTarget::TextureRenderTarget(
 | 
				
			||||||
 | 
					  const float_t width,
 | 
				
			||||||
 | 
					  const float_t height
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
 | 
					  this->texture = std::make_shared<Texture>();
 | 
				
			||||||
  this->setSize(width, height);
 | 
					  this->setSize(width, height);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Texture * TextureRenderTarget::getTexture() {
 | 
					std::shared_ptr<Texture> TextureRenderTarget::getTexture() {
 | 
				
			||||||
  return &this->texture;
 | 
					  return this->texture;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TextureRenderTarget::setSize(float_t width, float_t height) {
 | 
					void TextureRenderTarget::setSize(float_t width, float_t height) {
 | 
				
			||||||
@@ -29,7 +33,12 @@ void TextureRenderTarget::setSize(float_t width, float_t height) {
 | 
				
			|||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Resize texture
 | 
					  // Resize texture
 | 
				
			||||||
  this->texture.setSize((int32_t)width, (int32_t)height, TEXTURE_FORMAT_RGBA, TEXTURE_DATA_FORMAT_FLOAT);
 | 
					  this->texture->setSize(
 | 
				
			||||||
 | 
					    (int32_t)width,
 | 
				
			||||||
 | 
					    (int32_t)height,
 | 
				
			||||||
 | 
					    TEXTURE_FORMAT_RGBA,
 | 
				
			||||||
 | 
					    TEXTURE_DATA_FORMAT_FLOAT
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
  this->eventRenderTargetResized.invoke(*this, width, height);
 | 
					  this->eventRenderTargetResized.invoke(*this, width, height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Create Frame Buffer
 | 
					  // Create Frame Buffer
 | 
				
			||||||
@@ -38,7 +47,7 @@ void TextureRenderTarget::setSize(float_t width, float_t height) {
 | 
				
			|||||||
  glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
 | 
					  glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
 | 
					  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
 | 
				
			||||||
    GL_TEXTURE_2D, this->texture.id, 0
 | 
					    GL_TEXTURE_2D, this->texture->id, 0
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,14 +57,19 @@ void TextureRenderTarget::setSize(float_t width, float_t height) {
 | 
				
			|||||||
  glBindRenderbuffer(GL_RENDERBUFFER, this->rboId); 
 | 
					  glBindRenderbuffer(GL_RENDERBUFFER, this->rboId); 
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
  glRenderbufferStorage(
 | 
					  glRenderbufferStorage(
 | 
				
			||||||
    GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
 | 
					    GL_RENDERBUFFER,
 | 
				
			||||||
    this->texture.width, this->texture.height
 | 
					    GL_DEPTH24_STENCIL8,
 | 
				
			||||||
 | 
					    this->texture->width,
 | 
				
			||||||
 | 
					    this->texture->height
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
  glBindRenderbuffer(GL_RENDERBUFFER, 0);
 | 
					  glBindRenderbuffer(GL_RENDERBUFFER, 0);
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
 | 
					  glFramebufferRenderbuffer(
 | 
				
			||||||
    GL_RENDERBUFFER, this->rboId
 | 
					    GL_FRAMEBUFFER,
 | 
				
			||||||
 | 
					    GL_DEPTH_STENCIL_ATTACHMENT,
 | 
				
			||||||
 | 
					    GL_RENDERBUFFER,
 | 
				
			||||||
 | 
					    this->rboId
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  assertNoGLError();
 | 
					  assertNoGLError();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,18 +84,18 @@ float_t TextureRenderTarget::getScale() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float_t TextureRenderTarget::getWidth() {
 | 
					float_t TextureRenderTarget::getWidth() {
 | 
				
			||||||
  return (float_t)this->texture.getWidth();
 | 
					  return (float_t)this->texture->getWidth();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float_t TextureRenderTarget::getHeight() {
 | 
					float_t TextureRenderTarget::getHeight() {
 | 
				
			||||||
  return (float_t)this->texture.getHeight();
 | 
					  return (float_t)this->texture->getHeight();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TextureRenderTarget::setClearColor(struct Color color) {
 | 
					void TextureRenderTarget::setClearColor(const struct Color color) {
 | 
				
			||||||
  this->clearColor = color;
 | 
					  this->clearColor = color;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TextureRenderTarget::clear(flag8_t clearFlags) {
 | 
					void TextureRenderTarget::clear(const flag8_t clearFlags) {
 | 
				
			||||||
  glClearColor(
 | 
					  glClearColor(
 | 
				
			||||||
    clearColor.r,
 | 
					    clearColor.r,
 | 
				
			||||||
    clearColor.g,
 | 
					    clearColor.g,
 | 
				
			||||||
@@ -93,7 +107,7 @@ void TextureRenderTarget::clear(flag8_t clearFlags) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void TextureRenderTarget::bind() {
 | 
					void TextureRenderTarget::bind() {
 | 
				
			||||||
  glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
 | 
					  glBindFramebuffer(GL_FRAMEBUFFER, this->fboId);
 | 
				
			||||||
  glViewport(0, 0, this->texture.getWidth(), this->texture.getHeight());
 | 
					  glViewport(0, 0, this->texture->getWidth(), this->texture->getHeight());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TextureRenderTarget::~TextureRenderTarget() {
 | 
					TextureRenderTarget::~TextureRenderTarget() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,21 +16,21 @@ namespace Dawn {
 | 
				
			|||||||
      GLuint fboId = -1;
 | 
					      GLuint fboId = -1;
 | 
				
			||||||
      GLuint rboId = -1;
 | 
					      GLuint rboId = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      Texture texture;
 | 
					      std::shared_ptr<Texture> texture;
 | 
				
			||||||
      struct Color clearColor = COLOR_CORNFLOWER_BLUE;
 | 
					      struct Color clearColor = COLOR_CORNFLOWER_BLUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
      TextureRenderTarget(float_t width, float_t height);
 | 
					      TextureRenderTarget(const float_t width, const float_t height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      Texture * getTexture();
 | 
					      std::shared_ptr<Texture> getTexture();
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      void setSize(float_t width, float_t height);
 | 
					      void setSize(const float_t width, const float_t height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      float_t getScale() override;
 | 
					      float_t getScale() override;
 | 
				
			||||||
      float_t getWidth() override;
 | 
					      float_t getWidth() override;
 | 
				
			||||||
      float_t getHeight() override;
 | 
					      float_t getHeight() override;
 | 
				
			||||||
      void setClearColor(struct Color color) override;
 | 
					      void setClearColor(const struct Color color) override;
 | 
				
			||||||
      void clear(flag8_t clearFlags) override;
 | 
					      void clear(const flag8_t clearFlags) override;
 | 
				
			||||||
      void bind() override;
 | 
					      void bind() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ~TextureRenderTarget();
 | 
					      ~TextureRenderTarget();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "assert/assertgl.hpp"
 | 
					#include "assert/assertgl.hpp"
 | 
				
			||||||
#include "display/mesh/_Mesh.hpp"
 | 
					 | 
				
			||||||
#include "dawnopengl.hpp"
 | 
					#include "dawnopengl.hpp"
 | 
				
			||||||
#include "assert/assert.hpp"
 | 
					#include "assert/assert.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user