basic ppu background rendering
This commit is contained in:
parent
f9f401c6c0
commit
aef80e42fb
21 changed files with 468 additions and 41 deletions
|
@ -11,6 +11,7 @@
|
|||
#include "MemoryViewer.hpp"
|
||||
#include "NametableViewer.hpp"
|
||||
#include "ControllerPortViewer.hpp"
|
||||
#include "Palettes.hpp"
|
||||
|
||||
Debugger::Debugger(Bus* bus) :
|
||||
bus(bus)
|
||||
|
@ -26,6 +27,7 @@ Debugger::Debugger(Bus* bus) :
|
|||
windows.push_back(new MemoryViewer(this, bus));
|
||||
windows.push_back(new NametableViewer(this, bus));
|
||||
windows.push_back(new ControllerPortViewer(this, &bus->controllerPort));
|
||||
windows.push_back(new Palettes(this, bus));
|
||||
}
|
||||
|
||||
Debugger::~Debugger()
|
||||
|
|
|
@ -86,7 +86,15 @@ void PPUWatcher::OnRender()
|
|||
ImGui::Text("Pattern Tile Lo: %02X", ppu->patternTableLo);
|
||||
ImGui::Text("Pattern Tile Hi: %02X", ppu->patternTableHi);
|
||||
}
|
||||
|
||||
|
||||
if (ImGui::CollapsingHeader("Shift Registers"))
|
||||
{
|
||||
ImGui::Text("Pattern Tile Lo: %04X", ppu->loTile.Raw);
|
||||
ImGui::Text("Pattern Tile Hi: %02X", ppu->hiTile.Raw);
|
||||
ImGui::Text("Attribute Lo : %02X", ppu->loAttribute.Raw);
|
||||
ImGui::Text("Attribute Hi : %02X", ppu->hiAttribute.Raw);
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Registers"))
|
||||
{
|
||||
if (ImGui::TreeNode("PPUCTRL"))
|
||||
|
|
78
src/debugger/Palettes.cpp
Normal file
78
src/debugger/Palettes.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include "Palettes.hpp"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include "../Bus.hpp"
|
||||
#include "../PPU.hpp"
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
|
||||
Palettes::Palettes(Debugger* debugger, Bus* bus) :
|
||||
DebugWindow("Palettes", debugger), bus(bus)
|
||||
{
|
||||
glCreateTextures(GL_TEXTURE_2D, 4, backgroundPalettes.data());
|
||||
glCreateTextures(GL_TEXTURE_2D, 4, spritePalettes.data());
|
||||
|
||||
for (GLuint texture : backgroundPalettes)
|
||||
{
|
||||
glTextureStorage2D(texture, 1, GL_RGB8, 4, 1);
|
||||
glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
for (GLuint texture : spritePalettes)
|
||||
{
|
||||
glTextureStorage2D(texture, 1, GL_RGB8, 4, 1);
|
||||
glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
|
||||
Palettes::~Palettes()
|
||||
{
|
||||
glDeleteTextures(4, spritePalettes.data());
|
||||
glDeleteTextures(4, backgroundPalettes.data());
|
||||
}
|
||||
|
||||
void Palettes::OnRender()
|
||||
{
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_FirstUseEver);
|
||||
if (!ImGui::Begin(title.c_str(), &isOpen))
|
||||
{
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
Color palette[4];
|
||||
palette[0] = PPU::colorTable[bus->palettes[0]];
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
size.x /= 2;
|
||||
size.y = size.x / 4;
|
||||
if (ImGui::CollapsingHeader("Background"))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
palette[1] = PPU::colorTable[bus->palettes[i * 4 + 1]];
|
||||
palette[2] = PPU::colorTable[bus->palettes[i * 4 + 2]];
|
||||
palette[3] = PPU::colorTable[bus->palettes[i * 4 + 3]];
|
||||
|
||||
glTextureSubImage2D(backgroundPalettes[i], 0, 0, 0, 4, 1, GL_RGB, GL_UNSIGNED_BYTE, (const void*)palette);
|
||||
ImGui::Image((ImTextureID)backgroundPalettes[i], size);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Sprites"))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
palette[1] = PPU::colorTable[bus->palettes[0x10 + i * 4 + 1]];
|
||||
palette[2] = PPU::colorTable[bus->palettes[0x10 + i * 4 + 2]];
|
||||
palette[3] = PPU::colorTable[bus->palettes[0x10 + i * 4 + 3]];
|
||||
|
||||
glTextureSubImage2D(spritePalettes[i], 0, 0, 0, 4, 1, GL_RGB, GL_UNSIGNED_BYTE, (const void*)palette);
|
||||
ImGui::Image((ImTextureID)spritePalettes[i], size);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
22
src/debugger/Palettes.hpp
Normal file
22
src/debugger/Palettes.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include "DebugWindow.hpp"
|
||||
|
||||
class Bus;
|
||||
|
||||
class Palettes :
|
||||
public DebugWindow
|
||||
{
|
||||
public:
|
||||
Palettes(Debugger* debugger, Bus* bus);
|
||||
~Palettes();
|
||||
|
||||
virtual void OnRender() override;
|
||||
|
||||
private:
|
||||
Bus* bus;
|
||||
|
||||
std::array<uint32_t, 4> backgroundPalettes;
|
||||
std::array<uint32_t, 4> spritePalettes;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue