mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
Merge branch 'master' of github.com:fleroviux/Panda3DS into pica-tev-emulation
This commit is contained in:
commit
4cb7e3625b
13 changed files with 427 additions and 412 deletions
|
@ -320,10 +320,10 @@ void Renderer::reset() {
|
|||
|
||||
// Init the colour/depth buffer settings to some random defaults on reset
|
||||
colourBufferLoc = 0;
|
||||
colourBufferFormat = ColourBuffer::Formats::RGBA8;
|
||||
colourBufferFormat = PICA::ColorFmt::RGBA8;
|
||||
|
||||
depthBufferLoc = 0;
|
||||
depthBufferFormat = DepthBuffer::Formats::Depth16;
|
||||
depthBufferFormat = PICA::DepthFmt::Depth16;
|
||||
|
||||
if (triangleProgram.exists()) {
|
||||
const auto oldProgram = OpenGL::getProgram();
|
||||
|
@ -436,7 +436,7 @@ void Renderer::initGraphicsContext() {
|
|||
|
||||
// Set up the OpenGL blending context to match the emulated PICA
|
||||
void Renderer::setupBlending() {
|
||||
const bool blendingEnabled = (regs[PICAInternalRegs::ColourOperation] & (1 << 8)) != 0;
|
||||
const bool blendingEnabled = (regs[PICA::InternalRegs::ColourOperation] & (1 << 8)) != 0;
|
||||
|
||||
// Map of PICA blending equations to OpenGL blending equations. The unused blending equations are equivalent to equation 0 (add)
|
||||
static constexpr std::array<GLenum, 8> blendingEquations = {
|
||||
|
@ -456,7 +456,7 @@ void Renderer::setupBlending() {
|
|||
OpenGL::enableBlend();
|
||||
|
||||
// Get blending equations
|
||||
const u32 blendControl = regs[PICAInternalRegs::BlendFunc];
|
||||
const u32 blendControl = regs[PICA::InternalRegs::BlendFunc];
|
||||
const u32 rgbEquation = blendControl & 0x7;
|
||||
const u32 alphaEquation = getBits<8, 3>(blendControl);
|
||||
|
||||
|
@ -466,7 +466,7 @@ void Renderer::setupBlending() {
|
|||
const u32 alphaSourceFunc = getBits<24, 4>(blendControl);
|
||||
const u32 alphaDestFunc = getBits<28, 4>(blendControl);
|
||||
|
||||
const u32 constantColor = regs[PICAInternalRegs::BlendColour];
|
||||
const u32 constantColor = regs[PICA::InternalRegs::BlendColour];
|
||||
const u32 r = constantColor & 0xff;
|
||||
const u32 g = getBits<8, 8>(constantColor);
|
||||
const u32 b = getBits<16, 8>(constantColor);
|
||||
|
@ -511,7 +511,13 @@ void Renderer::setupTextureEnvState() {
|
|||
glUniform1ui(textureEnvBufferColorLoc, regs[0xfd]);
|
||||
}
|
||||
|
||||
void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex> vertices) {
|
||||
void Renderer::drawVertices(PICA::PrimType primType, std::span<const Vertex> vertices) {
|
||||
// The fourth type is meant to be "Geometry primitive". TODO: Find out what that is
|
||||
static constexpr std::array<OpenGL::Primitives, 4> primTypes = {
|
||||
OpenGL::Triangle, OpenGL::TriangleStrip, OpenGL::TriangleFan, OpenGL::Triangle
|
||||
};
|
||||
const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
|
||||
|
||||
// TODO: We should implement a GL state tracker that tracks settings like scissor, blending, bound program, etc
|
||||
// This way if we attempt to eg do multiple glEnable(GL_BLEND) calls in a row, it will say "Oh blending is already enabled"
|
||||
// And not actually perform the very expensive driver call for it
|
||||
|
@ -522,7 +528,7 @@ void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex>
|
|||
triangleProgram.use();
|
||||
|
||||
// Adjust alpha test if necessary
|
||||
const u32 alphaControl = regs[PICAInternalRegs::AlphaTestConfig];
|
||||
const u32 alphaControl = regs[PICA::InternalRegs::AlphaTestConfig];
|
||||
if (alphaControl != oldAlphaControl) {
|
||||
oldAlphaControl = alphaControl;
|
||||
glUniform1ui(alphaControlLoc, alphaControl);
|
||||
|
@ -532,7 +538,7 @@ void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex>
|
|||
OpenGL::Framebuffer poop = getColourFBO();
|
||||
poop.bind(OpenGL::DrawAndReadFramebuffer);
|
||||
|
||||
const u32 depthControl = regs[PICAInternalRegs::DepthAndColorMask];
|
||||
const u32 depthControl = regs[PICA::InternalRegs::DepthAndColorMask];
|
||||
const bool depthEnable = depthControl & 1;
|
||||
const bool depthWriteEnable = getBit<12>(depthControl);
|
||||
const int depthFunc = getBits<4, 3>(depthControl);
|
||||
|
@ -543,9 +549,9 @@ void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex>
|
|||
GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL
|
||||
};
|
||||
|
||||
const float depthScale = f24::fromRaw(regs[PICAInternalRegs::DepthScale] & 0xffffff).toFloat32();
|
||||
const float depthOffset = f24::fromRaw(regs[PICAInternalRegs::DepthOffset] & 0xffffff).toFloat32();
|
||||
const bool depthMapEnable = regs[PICAInternalRegs::DepthmapEnable] & 1;
|
||||
const float depthScale = f24::fromRaw(regs[PICA::InternalRegs::DepthScale] & 0xffffff).toFloat32();
|
||||
const float depthOffset = f24::fromRaw(regs[PICA::InternalRegs::DepthOffset] & 0xffffff).toFloat32();
|
||||
const bool depthMapEnable = regs[PICA::InternalRegs::DepthmapEnable] & 1;
|
||||
|
||||
// Update depth uniforms
|
||||
if (oldDepthScale != depthScale) {
|
||||
|
@ -585,7 +591,7 @@ void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex>
|
|||
u32 format = regs[ioBase + (i == 0 ? 14 : 6)] & 0xF;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
Texture targetTex(addr, static_cast<Texture::Formats>(format), width, height, config);
|
||||
Texture targetTex(addr, static_cast<PICA::TextureFmt>(format), width, height, config);
|
||||
OpenGL::Texture tex = getTexture(targetTex);
|
||||
tex.bind();
|
||||
}
|
||||
|
@ -593,15 +599,15 @@ void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex>
|
|||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// Update the texture unit configuration uniform if it changed
|
||||
const u32 texUnitConfig = regs[PICAInternalRegs::TexUnitCfg];
|
||||
const u32 texUnitConfig = regs[PICA::InternalRegs::TexUnitCfg];
|
||||
if (oldTexUnitConfig != texUnitConfig) {
|
||||
oldTexUnitConfig = texUnitConfig;
|
||||
glUniform1ui(texUnitConfigLoc, texUnitConfig);
|
||||
}
|
||||
|
||||
// TODO: Actually use this
|
||||
float viewportWidth = f24::fromRaw(regs[PICAInternalRegs::ViewportWidth] & 0xffffff).toFloat32() * 2.0;
|
||||
float viewportHeight = f24::fromRaw(regs[PICAInternalRegs::ViewportHeight] & 0xffffff).toFloat32() * 2.0;
|
||||
float viewportWidth = f24::fromRaw(regs[PICA::InternalRegs::ViewportWidth] & 0xffffff).toFloat32() * 2.0;
|
||||
float viewportHeight = f24::fromRaw(regs[PICA::InternalRegs::ViewportHeight] & 0xffffff).toFloat32() * 2.0;
|
||||
OpenGL::setViewport(viewportWidth, viewportHeight);
|
||||
|
||||
// Note: The code below must execute after we've bound the colour buffer & its framebuffer
|
||||
|
@ -623,7 +629,7 @@ void Renderer::drawVertices(OpenGL::Primitives primType, std::span<const Vertex>
|
|||
}
|
||||
|
||||
vbo.bufferVertsSub(vertices);
|
||||
OpenGL::draw(primType, vertices.size());
|
||||
OpenGL::draw(primitiveTopology, vertices.size());
|
||||
}
|
||||
|
||||
constexpr u32 topScreenBuffer = 0x1f000000;
|
||||
|
@ -685,8 +691,8 @@ void Renderer::bindDepthBuffer() {
|
|||
tex = depthBufferCache.add(sampleBuffer).texture.m_handle;
|
||||
}
|
||||
|
||||
if (DepthBuffer::Formats::Depth24Stencil8 != depthBufferFormat) Helpers::panic("TODO: Should we remove stencil attachment?");
|
||||
auto attachment = depthBufferFormat == DepthBuffer::Formats::Depth24Stencil8 ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
|
||||
if (PICA::DepthFmt::Depth24Stencil8 != depthBufferFormat) Helpers::panic("TODO: Should we remove stencil attachment?");
|
||||
auto attachment = depthBufferFormat == PICA::DepthFmt::Depth24Stencil8 ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, tex, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,34 +43,34 @@ u64 Texture::sizeInBytes() {
|
|||
u64 pixelCount = u64(size.x()) * u64(size.y());
|
||||
|
||||
switch (format) {
|
||||
case Formats::RGBA8: // 4 bytes per pixel
|
||||
case PICA::TextureFmt::RGBA8: // 4 bytes per pixel
|
||||
return pixelCount * 4;
|
||||
|
||||
case Formats::RGB8: // 3 bytes per pixel
|
||||
case PICA::TextureFmt::RGB8: // 3 bytes per pixel
|
||||
return pixelCount * 3;
|
||||
|
||||
case Formats::RGBA5551: // 2 bytes per pixel
|
||||
case Formats::RGB565:
|
||||
case Formats::RGBA4:
|
||||
case Formats::RG8:
|
||||
case Formats::IA8:
|
||||
case PICA::TextureFmt::RGBA5551: // 2 bytes per pixel
|
||||
case PICA::TextureFmt::RGB565:
|
||||
case PICA::TextureFmt::RGBA4:
|
||||
case PICA::TextureFmt::RG8:
|
||||
case PICA::TextureFmt::IA8:
|
||||
return pixelCount * 2;
|
||||
|
||||
case Formats::A8: // 1 byte per pixel
|
||||
case Formats::I8:
|
||||
case Formats::IA4:
|
||||
case PICA::TextureFmt::A8: // 1 byte per pixel
|
||||
case PICA::TextureFmt::I8:
|
||||
case PICA::TextureFmt::IA4:
|
||||
return pixelCount;
|
||||
|
||||
case Formats::I4: // 4 bits per pixel
|
||||
case Formats::A4:
|
||||
case PICA::TextureFmt::I4: // 4 bits per pixel
|
||||
case PICA::TextureFmt::A4:
|
||||
return pixelCount / 2;
|
||||
|
||||
case Formats::ETC1: // Compressed formats
|
||||
case Formats::ETC1A4: {
|
||||
case PICA::TextureFmt::ETC1: // Compressed formats
|
||||
case PICA::TextureFmt::ETC1A4: {
|
||||
// Number of 4x4 tiles
|
||||
const u64 tileCount = pixelCount / 16;
|
||||
// Tiles are 8 bytes each on ETC1 and 16 bytes each on ETC1A4
|
||||
const u64 tileSize = format == Formats::ETC1 ? 8 : 16;
|
||||
const u64 tileSize = format == PICA::TextureFmt::ETC1 ? 8 : 16;
|
||||
return tileCount * tileSize;
|
||||
}
|
||||
|
||||
|
@ -111,9 +111,9 @@ u32 Texture::getSwizzledOffset_4bpp(u32 u, u32 v, u32 width) {
|
|||
// Get the texel at position (u, v)
|
||||
// fmt: format of the texture
|
||||
// data: texture data of the texture
|
||||
u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
||||
u32 Texture::decodeTexel(u32 u, u32 v, PICA::TextureFmt fmt, const void* data) {
|
||||
switch (fmt) {
|
||||
case Formats::RGBA4: {
|
||||
case PICA::TextureFmt::RGBA4: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 2);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
u16 texel = u16(ptr[offset]) | (u16(ptr[offset + 1]) << 8);
|
||||
|
@ -126,7 +126,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
case Formats::RGBA5551: {
|
||||
case PICA::TextureFmt::RGBA5551: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 2);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
u16 texel = u16(ptr[offset]) | (u16(ptr[offset + 1]) << 8);
|
||||
|
@ -139,7 +139,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
case Formats::RGB565: {
|
||||
case PICA::TextureFmt::RGB565: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 2);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
u16 texel = u16(ptr[offset]) | (u16(ptr[offset + 1]) << 8);
|
||||
|
@ -151,7 +151,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (0xff << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
case Formats::RG8: {
|
||||
case PICA::TextureFmt::RG8: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 2);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -162,7 +162,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (0xff << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
case Formats::RGB8: {
|
||||
case PICA::TextureFmt::RGB8: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 3);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -173,7 +173,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (0xff << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
case Formats::RGBA8: {
|
||||
case PICA::TextureFmt::RGBA8: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 4);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -185,7 +185,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
case Formats::IA4: {
|
||||
case PICA::TextureFmt::IA4: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 1);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -197,7 +197,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (intensity << 16) | (intensity << 8) | intensity;
|
||||
}
|
||||
|
||||
case Formats::A4: {
|
||||
case PICA::TextureFmt::A4: {
|
||||
u32 offset = getSwizzledOffset_4bpp(u, v, size.u());
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -209,7 +209,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (0 << 16) | (0 << 8) | 0;
|
||||
}
|
||||
|
||||
case Formats::A8: {
|
||||
case PICA::TextureFmt::A8: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 1);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
const u8 alpha = ptr[offset];
|
||||
|
@ -218,7 +218,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (0 << 16) | (0 << 8) | 0;
|
||||
}
|
||||
|
||||
case Formats::I4: {
|
||||
case PICA::TextureFmt::I4: {
|
||||
u32 offset = getSwizzledOffset_4bpp(u, v, size.u());
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -230,7 +230,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (0xff << 24) | (intensity << 16) | (intensity << 8) | intensity;
|
||||
}
|
||||
|
||||
case Formats::I8: {
|
||||
case PICA::TextureFmt::I8: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 1);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
const u8 intensity = ptr[offset];
|
||||
|
@ -239,7 +239,7 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (0xff << 24) | (intensity << 16) | (intensity << 8) | intensity;
|
||||
}
|
||||
|
||||
case Formats::IA8: {
|
||||
case PICA::TextureFmt::IA8: {
|
||||
u32 offset = getSwizzledOffset(u, v, size.u(), 2);
|
||||
auto ptr = static_cast<const u8*>(data);
|
||||
|
||||
|
@ -249,8 +249,8 @@ u32 Texture::decodeTexel(u32 u, u32 v, Texture::Formats fmt, const void* data) {
|
|||
return (alpha << 24) | (intensity << 16) | (intensity << 8) | intensity;
|
||||
}
|
||||
|
||||
case Formats::ETC1: return getTexelETC(false, u, v, size.u(), data);
|
||||
case Formats::ETC1A4: return getTexelETC(true, u, v, size.u(), data);
|
||||
case PICA::TextureFmt::ETC1: return getTexelETC(false, u, v, size.u(), data);
|
||||
case PICA::TextureFmt::ETC1A4: return getTexelETC(true, u, v, size.u(), data);
|
||||
|
||||
default:
|
||||
Helpers::panic("[Texture::DecodeTexel] Unimplemented format = %d", static_cast<int>(fmt));
|
||||
|
@ -271,24 +271,4 @@ void Texture::decodeTexture(const void* data) {
|
|||
|
||||
texture.bind();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.u(), size.v(), GL_RGBA, GL_UNSIGNED_BYTE, decoded.data());
|
||||
}
|
||||
|
||||
std::string Texture::textureFormatToString(Texture::Formats fmt) {
|
||||
switch (fmt) {
|
||||
case Formats::A4: return "A4";
|
||||
case Formats::A8: return "A8";
|
||||
case Formats::ETC1: return "ETC1";
|
||||
case Formats::ETC1A4: return "ETC1A4";
|
||||
case Formats::I4: return "I4";
|
||||
case Formats::I8: return "I8";
|
||||
case Formats::IA4: return "IA4";
|
||||
case Formats::IA8: return "IA8";
|
||||
case Formats::RG8: return "RG8";
|
||||
case Formats::RGB565: return "RGB565";
|
||||
case Formats::RGB8: return "RGB8";
|
||||
case Formats::RGBA4: return "RGBA4";
|
||||
case Formats::RGBA5551: return "RGBA5551";
|
||||
case Formats::RGBA8: return "RGBA8";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue