Skip to content

Commit

Permalink
sync some more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Jan 15, 2023
1 parent 402f392 commit e118cd7
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 104 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ if (NINTENDO_WIIU)
target_include_directories(${PROJECT_NAME} PRIVATE ${DEVKITPRO}/portlibs/wiiu/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${FREETYPE_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_Mixer mpg123 SDL2)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_mixer mpg123 SDL2)
endif()

# Options for code generation
Expand Down
11 changes: 11 additions & 0 deletions include/common/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,15 @@ namespace love

return result;
}

inline std::vector<Screen> GetScreenEnums()
{
std::vector<Screen> result {};
const auto& info = GetScreenInfo();

for (auto& item : info)
result.push_back((Screen)item.id);

return result;
}
} // namespace love
5 changes: 0 additions & 5 deletions include/modules/keyboard/keyboard.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ namespace love
return "love.keyboard";
}

const bool HasTextInput() const
{
return true;
}

const bool HasScreenKeyboard() const
{
return true;
Expand Down
26 changes: 16 additions & 10 deletions platform/cafe/include/modules/keyboard_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ namespace love

virtual ~Keyboard();

void SetContextState()
{
if (!this->IsShowing())
return;

GX2SetContextState(this->state);
}

void SetTextInput(const KeyboardOptions& options);

const uint32_t GetMaxEncodingLength(const uint32_t in)
{
return in * 0x04;
}

const nn::swkbd::State GetState() const
{
return nn::swkbd::GetStateInputForm();
}

const bool HasTextInput() const
{
return this->IsShowing();
}

const bool IsShowing() const
{
auto state = nn::swkbd::GetStateInputForm();
return state != nn::swkbd::State::Hidden;
return this->GetState() != nn::swkbd::State::Hidden;
}

const bool IsHiding() const
{
return this->GetState() == nn::swkbd::State::FadeOut;
}

void HideKeyboard()
Expand Down
31 changes: 31 additions & 0 deletions platform/cafe/include/utilities/driver/framebuffer.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once

#include <common/math.hpp>
#include <common/screen_ext.hpp>
#include <common/vector.hpp>

#include <coreinit/memfrmheap.h>

#include <gx2/context.h>
#include <gx2/mem.h>
#include <gx2/registers.h>
#include <gx2/state.h>

#include <glm/mat4x4.hpp>

Expand All @@ -16,6 +19,10 @@ namespace love
{
class Framebuffer
{
private:
static constexpr float Z_NEAR = -10.0f;
static constexpr float Z_FAR = 10.0f;

public:
struct Transform
{
Expand Down Expand Up @@ -62,6 +69,10 @@ namespace love
*/
void SetProjection(const glm::highp_mat4& projection);

void SetViewport(const Rect& viewport = Rect::EMPTY);

void SetScissor(const Rect& scissor = Rect::EMPTY);

/*
** Invalidates the little endian Transform
** to be used in the Uniform Block
Expand Down Expand Up @@ -93,6 +104,21 @@ namespace love
/* Called on Renderer::OnForegroundAcquired */
bool InvalidateDepthBuffer(MEMHeapHandle handle);

void SetContext()
{
GX2SetContextState(this->state);
}

Rect GetViewport() const
{
return this->viewport;
}

Rect GetScissor() const
{
return this->scissor;
}

private:
static constexpr GX2ScanTarget SCAN_TARGETS[0x02] { GX2_SCAN_TARGET_TV,
GX2_SCAN_TARGET_DRC };
Expand Down Expand Up @@ -141,12 +167,17 @@ namespace love
GX2ColorBuffer colorBuffer;
GX2DepthBuffer depthBuffer;

GX2ContextState* state;

uint8_t mode;

void* scanBuffer;
uint32_t scanBufferSize;

int width;
int height;

Rect viewport;
Rect scissor;
};
} // namespace love
8 changes: 8 additions & 0 deletions platform/cafe/include/utilities/driver/renderer_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace love

void Clear(const Color& color);

void SetDepthWrites(bool write);

void ClearDepthStencil(int stencil, uint8_t mask, double depth);

void SetBlendColor(const Color& color);
Expand Down Expand Up @@ -208,6 +210,12 @@ namespace love
GX2FrontFace winding;
bool cullFront;
bool cullBack;

bool depthWrite;
bool depthTest;
GX2CompareFunction compareMode;

uint32_t writeMask;
} renderState;

std::vector<std::shared_ptr<DrawBuffer>> buffers;
Expand Down
8 changes: 7 additions & 1 deletion platform/cafe/source/modules/graphics_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void Graphics<Console::CAFE>::Clear(OptionalColor color, OptionalInt stencil, Op

if (stencil.has_value() && depth.has_value())
::Renderer::Instance().ClearDepthStencil(stencil.value(), 0xFF, depth.value());

if (color.has_value() && Shader<Console::CAFE>::current)
::Renderer::Instance().UseProgram(Shader<Console::CAFE>::current->GetGroup());
}

void Graphics<Console::CAFE>::Clear(std::vector<OptionalColor>& colors, OptionalInt stencil,
Expand All @@ -44,7 +47,10 @@ void Graphics<Console::CAFE>::Clear(std::vector<OptionalColor>& colors, Optional
int colorCount = colors.size();

if (colorCount == 0 || !stencil.has_value() || !depth.has_value())
this->Clear(colorCount > 0 ? colors[0] : Color {}, stencil, depth);
return;

if (stencil.has_value() || depth.has_value())
::Renderer::Instance().ClearDepthStencil(stencil.value(), 0xFF, depth.value());
}

void Graphics<Console::CAFE>::Present()
Expand Down
8 changes: 0 additions & 8 deletions platform/cafe/source/modules/keyboard_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ using namespace love;

Keyboard<Console::CAFE>::Keyboard() :
Keyboard<>(this->GetMaxEncodingLength(MAX_INPUT_LENGTH)),
state(nullptr),
createArgs {},
appearArgs {},
client(nullptr),
Expand All @@ -19,13 +18,6 @@ Keyboard<Console::CAFE>::Keyboard() :

void Keyboard<Console::CAFE>::Initialize()
{
this->state = (GX2ContextState*)memalign(GX2_CONTEXT_STATE_ALIGNMENT, sizeof(GX2ContextState));

if (!this->state)
throw love::Exception("Failed to allocate GX2ContextState for nn::swkbd!");

GX2SetupContextStateEx(this->state, false);

this->client = (FSClient*)MEMAllocFromDefaultHeap(sizeof(FSClient));

if (!this->client)
Expand Down
34 changes: 30 additions & 4 deletions platform/cafe/source/utilities/driver/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ Framebuffer::Framebuffer() :
scanBuffer(nullptr),
scanBufferSize(0),
width(0),
height(0)
height(0),
viewport {},
scissor {}
{}

Framebuffer::~Framebuffer()
{}
{
free(this->state);
this->state = nullptr;
}

void Framebuffer::Create(Screen screen)
{
Expand Down Expand Up @@ -204,6 +209,12 @@ void Framebuffer::SetSize(int width, int height)

this->InitColorBuffer();
this->InitDepthBuffer();

this->viewport = { 0, 0, width, height };
this->scissor = { 0, 0, width, height };

this->SetViewport();
this->SetScissor();
}

void Framebuffer::SetTVSize()
Expand All @@ -224,6 +235,22 @@ void Framebuffer::SetDRCSize()
GX2SetDRCScale(this->width, this->height);
}

void Framebuffer::SetViewport(const Rect& viewport)
{
if (viewport == Rect::EMPTY)
GX2SetViewport(0, 0, (float)this->width, (float)this->height, Z_NEAR, Z_FAR);
else
GX2SetViewport(viewport.x, viewport.y, viewport.w, viewport.h, Z_NEAR, Z_FAR);
}

void Framebuffer::SetScissor(const Rect& scissor)
{
if (scissor == Rect::EMPTY)
GX2SetScissor(0, 0, this->width, this->height);
else
GX2SetScissor(scissor.x, scissor.y, scissor.w, scissor.h);
}

void Framebuffer::SetProjection(const glm::highp_mat4& _projection)
{
/* glm::value_ptr lets us access the data linearly rather than an XxY matrix */
Expand All @@ -243,8 +270,7 @@ void Framebuffer::SetProjection(const glm::highp_mat4& _projection)

void Framebuffer::UseProjection()
{
GX2Invalidate(Framebuffer::INVALIDATE_UNIFORM, (void*)this->transform,
Framebuffer::TRANSFORM_SIZE);
GX2Invalidate(INVALIDATE_UNIFORM, (void*)this->transform, TRANSFORM_SIZE);

GX2SetVertexUniformBlock(1, Framebuffer::TRANSFORM_SIZE, (const void*)this->transform);
}
Loading

0 comments on commit e118cd7

Please sign in to comment.