Skip to content

Commit

Permalink
fix wii u release not rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Nov 1, 2024
1 parent 4ba83b0 commit 0590864
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 102 deletions.
2 changes: 1 addition & 1 deletion include/common/Exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace love
std::string message;
};

#if __DEBUG__
#if 1
#include <cstdio>

// Macro to log to both stdout and a debug.log file
Expand Down
78 changes: 41 additions & 37 deletions include/modules/joystick/Joystick.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace love
GAMEPAD_BUTTON_DPAD_RIGHT,
GAMEPAD_BUTTON_MISC1,
GAMEPAD_BUTTON_MISC2,
GAMEPAD_BUTTON_Z, //< Nunchuk only
GAMEPAD_BUTTON_C, //< Nunchuk only
GAMEPAD_BUTTON_MAX_ENUM
};

Expand Down Expand Up @@ -190,23 +192,25 @@ namespace love

// clang-format off
STRINGMAP_DECLARE(GamepadButtons, GamepadButton,
{ "a", GAMEPAD_BUTTON_A },
{ "b", GAMEPAD_BUTTON_B },
{ "x", GAMEPAD_BUTTON_X },
{ "y", GAMEPAD_BUTTON_Y },
{ "back", GAMEPAD_BUTTON_BACK },
{ "guide", GAMEPAD_BUTTON_GUIDE },
{ "start", GAMEPAD_BUTTON_START },
{ "leftstick", GAMEPAD_BUTTON_LEFTSTICK },
{ "rightstick", GAMEPAD_BUTTON_RIGHTSTICK },
{ "leftshoulder", GAMEPAD_BUTTON_LEFTSHOULDER },
{ "rightshoulder", GAMEPAD_BUTTON_RIGHTSHOULDER },
{ "dpup", GAMEPAD_BUTTON_DPAD_UP },
{ "dpdown", GAMEPAD_BUTTON_DPAD_DOWN },
{ "dpleft", GAMEPAD_BUTTON_DPAD_LEFT },
{ "dpright", GAMEPAD_BUTTON_DPAD_RIGHT },
{ "misc1", GAMEPAD_BUTTON_MISC1 },
{ "misc2", GAMEPAD_BUTTON_MISC2 }
{ "a", GAMEPAD_BUTTON_A },
{ "b", GAMEPAD_BUTTON_B },
{ "x", GAMEPAD_BUTTON_X },
{ "y", GAMEPAD_BUTTON_Y },
{ "back", GAMEPAD_BUTTON_BACK },
{ "guide", GAMEPAD_BUTTON_GUIDE },
{ "start", GAMEPAD_BUTTON_START },
{ "leftstick", GAMEPAD_BUTTON_LEFTSTICK },
{ "rightstick", GAMEPAD_BUTTON_RIGHTSTICK },
{ "leftshoulder", GAMEPAD_BUTTON_LEFTSHOULDER },
{ "rightshoulder", GAMEPAD_BUTTON_RIGHTSHOULDER },
{ "dpup", GAMEPAD_BUTTON_DPAD_UP },
{ "dpdown", GAMEPAD_BUTTON_DPAD_DOWN },
{ "dpleft", GAMEPAD_BUTTON_DPAD_LEFT },
{ "dpright", GAMEPAD_BUTTON_DPAD_RIGHT },
{ "misc1", GAMEPAD_BUTTON_MISC1 },
{ "misc2", GAMEPAD_BUTTON_MISC2 },
{ "z", GAMEPAD_BUTTON_Z }, //< Nunchuk only
{ "c", GAMEPAD_BUTTON_C } //< Nunchuk only
);

STRINGMAP_DECLARE(GamepadAxes, GamepadAxis,
Expand All @@ -219,29 +223,29 @@ namespace love
);

STRINGMAP_DECLARE(InputTypes, InputType,
{ "axis", INPUT_TYPE_AXIS },
{ "button", INPUT_TYPE_BUTTON },
{ "hat", INPUT_TYPE_HAT }
{ "axis", INPUT_TYPE_AXIS },
{ "button", INPUT_TYPE_BUTTON },
{ "hat", INPUT_TYPE_HAT }
);

STRINGMAP_DECLARE(GamepadTypes, GamepadType,
{ "unknown", GAMEPAD_TYPE_UNKNOWN },
{ "3ds", GAMEPAD_TYPE_NINTENDO_3DS },
{ "3dsxl", GAMEPAD_TYPE_NINTENDO_3DS_XL },
{ "new3ds", GAMEPAD_TYPE_NEW_NINTENDO_3DS },
{ "new3dsxl", GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL },
{ "2ds", GAMEPAD_TYPE_NINTENDO_2DS },
{ "new2dsxl", GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL },
{ "wiiremote", GAMEPAD_TYPE_NINTENDO_WII_REMOTE },
{ "wiiremotenunchuck", GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK },
{ "wiiclassic", GAMEPAD_TYPE_NINTENDO_WII_CLASSIC },
{ "wiiugamepad", GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD },
{ "wiiupro", GAMEPAD_TYPE_NINTENDO_WII_U_PRO },
{ "switchhandheld", GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD },
{ "switchpro", GAMEPAD_TYPE_NINTENDO_SWITCH_PRO },
{ "joyconleft", GAMEPAD_TYPE_JOYCON_LEFT },
{ "joyconright", GAMEPAD_TYPE_JOYCON_RIGHT },
{ "joyconpair", GAMEPAD_TYPE_JOYCON_PAIR }
{ "unknown", GAMEPAD_TYPE_UNKNOWN },
{ "3ds", GAMEPAD_TYPE_NINTENDO_3DS },
{ "3dsxl", GAMEPAD_TYPE_NINTENDO_3DS_XL },
{ "new3ds", GAMEPAD_TYPE_NEW_NINTENDO_3DS },
{ "new3dsxl", GAMEPAD_TYPE_NEW_NINTENDO_3DS_XL },
{ "2ds", GAMEPAD_TYPE_NINTENDO_2DS },
{ "new2dsxl", GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL },
{ "wiiremote", GAMEPAD_TYPE_NINTENDO_WII_REMOTE },
{ "wiiremotenunchuk", GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK },
{ "wiiclassic", GAMEPAD_TYPE_NINTENDO_WII_CLASSIC },
{ "wiiugamepad", GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD },
{ "wiiupro", GAMEPAD_TYPE_NINTENDO_WII_U_PRO },
{ "switchhandheld", GAMEPAD_TYPE_NINTENDO_SWITCH_HANDHELD },
{ "switchpro", GAMEPAD_TYPE_NINTENDO_SWITCH_PRO },
{ "joyconleft", GAMEPAD_TYPE_JOYCON_LEFT },
{ "joyconright", GAMEPAD_TYPE_JOYCON_RIGHT },
{ "joyconpair", GAMEPAD_TYPE_JOYCON_PAIR }
);

STRINGMAP_DECLARE(JoystickTypes, JoystickType,
Expand Down
2 changes: 1 addition & 1 deletion include/utility/guid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace love
GAMEPAD_TYPE_NINTENDO_2DS,
GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL,
GAMEPAD_TYPE_NINTENDO_WII_REMOTE,
GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK,
GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK,
GAMEPAD_TYPE_NINTENDO_WII_CLASSIC,
GAMEPAD_TYPE_NINTENDO_WII_U_GAMEPAD,
GAMEPAD_TYPE_NINTENDO_WII_U_PRO,
Expand Down
10 changes: 2 additions & 8 deletions platform/cafe/include/driver/display/Framebuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ namespace love

void copyScanBuffer();

operator GX2ContextState*()
{
return this->state;
}

private:
static constexpr auto FORMAT = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
static constexpr auto BUFFER_MODE = GX2_BUFFERING_MODE_DOUBLE;
Expand All @@ -66,11 +61,10 @@ namespace love
uint8_t renderMode;
GX2ScanTarget id;

Uniform* uniform;
Uniform* uniform = nullptr;
glm::mat4 tmpModel;

void* scanBuffer;
uint32_t scanBufferSize;

GX2ContextState* state;
};
} // namespace love
28 changes: 3 additions & 25 deletions platform/cafe/include/driver/display/Uniform.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "common/Exception.hpp"
#include "common/Matrix.hpp"

#include <glm/glm.hpp>
Expand All @@ -11,32 +12,9 @@ namespace love
{
glm::mat4 modelView;
glm::mat4 projection;

void debug()
{
const auto count = sizeof(glm::mat4) / sizeof(uint32_t);

uint32_t* model = (uint32_t*)glm::value_ptr(this->modelView);
for (size_t index = 0; index < count; index++)
std::printf("modelView[%zu] = %u\n", index, model[index]);

uint32_t* projection = (uint32_t*)glm::value_ptr(this->projection);
for (size_t index = 0; index < count; index++)
std::printf("projection[%zu] = %u\n", index, projection[index]);
}

void update(const Matrix4& matrix)
{
const auto count = sizeof(glm::mat4) / sizeof(uint32_t);
uint32_t* destination = (uint32_t*)glm::value_ptr(this->modelView);

glm::mat4 sourceMatrix = glm::transpose(glm::make_mat4(matrix.getElements()));
uint32_t* source = (uint32_t*)glm::value_ptr(sourceMatrix);

for (int i = 0; i < count; ++i)
destination[i] = __builtin_bswap32(source[i]);
}
};

void debugUniform(Uniform* uniform);

static constexpr auto UNIFORM_SIZE = sizeof(Uniform);
} // namespace love
4 changes: 4 additions & 0 deletions platform/cafe/include/driver/graphics/StreamBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace love
throw love::Exception("Failed to create StreamBuffer");
}

StreamBuffer(StreamBuffer&&) = delete;

StreamBuffer& operator=(const StreamBuffer&) = delete;

~StreamBuffer()
{
GX2RDestroyBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE);
Expand Down
3 changes: 2 additions & 1 deletion platform/cafe/include/modules/joystick/kpad/Joystick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ namespace love

// clang-format off
ENUMMAP_DECLARE(NunchuckButtons, GamepadButton, WPADNunchukButton,
{ GAMEPAD_BUTTON_LEFTSHOULDER, WPAD_NUNCHUK_BUTTON_C }
{ GAMEPAD_BUTTON_C, WPAD_NUNCHUK_BUTTON_C },
{ GAMEPAD_BUTTON_Z, WPAD_NUNCHUK_BUTTON_Z }
);

ENUMMAP_DECLARE(NunchuckAxes, GamepadAxis, NunchuckAxis,
Expand Down
10 changes: 9 additions & 1 deletion platform/cafe/source/driver/display/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ namespace love

this->uniform->modelView = glm::mat4(1.0f);
this->uniform->projection = glm::mat4(1.0f);

this->tmpModel = glm::mat4(1.0f);
}

void Framebuffer::destroy()
{
std::free(this->uniform);
this->uniform = nullptr;
}

bool Framebuffer::allocateScanBuffer(MEMHeapHandle handle)
Expand Down Expand Up @@ -127,13 +130,18 @@ namespace love

const size_t count = sizeof(glm::mat4) / sizeof(uint32_t);

uint32_t* model = (uint32_t*)glm::value_ptr(glm::mat4(1.0f));
uint32_t* model = (uint32_t*)glm::value_ptr(this->tmpModel);
for (size_t index = 0; index < count; index++)
{
LOG("%lu/%f", model[index], (float)(model[index]));
dstModel[index] = __builtin_bswap32(model[index]);
}

uint32_t* projection = (uint32_t*)glm::value_ptr(ortho);
for (size_t index = 0; index < count; index++)
dstProj[index] = __builtin_bswap32(projection[index]);

love::debugUniform(this->uniform);
}

void Framebuffer::setScissor(const Rect& scissor)
Expand Down
5 changes: 4 additions & 1 deletion platform/cafe/source/driver/display/GX2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ namespace love
this->context.depthWrite = true;
this->context.compareMode = GX2_COMPARE_FUNC_ALWAYS;

this->uniform = (Uniform*)memalign(GX2_UNIFORM_BLOCK_ALIGNMENT, sizeof(Uniform));
this->uniform = (Uniform*)memalign(GX2_UNIFORM_BLOCK_ALIGNMENT, sizeof(Uniform));
this->uniform->modelView = glm::mat4(1.0f);
this->uniform->projection = glm::mat4(1.0f);

this->bindFramebuffer(&this->targets[0].get());

this->initialized = true;
Expand Down
21 changes: 8 additions & 13 deletions platform/cafe/source/driver/display/Uniform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

namespace love
{
glm::mat4 createTransposedSwappedMatrix(const Matrix4& matrix)
void debugUniform(Uniform* uniform)
{
const uint32_t count = sizeof(glm::mat4) / sizeof(uint32_t);
const auto count = sizeof(glm::mat4) / sizeof(uint32_t);

// Transpose the input matrix to convert from row-major to column-major
glm::mat4 sourceMatrix = glm::transpose(glm::make_mat4(matrix.getElements()));
uint32_t* model = (uint32_t*)glm::value_ptr(uniform->modelView);
for (size_t index = 0; index < count; index++)
LOG("modelView[%zu] = %u\n", index, model[index]);

// Create a new matrix to hold the endian-swapped version
glm::mat4 resultMatrix;
uint32_t* destination = (uint32_t*)glm::value_ptr(resultMatrix);
const uint32_t* source = (const uint32_t*)glm::value_ptr(sourceMatrix);

for (int i = 0; i < count; ++i)
destination[i] = __builtin_bswap32(source[i]);

return resultMatrix;
uint32_t* projection = (uint32_t*)glm::value_ptr(uniform->projection);
for (size_t index = 0; index < count; index++)
LOG("projection[%zu] = %u\n", index, projection[index]);
}
} // namespace love
32 changes: 19 additions & 13 deletions platform/cafe/source/modules/joystick/kpad/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace love
}
case WPAD_EXT_NUNCHUK:
{
this->gamepadType = GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK;
this->gamepadType = GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK;
break;
}
case WPAD_EXT_PRO_CONTROLLER:
Expand Down Expand Up @@ -138,13 +138,17 @@ namespace love
return clamp(this->status.classic.rightStick.y);
else if (axis == GAMEPAD_AXIS_TRIGGERLEFT)
return this->status.classic.hold & WPAD_CLASSIC_BUTTON_ZL ? 1.0f : 0.0f;
else if (axis == GAMEPAD_AXIS_TRIGGERRIGHT)
return this->status.classic.hold & WPAD_CLASSIC_BUTTON_ZR ? 1.0f : 0.0f;

return this->status.classic.hold & WPAD_CLASSIC_BUTTON_ZR ? 1.0f : 0.0f;
break;
}
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
{
if (axis == GAMEPAD_AXIS_TRIGGERLEFT)
return this->status.nunchuk.hold & WPAD_NUNCHUK_BUTTON_Z ? 1.0f : 0.0f;
if (axis == GAMEPAD_AXIS_LEFTX)
return clamp(this->status.nunchuk.stick.x);
else if (axis == GAMEPAD_AXIS_LEFTY)
return clamp(this->status.nunchuk.stick.y);

break;
}
Expand All @@ -160,11 +164,13 @@ namespace love
return clamp(this->status.pro.rightStick.y);
else if (axis == GAMEPAD_AXIS_TRIGGERLEFT)
return this->status.pro.hold & WPAD_PRO_TRIGGER_ZL ? 1.0f : 0.0f;
else if (axis == GAMEPAD_AXIS_TRIGGERRIGHT)
return this->status.pro.hold & WPAD_PRO_TRIGGER_ZR ? 1.0f : 0.0f;

return this->status.pro.hold & WPAD_PRO_TRIGGER_ZR ? 1.0f : 0.0f;
break;
}
default:
return 0.0f;
break;
}

return 0.0f;
Expand Down Expand Up @@ -235,7 +241,7 @@ namespace love
{
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE:
return isButtonDown<WPADButton>(buttons);
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
return isButtonDown<WPADButton>(buttons) || isButtonDown<WPADNunchukButton>(buttons);
case GAMEPAD_TYPE_NINTENDO_WII_CLASSIC:
return isButtonDown<WPADClassicButton>(buttons);
Expand All @@ -257,7 +263,7 @@ namespace love
{
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE:
return isButtonUp<WPADButton>(buttons);
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
return isButtonUp<WPADButton>(buttons) || isButtonUp<WPADNunchukButton>(buttons);
case GAMEPAD_TYPE_NINTENDO_WII_CLASSIC:
return isButtonUp<WPADClassicButton>(buttons);
Expand Down Expand Up @@ -296,7 +302,7 @@ namespace love
{
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE:
break;
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
return isAxisValueChanged<NunchuckAxis>(axis);
case GAMEPAD_TYPE_NINTENDO_WII_CLASSIC:
return isAxisValueChanged<ClassicAxis>(axis);
Expand Down Expand Up @@ -411,7 +417,7 @@ namespace love
data.push_back(this->status.acc.z);
break;
}
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
data.push_back(this->status.acc.x);
data.push_back(this->status.acc.y);
data.push_back(this->status.acc.z);
Expand All @@ -436,7 +442,7 @@ namespace love
switch (this->gamepadType)
{
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
{
result[0] = this->status.pos.x;
result[1] = this->status.pos.y;
Expand All @@ -458,7 +464,7 @@ namespace love
switch (this->gamepadType)
{
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK:
case GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK:
{
result[0] = this->status.angle.x;
result[1] = this->status.angle.y;
Expand Down
2 changes: 1 addition & 1 deletion source/utility/guid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace love
{ 12, 2, 0, "{3846FA8C-25AB-44CB-91FD-D58FB1F572CC}", false, false, true, true }, // GAMEPAD_TYPE_NINTENDO_2DS
{ 12, 6, 0, "{560CDDB3-0594-4A52-A3D5-617060D2001B}", true, true, true, true }, // GAMEPAD_TYPE_NEW_NINTENDO_2DS_XL
{ 10, 0, 0, "{02DC4D7B-2480-4678-BB06-D9AEDC3DE29B}", false, false, false, true }, // GAMEPAD_TYPE_NINTENDO_WII_REMOTE
{ 12, 2, 0, "{C0E2DDE5-25DF-4F7D-AEA6-4F25DE2FC385}", false, false, false, true }, // GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUCK
{ 12, 2, 0, "{C0E2DDE5-25DF-4F7D-AEA6-4F25DE2FC385}", false, false, false, true }, // GAMEPAD_TYPE_NINTENDO_WII_REMOTE_NUNCHUK
{ 12, 6, 0, "{B4F6A311-8228-477D-857B-B875D891C46D}", true, true, false, false }, // GAMEPAD_TYPE_NINTENDO_WII_CLASSIC
{ 14, 6, 0, "{62998927-C43D-41F5-B6B1-D22CBF031D91}", true, true, true, true }, // GAMEPAD_TYPE_WII_U_GAMEPAD
{ 14, 6, 0, "{36895D3B-A724-4F46-994C-64BCE736EBCB}", true, true, false, false }, // GAMEPAD_TYPE_WII_U_PRO
Expand Down

0 comments on commit 0590864

Please sign in to comment.