-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified PixelRenderer to work with new Texture <=> Buffer interface
- Loading branch information
Showing
6 changed files
with
156 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,86 @@ | ||
// #include "PixelRenderer.hpp" | ||
// | ||
// namespace Engine | ||
// { | ||
// // ----- Public ----- | ||
// | ||
// PixelRenderer::PixelRenderer | ||
// ( | ||
// const uint32 width, | ||
// const uint32 height, | ||
// const uint32 pxSize, | ||
// const std::string& bgTexture, | ||
// const std::string& shader | ||
// ) | ||
// : _width(width), _height(height), _pxSize(pxSize), | ||
// _canvasSprite(ResourceManager::GetTexture(bgTexture), | ||
// ResourceManager::GetShader(shader), | ||
// COLOR_WHITE, | ||
// glm::vec2(_width * _pxSize, _height * _pxSize)) | ||
// { | ||
// Logger::Info("Created", "Renderer", __func__); | ||
// } | ||
// | ||
// void PixelRenderer::Flush(Renderer* renderer) | ||
// { | ||
// //Commit texture changes | ||
// _canvasSprite.GetTexture()->CommitModifications(); | ||
// | ||
// //Render sprite | ||
// RenderStatistics::drawnVertices += _canvasSprite.Draw(); | ||
// RenderStatistics::drawCalls++; | ||
// | ||
// //Increase render pass counter | ||
// RenderStatistics::spritePasses++; | ||
// } | ||
// | ||
// void PixelRenderer::Set(const uint32 x, const uint32 y, const glm::vec3& color) const | ||
// { | ||
// const uint32 x_end = x * _pxSize; | ||
// const uint32 y_end = y * _pxSize; | ||
// const uint32 x_start = x_end - _pxSize; | ||
// const uint32 y_start = y_end - _pxSize; | ||
// | ||
// SetArea(x_start, x_end, y_start, y_end, color); | ||
// } | ||
// | ||
// void PixelRenderer::SetArea(const uint32 x_start, const uint32 x_end, const uint32 y_start, const uint32 y_end, const glm::vec3& color) const | ||
// { | ||
// for(uint32 x = x_start; x < x_end; x++) | ||
// { | ||
// for(uint32 y = y_start; y < y_end; y++) | ||
// { | ||
// _canvasSprite.GetTexture()->ModifyTexture(x, y, color); | ||
// } | ||
// } | ||
// } | ||
// | ||
// void PixelRenderer::ResetArea(const uint32 x_start, const uint32 x_end, const uint32 y_start, const uint32 y_end) const | ||
// { | ||
// for(uint32 x = x_start; x < x_end; x++) | ||
// { | ||
// for(uint32 y = y_start; y < y_end; y++) | ||
// { | ||
// _canvasSprite.GetTexture()->ResetTextureModification(x, y); | ||
// } | ||
// } | ||
// } | ||
// | ||
// void PixelRenderer::SetScreen(const glm::vec3& color) const | ||
// { | ||
// SetArea(0, _width * _pxSize, 0, _height * _pxSize, color); | ||
// } | ||
// | ||
// void PixelRenderer::ClearScreen() const | ||
// { | ||
// ResetArea(0, _width * _pxSize, 0, _height * _pxSize); | ||
// } | ||
// } | ||
#include "PixelRenderer.hpp" | ||
|
||
namespace Engine | ||
{ | ||
// ----- Public ----- | ||
|
||
PixelRenderer::PixelRenderer | ||
( | ||
const uint32 width, | ||
const uint32 height, | ||
const uint32 pxSize, | ||
const std::string& bgTexture, | ||
const std::string& shader | ||
) | ||
: _width(width), _height(height), _pxSize(pxSize), | ||
_canvasSprite(ResourceManager::GetGLTexture(bgTexture), | ||
ResourceManager::GetShader(shader), | ||
COLOR_WHITE, | ||
glm::vec2(_width * _pxSize, _height * _pxSize)) | ||
{ | ||
Logger::Info("Created", "Renderer", __func__); | ||
} | ||
|
||
void PixelRenderer::Flush(Renderer* renderer) | ||
{ | ||
//Commit texture changes | ||
_canvasSprite.GetGLTexture()->UploadModifiedBuffer(); | ||
|
||
//Render sprite | ||
RenderStatistics::drawnVertices += _canvasSprite.Draw(); | ||
RenderStatistics::drawCalls++; | ||
|
||
//Increase render pass counter | ||
RenderStatistics::spritePasses++; | ||
} | ||
|
||
void PixelRenderer::Set(const uint32 x, const uint32 y, const PxColor& colorIn) const | ||
{ | ||
const uint32 x_end = x * _pxSize; | ||
const uint32 y_end = y * _pxSize; | ||
const uint32 x_start = x_end - _pxSize; | ||
const uint32 y_start = y_end - _pxSize; | ||
|
||
SetArea(x_start, x_end, y_start, y_end, colorIn); | ||
} | ||
|
||
void PixelRenderer::SetArea(const uint32 x_start, const uint32 x_end, const uint32 y_start, const uint32 y_end, const PxColor& colorIn) const | ||
{ | ||
for(uint32 x = x_start; x < x_end; x++) | ||
{ | ||
for(uint32 y = y_start; y < y_end; y++) | ||
{ | ||
//Modify texture buffer and break/quit if something goes wrong | ||
if(_canvasSprite.GetGLTexture()->GetTextureBuffer()->SetPxColor(x, y, colorIn) == false) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void PixelRenderer::ResetArea(const uint32 x_start, const uint32 x_end, const uint32 y_start, const uint32 y_end) const | ||
{ | ||
for(uint32 x = x_start; x < x_end; x++) | ||
{ | ||
for(uint32 y = y_start; y < y_end; y++) | ||
{ | ||
//Reset texture buffer back to the default values and break/quit if something goes wrong | ||
if(_canvasSprite.GetGLTexture()->GetTextureBuffer()->ResetPxColor(x, y)) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void PixelRenderer::SetScreen(const PxColor& colorIn) const | ||
{ | ||
SetArea(0, _width * _pxSize, 0, _height * _pxSize, colorIn); | ||
} | ||
|
||
void PixelRenderer::ClearScreen() const | ||
{ | ||
ResetArea(0, _width * _pxSize, 0, _height * _pxSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
// #pragma once | ||
// | ||
// #include "Renderer.hpp" | ||
// #include "glm.hpp" | ||
// #include "Sprite.hpp" | ||
// #include "Texture.hpp" | ||
// #include "Shader.hpp" | ||
// #include "GLRenderSettings.hpp" | ||
// #include "GlobalParams.hpp" | ||
// #include "ResourceManager.hpp" | ||
// | ||
// namespace Engine | ||
// { | ||
// class PixelRenderer final : public Renderer | ||
// { | ||
// private: | ||
// uint32 _width, _height, _pxSize; | ||
// Sprite _canvasSprite; | ||
// | ||
// public: | ||
// PixelRenderer | ||
// ( | ||
// uint32 width, | ||
// uint32 height, | ||
// uint32 pxSize, | ||
// const std::string& bgTexture, | ||
// const std::string& shader | ||
// ); | ||
// | ||
// void Flush(Renderer* renderer) override; | ||
// void Set(uint32 x, uint32 y, const glm::vec3& color) const; | ||
// void SetArea(uint32 x_start, uint32 x_end, uint32 y_start, uint32 y_end, const glm::vec3& color) const; | ||
// void ResetArea(uint32 x_start, uint32 x_end, uint32 y_start, uint32 y_end) const; | ||
// void SetScreen(const glm::vec3& color) const; | ||
// void ClearScreen() const; | ||
// }; | ||
// } | ||
#pragma once | ||
|
||
#include "Renderer.hpp" | ||
#include "glm.hpp" | ||
#include "Sprite.hpp" | ||
#include "GLTexture.hpp" | ||
#include "Shader.hpp" | ||
#include "GLRenderSettings.hpp" | ||
#include "GlobalParams.hpp" | ||
#include "ResourceManager.hpp" | ||
|
||
namespace Engine | ||
{ | ||
class PixelRenderer final : public Renderer | ||
{ | ||
private: | ||
uint32 _width, _height, _pxSize; | ||
Sprite _canvasSprite; | ||
|
||
public: | ||
PixelRenderer | ||
( | ||
uint32 width, | ||
uint32 height, | ||
uint32 pxSize, | ||
const std::string& bgTexture, | ||
const std::string& shader | ||
); | ||
|
||
void Flush(Renderer* renderer) override; | ||
void Set(uint32 x, uint32 y, const PxColor& colorIn) const; | ||
void SetArea(uint32 x_start, uint32 x_end, uint32 y_start, uint32 y_end, const PxColor& colorIn) const; | ||
void ResetArea(uint32 x_start, uint32 x_end, uint32 y_start, uint32 y_end) const; | ||
void SetScreen(const PxColor& colorIn) const; | ||
void ClearScreen() const; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters