dynamic renderer seems to work but have some resize/ratio issues

This commit is contained in:
Clément Le Bihan
2021-07-26 16:32:46 +02:00
parent 87aabbfce4
commit 620ccb3e80
4 changed files with 27 additions and 19 deletions
@@ -20,15 +20,9 @@ namespace ComSquare::Debugger
void prepVector(std::vector<std::vector<uint32_t>> &vector, int nbColumns) void prepVector(std::vector<std::vector<uint32_t>> &vector, int nbColumns)
{ {
std::vector<std::vector<uint32_t>> vec(1 * PPU::Tile::NbPixelsHeight, std::vector<uint32_t>(nbColumns * PPU::Tile::NbPixelsWidth, 0)); std::vector<std::vector<uint32_t>> vec(1 * PPU::Tile::NbPixelsHeight,
std::vector<uint32_t>(nbColumns * PPU::Tile::NbPixelsWidth, 0));
vector = vec; vector = vec;
return;
std::vector<uint32_t> pixelLine(static_cast<unsigned int>(nbColumns), 0);
vector.reserve(8);
for (int i = 0; i < 8; i++) {
vector.push_back(pixelLine);
}
} }
void RAMTileRenderer::render() void RAMTileRenderer::render()
+19 -7
View File
@@ -16,11 +16,12 @@
namespace ComSquare::Debugger namespace ComSquare::Debugger
{ {
TileViewer::TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu) TileViewer::TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu)
:_window(new ClosableWindow([&snes] { snes.disableTileViewer(); })), : _window(new ClosableWindow([&snes] { snes.disableTileViewer(); })),
_snes(snes), _snes(snes),
_ui(), _ui(),
_ppu(ppu), _ppu(ppu),
_ramTileRenderer(ppu.vram, ppu.cgram) _ramTileRenderer(ppu.vram, ppu.cgram),
_currentRendererSize(0, 0)
{ {
this->_ui.setupUi(this->_window); this->_ui.setupUi(this->_window);
//this->_qtSfmlRenderer(this->_ui.widget_sfml, 30); //this->_qtSfmlRenderer(this->_ui.widget_sfml, 30);
@@ -114,14 +115,25 @@ namespace ComSquare::Debugger
void TileViewer::internalUpdate() void TileViewer::internalUpdate()
{ {
this->_ramTileRenderer.render(); this->_ramTileRenderer.render();
if (this->_ramTileRenderer.buffer.size() != this->_currentRendererSize.y
|| this->_ramTileRenderer.buffer.at(0).size() != this->_currentRendererSize.x) {
if (this->_ramTileRenderer.buffer.size() == 0 || this->_ramTileRenderer.buffer.at(0).size() == 0)
return;
this->_currentRendererSize = {static_cast<unsigned int>(this->_ramTileRenderer.buffer.at(0).size()), static_cast<unsigned int>(this->_ramTileRenderer.buffer.size())};
this->_renderer->setSize(this->_currentRendererSize.x, this->_currentRendererSize.y);
}
int i = 0; int i = 0;
int j = 0; int j = 0;
for (const auto &row : this->_ramTileRenderer.buffer) { try {
for (const auto &pixel : row) { for (const auto &row : this->_ramTileRenderer.buffer) {
this->_renderer->putPixel(i, j++, pixel); for (const auto &pixel : row) {
this->_renderer->putPixel(i, j++, pixel);
}
j = 0;
i++;
} }
j = 0; } catch (const std::exception &e) {
i++; std::cout << "cc" << std::endl;
} }
} }
@@ -40,6 +40,8 @@ namespace ComSquare::Debugger
//! @brief Change the bpp from the index given by the ui (QT combo box) //! @brief Change the bpp from the index given by the ui (QT combo box)
void _bppChangeUIHandler(int index); void _bppChangeUIHandler(int index);
Vector2<unsigned> _currentRendererSize;
public: public:
//! @brief ctor //! @brief ctor
explicit TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu); explicit TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu);
+4 -4
View File
@@ -61,10 +61,10 @@ namespace ComSquare::Renderer
void SFRenderer::putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) void SFRenderer::putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba)
{ {
if (verticalPosition >= this->_videoMode.width) if (horizontalPosition >= this->_videoMode.width)
throw InvalidPixelPosition("Width", verticalPosition, this->_videoMode.width); throw InvalidPixelPosition("Width", horizontalPosition, this->_videoMode.width);
if (horizontalPosition >= this->_videoMode.height) if (verticalPosition >= this->_videoMode.height)
throw InvalidPixelPosition("Height", horizontalPosition, this->_videoMode.height); throw InvalidPixelPosition("Height", verticalPosition, this->_videoMode.height);
this->_pixelBuffer[this->_videoMode.width * verticalPosition + horizontalPosition] = sf::Color(rgba); this->_pixelBuffer[this->_videoMode.width * verticalPosition + horizontalPosition] = sf::Color(rgba);
} }