mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-28 00:31:38 +00:00
wip: trying to correctly resize renderer during tileviewer use
This commit is contained in:
@@ -15,7 +15,7 @@ namespace ComSquare::Debugger
|
||||
_ramOffset(0),
|
||||
_bpp(2),
|
||||
_tileRenderer(ram, cgram),
|
||||
buffer({{{0}}})
|
||||
buffer({{0}})
|
||||
{}
|
||||
|
||||
void RAMTileRenderer::render()
|
||||
@@ -24,8 +24,8 @@ namespace ComSquare::Debugger
|
||||
int bufY = 0;
|
||||
int nbTilesDrawn = 0;
|
||||
int resetX = bufX;
|
||||
for (auto &i : this->buffer)
|
||||
i.fill(0);
|
||||
//for (auto &i : this->buffer)
|
||||
// i.fill(0);
|
||||
uint24_t limit = std::fmin(this->_ram.getSize(), this->_renderSize) + this->_ramOffset;
|
||||
|
||||
for (uint24_t i = this->_ramOffset; i < limit; i += PPU::Tile::BaseByteSize * this->_bpp, nbTilesDrawn++) {
|
||||
@@ -47,7 +47,7 @@ namespace ComSquare::Debugger
|
||||
|
||||
for (const auto &raw : this->_tileRenderer.buffer) {
|
||||
for (const auto &pixel : raw) {
|
||||
buffer[bufX++][bufY] = pixel;
|
||||
this->buffer[bufX++][bufY] = pixel;
|
||||
}
|
||||
bufY++;
|
||||
bufX = resetX;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include "PPU/TileRenderer.hpp"
|
||||
#include "Ram/Ram.hpp"
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ComSquare::Debugger
|
||||
PPU::TileRenderer _tileRenderer;
|
||||
public:
|
||||
//! @brief internal buffer
|
||||
std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
||||
std::vector<std::vector<uint32_t>> buffer;
|
||||
//! @brief Set the palette to use for render (index of palette)
|
||||
void setPaletteIndex(int paletteIndex);
|
||||
//! @brief Set the bpp to render graphics
|
||||
|
||||
@@ -11,18 +11,21 @@
|
||||
#include <iostream>
|
||||
#include "RAMTileRenderer.hpp"
|
||||
#include "PPU/PPU.hpp"
|
||||
#include "PPU/Tile.hpp"
|
||||
|
||||
namespace ComSquare::Debugger
|
||||
{
|
||||
TileViewer::TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu)
|
||||
: _window(new ClosableWindow([&snes] { snes.disableTileViewer(); })),
|
||||
:_window(new ClosableWindow([&snes] { snes.disableTileViewer(); })),
|
||||
_snes(snes),
|
||||
_ui(),
|
||||
_ppu(ppu),
|
||||
_ramTileRenderer(ppu.vram, ppu.cgram)
|
||||
{
|
||||
this->_ui.setupUi(this->_window);
|
||||
this->_sfWidget = std::make_unique<Renderer::QtSFMLTileRenderer>(this->_ui.widget_sfml);
|
||||
this->_qtSfmlRenderer(this->_ui.widget_sfml, 30);
|
||||
this->_renderer = this->_qtSfmlRenderer;
|
||||
// this->_sfWidget = std::make_unique<Renderer::QtSFMLTileRenderer>(this->_ui.widget_sfml);
|
||||
QMainWindow::connect(this->_ui.NbColumns, QOverload<int>::of(&QSpinBox::valueChanged), this,
|
||||
[this](int nb) -> void { this->setNbColumns(nb); });
|
||||
QMainWindow::connect(this->_ui.ByteSize, QOverload<int>::of(&QSpinBox::valueChanged), this,
|
||||
@@ -109,7 +112,15 @@ namespace ComSquare::Debugger
|
||||
void TileViewer::internalUpdate()
|
||||
{
|
||||
this->_ramTileRenderer.render();
|
||||
this->_sfWidget->buffer = this->_ramTileRenderer.buffer;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (const auto &row : this->_ramTileRenderer.buffer) {
|
||||
for (const auto &pixel : row) {
|
||||
this->_renderer.putPixel(j++, i, pixel);
|
||||
}
|
||||
j = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void TileViewer::setRamOffset(int offset)
|
||||
|
||||
@@ -31,11 +31,16 @@ namespace ComSquare::Debugger
|
||||
//! @brief A reference to the ppu
|
||||
ComSquare::PPU::PPU &_ppu;
|
||||
//! @brief the window
|
||||
std::unique_ptr<Renderer::QtSFMLTileRenderer> _sfWidget;
|
||||
//std::unique_ptr<Renderer::QtSFMLTileRenderer> _sfWidget;
|
||||
//! @brief The ram tile renderer
|
||||
RAMTileRenderer _ramTileRenderer;
|
||||
//! @brief The instantiation of the renderer (should be passed via argument)
|
||||
Renderer::QtWidgetSFML _qtSfmlRenderer;
|
||||
//! @brief Renderer used to display tiles
|
||||
Renderer::IRenderer &_renderer;
|
||||
//! @brief Change the bpp from the index given by the ui (QT combo box)
|
||||
void _bppChangeUIHandler(int index);
|
||||
|
||||
public:
|
||||
//! @brief ctor
|
||||
explicit TileViewer(SNES &snes, ComSquare::PPU::PPU &ppu);
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ namespace ComSquare::PPU
|
||||
{
|
||||
this->_registers._isLowByte = true;
|
||||
|
||||
//Utils::Debug::populateEnvironment(*this, 1);
|
||||
Utils::Debug::populateEnvironment(*this, 1);
|
||||
}
|
||||
|
||||
uint8_t PPU::read(uint24_t addr)
|
||||
|
||||
@@ -75,7 +75,6 @@ namespace ComSquare::PPU
|
||||
|
||||
uint8_t TileRenderer::getPixelReferenceFromTileRow(uint16_t tileRowAddress, uint8_t pixelIndex)
|
||||
{
|
||||
// TODO unit test this
|
||||
uint16_t result = 0;
|
||||
|
||||
switch (this->_bpp) {
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace ComSquare
|
||||
//! @brief Render the buffer to the window
|
||||
virtual void drawScreen() = 0;
|
||||
|
||||
//! @brief Set a size or resize the Renderer drawing size
|
||||
//! @param height The new height of the renderer in pixels
|
||||
//! @param width The new width of the renderer in pixels
|
||||
virtual void setSize(unsigned width, unsigned height) = 0;
|
||||
|
||||
//! @brief Set a pixel to the coordinates x, y with the color rgba
|
||||
//! @param x The x position of the window (0, 0 is the top left corner).
|
||||
//! @param y The y position of the window (0, 0 is the top left corner).
|
||||
|
||||
@@ -2,26 +2,31 @@
|
||||
// Created by cbihan on 08/06/2021.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "PPU/Tile.hpp"
|
||||
#include "QtSfmlTileRenderer.hpp"
|
||||
|
||||
|
||||
namespace ComSquare::Renderer
|
||||
{
|
||||
|
||||
QtSFMLTileRenderer::QtSFMLTileRenderer(QWidget *parent,
|
||||
int frameRate)
|
||||
: QtWidgetSFML(parent, {0, 0}, {1025, 1025}, frameRate)
|
||||
: QtWidgetSFML(parent, {0, 0}, {16 * PPU::Tile::NbPixelsWidth, 18 * PPU::Tile::NbPixelsHeight}, frameRate)
|
||||
{
|
||||
// todo the size of the sfml renderwindow should fill the parent
|
||||
}
|
||||
|
||||
void QtSFMLTileRenderer::onUpdate()
|
||||
{
|
||||
this->_window.clear(sf::Color::Black);
|
||||
for (unsigned long i = 0; i < this->buffer.size(); i++) {
|
||||
for (unsigned long j = 0; j < this->buffer[i].size(); j++) {
|
||||
this->putPixel(j, i, this->buffer[i][j]);
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
this->_renderWindow.clear(sf::Color::Black);
|
||||
for (const auto &row : this->buffer) {
|
||||
for (const auto &pixel : row) {
|
||||
this->putPixel(j++, i, pixel);
|
||||
}
|
||||
i++;
|
||||
j = 0;
|
||||
}
|
||||
this->drawScreen();
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace ComSquare::Renderer
|
||||
#ifdef Q_WS_X11
|
||||
XFlush(QX11Info::display());
|
||||
#endif
|
||||
this->_window.create(static_cast<sf::WindowHandle>(this->winId()));
|
||||
this->_window.setFramerateLimit(60);
|
||||
this->_renderWindow.create(static_cast<sf::WindowHandle>(this->winId()));
|
||||
this->_renderWindow.setFramerateLimit(60);
|
||||
this->_onInit();
|
||||
|
||||
this->_timer.setSingleShot(false);
|
||||
@@ -52,4 +52,15 @@ namespace ComSquare::Renderer
|
||||
|
||||
void QtWidgetSFML::_onInit()
|
||||
{}
|
||||
|
||||
void QtWidgetSFML::setSize(unsigned int width, unsigned int height)
|
||||
{
|
||||
SFRenderer::setSize(width, height);
|
||||
QWidget::resize(static_cast<int>(width), static_cast<int>(height));
|
||||
}
|
||||
|
||||
void QtWidgetSFML::onUpdate()
|
||||
{
|
||||
this->drawScreen();
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,12 @@ namespace ComSquare::Renderer
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
//! @brief Function called to update this widget.
|
||||
virtual void onUpdate() = 0;
|
||||
virtual void onUpdate();
|
||||
|
||||
//! @brief Set a size or resize the Renderer drawing size
|
||||
//! @param height The new height of the renderer in pixels
|
||||
//! @param width The new width of the renderer in pixels
|
||||
void setSize(unsigned width, unsigned height) override;
|
||||
private:
|
||||
//! @brief Function called when this widget is created.
|
||||
virtual void _onInit();
|
||||
|
||||
@@ -12,21 +12,21 @@
|
||||
namespace ComSquare::Renderer
|
||||
{
|
||||
SFRenderer::SFRenderer(unsigned int height, unsigned int width)
|
||||
: _videoMode({width, height, 32}),
|
||||
_pixelBuffer(new sf::Color[height * width])
|
||||
{
|
||||
this->_videoMode = {width, height, 32};
|
||||
this->_texture.create(width, height);
|
||||
this->_sprite.setTexture(this->_texture);
|
||||
this->_pixelBuffer = new sf::Color[height * width];
|
||||
this->_sound.setBuffer(this->_soundBuffer);
|
||||
}
|
||||
|
||||
void SFRenderer::createWindow(SNES &snes, int maxFPS)
|
||||
{
|
||||
sf::Image icon;
|
||||
this->_window.create(this->_videoMode, "ComSquare Emulator", sf::Style::Default);
|
||||
this->_renderWindow.create(this->_videoMode, "ComSquare Emulator", sf::Style::Default);
|
||||
if (icon.loadFromFile("resources/Logo.png"))
|
||||
this->_window.setIcon(314, 314, icon.getPixelsPtr());
|
||||
this->_window.setFramerateLimit(maxFPS);
|
||||
this->_renderWindow.setIcon(314, 314, icon.getPixelsPtr());
|
||||
this->_renderWindow.setFramerateLimit(maxFPS);
|
||||
this->setWindowName(snes.cartridge.header.gameName);
|
||||
|
||||
while (!this->shouldExit) {
|
||||
@@ -37,20 +37,20 @@ namespace ComSquare::Renderer
|
||||
|
||||
SFRenderer::~SFRenderer()
|
||||
{
|
||||
delete [] this->_pixelBuffer;
|
||||
delete[] this->_pixelBuffer;
|
||||
}
|
||||
|
||||
void SFRenderer::setWindowName(std::string &newWindowName)
|
||||
{
|
||||
this->_window.setTitle(newWindowName + " - ComSquare");
|
||||
this->_renderWindow.setTitle(newWindowName + " - ComSquare");
|
||||
}
|
||||
|
||||
void SFRenderer::drawScreen()
|
||||
{
|
||||
this->_texture.update(reinterpret_cast<sf::Uint8 *>(this->_pixelBuffer));
|
||||
this->_sprite.setTexture(this->_texture);
|
||||
this->_window.draw(this->_sprite);
|
||||
this->_window.display();
|
||||
this->_renderWindow.draw(this->_sprite);
|
||||
this->_renderWindow.display();
|
||||
}
|
||||
|
||||
void SFRenderer::playAudio(std::span<int16_t> samples)
|
||||
@@ -71,12 +71,24 @@ namespace ComSquare::Renderer
|
||||
|
||||
void SFRenderer::getEvents()
|
||||
{
|
||||
sf::Event event;
|
||||
while (this->_window.pollEvent(event)) {
|
||||
sf::Event event{};
|
||||
while (this->_renderWindow.pollEvent(event)) {
|
||||
if (event.type == sf::Event::Closed) {
|
||||
this->shouldExit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SFRenderer::setSize(unsigned int width, unsigned int height)
|
||||
{
|
||||
this->_renderWindow.setSize({width, height});
|
||||
this->_videoMode.width = width;
|
||||
this->_videoMode.height = height;
|
||||
if (!this->_texture.create(width, height)) {
|
||||
throw std::runtime_error("sfml texture resize failed");
|
||||
}
|
||||
delete[] this->_pixelBuffer;
|
||||
this->_pixelBuffer = new sf::Color[height * width];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace ComSquare::Renderer
|
||||
public:
|
||||
explicit InvalidPixelPosition(const std::string &name, unsigned int x, unsigned int width)
|
||||
: _msg("Trying to place a pixel at an invalid " + name + " (" + std::to_string(x) + ">=" + std::to_string(width) + ")") {}
|
||||
const char *what() const noexcept override { return this->_msg.c_str(); }
|
||||
[[nodiscard]] const char *what() const noexcept override { return this->_msg.c_str(); }
|
||||
};
|
||||
|
||||
class SFRenderer : public IRenderer {
|
||||
protected:
|
||||
//! @brief The Renderer for the window.
|
||||
sf::RenderWindow _window;
|
||||
sf::RenderWindow _renderWindow;
|
||||
//! @brief Video Mode containing the _height and _width of the window.
|
||||
sf::VideoMode _videoMode;
|
||||
//! @brief The image that contain all of the pixels
|
||||
@@ -48,6 +48,10 @@ namespace ComSquare::Renderer
|
||||
void setWindowName(std::string &newWindowName) override;
|
||||
//! @brief Update the screen by printing the buffer.
|
||||
void drawScreen() override;
|
||||
//! @brief Set a size or resize the Renderer drawing size
|
||||
//! @param height The new height of the renderer in pixels
|
||||
//! @param width The new width of the renderer in pixels
|
||||
void setSize(unsigned width, unsigned height) override;
|
||||
//! @brief Add a pixel to the buffer to the coordinates x, y with the color rgba.
|
||||
//! @param X horizontal index.
|
||||
//! @param Y vertical index.
|
||||
|
||||
+48
-9
@@ -22,7 +22,45 @@
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_sfml" native="true"/>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>7</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1024</width>
|
||||
<height>1024</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="widget_sfml">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1024</width>
|
||||
<height>1024</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>1024</width>
|
||||
<height>1024</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
@@ -55,14 +93,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>SIze (bytes)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="ByteSize">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
@@ -93,14 +131,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="BppFormat">
|
||||
<property name="currentText">
|
||||
<string>2 bpp</string>
|
||||
@@ -131,7 +169,7 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="cursor">
|
||||
<cursorShape>ArrowCursor</cursorShape>
|
||||
@@ -140,10 +178,11 @@
|
||||
<string>Columns</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring></cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="NbColumns">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
@@ -162,14 +201,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Palette Index</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QSpinBox" name="PaletteIndex">
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
|
||||
Reference in New Issue
Block a user