Skip to content

Commit

Permalink
push whatever this was
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Sep 29, 2024
1 parent c300387 commit a9ec4ef
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ if (NINTENDO_WIIU)

find_package(Freetype REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Freetype::Freetype bz2 png turbojpeg ddsparse)

execute_process(COMMAND patch -d ${CMAKE_CURRENT_BINARY_DIR}/luasocket/libluasocket -N -i ${PROJECT_SOURCE_DIR}/platform/cafe/libraries/luasocket.patch)
endif()

add_custom_target(test
Expand Down
2 changes: 2 additions & 0 deletions include/modules/keyboard/Keyboard.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace love
using ValidationError = const char**;
#elif defined(__SWITCH__)
using ValidationError = char*;
#else
using ValidationError = void*;
#endif

typedef KeyboardResult (*KeyboardValidationCallback)(const KeyboardValidationInfo* info,
Expand Down
26 changes: 10 additions & 16 deletions platform/cafe/include/driver/graphics/StreamBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,22 @@ namespace love
public:
StreamBuffer(BufferUsage usage, size_t size) : StreamBufferBase<T>(usage, size)
{
this->buffer = new GX2RBuffer();

if (this->buffer == nullptr)
throw love::Exception(E_OUT_OF_MEMORY);

auto flags = (usage == BufferUsage::BUFFERUSAGE_VERTEX) ? GX2R_RESOURCE_BIND_VERTEX_BUFFER
: GX2R_RESOURCE_BIND_INDEX_BUFFER;

this->buffer->elemCount = size;
this->buffer->elemSize = sizeof(T);
this->buffer->flags = flags | BUFFER_CREATE_FLAGS;
this->buffer.elemCount = size;
this->buffer.elemSize = sizeof(T);
this->buffer.flags = flags | BUFFER_CREATE_FLAGS;

if (!GX2RCreateBuffer(this->buffer))
if (!GX2RCreateBuffer(&this->buffer))
throw love::Exception("Failed to create StreamBuffer");
}

MapInfo<T> map(size_t)
{
MapInfo<T> info {};

auto* data = (T*)GX2RLockBufferEx(this->buffer, GX2R_RESOURCE_BIND_NONE);
auto* data = (T*)GX2RLockBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE);

info.data = &data[this->index];
info.size = this->bufferSize - this->frameGPUReadOffset;
Expand All @@ -45,29 +40,28 @@ namespace love

size_t unmap(size_t)
{
GX2RUnlockBufferEx(this->buffer, GX2R_RESOURCE_BIND_NONE);
GX2RUnlockBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE);

if (this->usage == BufferUsage::BUFFERUSAGE_VERTEX)
GX2RSetAttributeBuffer(this->buffer, 0, this->buffer->elemSize, 0);
GX2RSetAttributeBuffer(&this->buffer, 0, this->buffer.elemSize, 0);

return this->index;
}

~StreamBuffer()
{
GX2RDestroyBufferEx(this->buffer, GX2R_RESOURCE_BIND_NONE);
delete this->buffer;
GX2RDestroyBufferEx(&this->buffer, GX2R_RESOURCE_BIND_NONE);
}

ptrdiff_t getHandle() const override
{
return (ptrdiff_t)this->buffer;
return (ptrdiff_t)std::addressof(this->buffer);
}

private:
static constexpr auto BUFFER_CREATE_FLAGS =
GX2R_RESOURCE_USAGE_CPU_READ | GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ;

GX2RBuffer* buffer;
GX2RBuffer buffer;
};
} // namespace love
19 changes: 6 additions & 13 deletions platform/cafe/source/driver/display/GX2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ namespace love

GX2Init(attributes);

this->createFramebuffers();

this->state = (GX2ContextState*)memalign(GX2_CONTEXT_STATE_ALIGNMENT, sizeof(GX2ContextState));

if (!this->state)
Expand All @@ -122,8 +120,10 @@ namespace love
GX2SetupContextStateEx(this->state, false);
GX2SetContextState(this->state);

this->createFramebuffers();

GX2SetDepthOnlyControl(false, false, GX2_COMPARE_FUNC_ALWAYS);
GX2SetAlphaTest(false, GX2_COMPARE_FUNC_ALWAYS, 0.0f);
// GX2SetAlphaTest(false, GX2_COMPARE_FUNC_ALWAYS, 0.0f);

GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, false, true);
GX2SetSwapInterval(1);
Expand Down Expand Up @@ -157,12 +157,7 @@ namespace love
const auto& info = love::getScreenInfo();

for (size_t index = 0; index < info.size(); ++index)
{
Framebuffer framebuffer {};
framebuffer.create(info[index]);

this->targets[index] = std::move(framebuffer);
}
this->targets[index].create(info[index]);
}

GX2ColorBuffer& GX2::getInternalBackbuffer()
Expand Down Expand Up @@ -190,7 +185,7 @@ namespace love
{
if (!this->inFrame)
{
GX2SetContextState(this->state);
// GX2SetContextState(this->state);
this->inFrame = true;
}
}
Expand Down Expand Up @@ -228,6 +223,7 @@ namespace love

if (bindingModified)
{
// this->targets[love::currentScreen].useState();
GX2SetColorBuffer(target, GX2_RENDER_TARGET_0);
this->setMode(target->surface.width, target->surface.height);
}
Expand Down Expand Up @@ -323,10 +319,7 @@ namespace love
}

if (Keyboard()->hasTextInput())
{
nn::swkbd::DrawDRC();
GX2SetContextState(this->state);
}

for (auto& target : this->targets)
target.copyScanBuffer();
Expand Down
15 changes: 8 additions & 7 deletions platform/cafe/source/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,14 @@ namespace love
gx2.prepareDraw(this);
gx2.bindTextureToUnit(command.texture, 0);

auto* buffer = (GX2RBuffer*)command.indexBuffer->getHandle();
const size_t offset = command.indexBufferOffset;

const auto mode = GX2::getPrimitiveType(command.primitiveType);
const auto indexType = GX2::getIndexType(command.indexType);

GX2RDrawIndexed(mode, buffer, indexType, command.indexCount, offset, 0, command.instanceCount);
const auto mode = GX2::getPrimitiveType(command.primitiveType);
auto* buffer = (GX2RBuffer*)command.indexBuffer->getHandle();
const auto indexType = GX2::getIndexType(command.indexType);
const uint32_t count = (uint32_t)command.indexCount;
const uint32_t offset = (uint32_t)command.indexBufferOffset;
const uint32_t instanceCount = (uint32_t)command.instanceCount;

GX2RDrawIndexed(mode, buffer, indexType, count, offset, 0, instanceCount);
++this->drawCalls;
}

Expand Down
20 changes: 10 additions & 10 deletions platform/cafe/source/modules/graphics/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace love

auto transform = graphics->getTransform();

GX2Invalidate(INVALIDATE_UNIFORM_BLOCK, uniform, sizeof(Uniform));
GX2Invalidate(GX2_INVALIDATE_MODE_UNIFORM_BLOCK, uniform, sizeof(Uniform));
GX2SetVertexUniformBlock(this->uniform.location, sizeof(Uniform), uniform);
}

Expand All @@ -119,18 +119,18 @@ namespace love

void Shader::attach()
{
if (current != this)
{
Graphics::flushBatchedDrawsGlobal();
// if (current != this)
// {
Graphics::flushBatchedDrawsGlobal();

GX2SetShaderMode(GX2_SHADER_MODE_UNIFORM_BLOCK);
GX2SetShaderMode(GX2_SHADER_MODE_UNIFORM_BLOCK);

GX2SetFetchShader(&this->program.fetchShader);
GX2SetVertexShader(this->program.vertexShader);
GX2SetPixelShader(this->program.pixelShader);
GX2SetFetchShader(&this->program.fetchShader);
GX2SetVertexShader(this->program.vertexShader);
GX2SetPixelShader(this->program.pixelShader);

current = this;
}
current = this;
// }
}

bool Shader::validate(const char* filepath, std::string& error)
Expand Down
6 changes: 4 additions & 2 deletions source/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "common/Console.hpp"
#include "common/screen.hpp"

#include <cmath>

namespace love
{
GraphicsBase::GraphicsBase(const char* name) :
Expand Down Expand Up @@ -991,8 +993,8 @@ namespace love

for (int index = 0; index < points; ++index, phi += shift)
{
coords[index].x = x + a * std::cosf(phi);
coords[index].y = y + b * std::sinf(phi);
coords[index].x = x + a * cosf(phi);
coords[index].y = y + b * sinf(phi);
}

coords[points] = coords[0];
Expand Down
2 changes: 1 addition & 1 deletion source/modules/graphics/wrap_Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ static void luax_checktexturesettings(lua_State* L, int index, bool optional, bo
lua_rawgeti(L, -1, index);
const char* formatName = luaL_checkstring(L, -1);

PixelFormat format;
PixelFormat format = PIXELFORMAT_UNKNOWN;
if (!love::getConstant(formatName, format))
luax_enumerror(L, "pixel format", formatName);

Expand Down

0 comments on commit a9ec4ef

Please sign in to comment.