mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
3DS: Set gfx render screen target directly
This commit is contained in:
parent
e91cc7cfd8
commit
475cb602ca
9 changed files with 49 additions and 74 deletions
|
@ -238,8 +238,14 @@ void Gfx_OnWindowResize(void);
|
|||
/* NOTE: Each line is separated by \n */
|
||||
void Gfx_GetApiInfo(cc_string* info);
|
||||
|
||||
void Gfx_3DS_DrawToTopScreen(void);
|
||||
void Gfx_3DS_DrawToBottomScreen(void);
|
||||
enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN };
|
||||
#ifdef CC_BUILD_DUALSCREEN
|
||||
/* Selects which screen on the 3DS to render to */
|
||||
void Gfx_3DS_SetRenderScreen(enum Screen3DS screen);
|
||||
#else
|
||||
static inline
|
||||
void Gfx_3DS_SetRenderScreen(enum Screen3DS screen) { }
|
||||
#endif
|
||||
|
||||
/* Raises ContextLost event and updates state for lost contexts */
|
||||
void Gfx_LoseContext(const char* reason);
|
||||
|
@ -283,4 +289,4 @@ void Gfx_RestoreAlphaState(cc_uint8 draw);
|
|||
void Texture_Render(const struct Texture* tex);
|
||||
/* Binds then renders the given texture */
|
||||
void Texture_RenderShaded(const struct Texture* tex, PackedCol shadeColor);
|
||||
#endif
|
||||
#endif
|
|
@ -181,12 +181,8 @@ void Gfx_FreeState(void) {
|
|||
Gfx_DeleteTexture(&white_square);
|
||||
}
|
||||
|
||||
void Gfx_3DS_DrawToTopScreen(void) {
|
||||
C3D_FrameDrawOn(topTarget);
|
||||
}
|
||||
|
||||
void Gfx_3DS_DrawToBottomScreen(void) {
|
||||
C3D_FrameDrawOn(bottomTarget);
|
||||
void Gfx_3DS_SetRenderScreen(enum Screen3DS screen) {
|
||||
C3D_FrameDrawOn(screen == TOP_SCREEN ? topTarget : bottomTarget);
|
||||
}
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
@ -375,8 +371,8 @@ void Gfx_BeginFrame(void) {
|
|||
}
|
||||
|
||||
void Gfx_Clear(void) {
|
||||
C3D_RenderTargetClear(topTarget, C3D_CLEAR_ALL, clear_color, 0);
|
||||
C3D_RenderTargetClear(bottomTarget, C3D_CLEAR_ALL, 0, 0);
|
||||
C3D_RenderTargetClear(topTarget, C3D_CLEAR_ALL, clear_color, 0);
|
||||
C3D_RenderTargetClear(bottomTarget, C3D_CLEAR_ALL, 0, 0);
|
||||
}
|
||||
|
||||
void Gfx_EndFrame(void) {
|
||||
|
@ -797,4 +793,4 @@ void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol color) {
|
|||
C3D_ImmSendAttrib(v[0].U, v[0].V, 0.0f, 0.0f);
|
||||
C3D_ImmDrawEnd();
|
||||
}
|
||||
#endif
|
||||
#endif
|
13
src/Gui.c
13
src/Gui.c
|
@ -190,15 +190,11 @@ static void Gui_AddCore(struct Screen* s, int priority) {
|
|||
s->VTABLE->ContextRecreated(s);
|
||||
s->VTABLE->Layout(s);
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
/* for selecting active button etc */
|
||||
for (i = 0; i < Pointers_Count; i++)
|
||||
{
|
||||
s->VTABLE->HandlesPointerMove(s, i, Pointers[i].x, Pointers[i].y);
|
||||
}
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
}
|
||||
|
||||
/* Returns index of the given screen in the screens list, -1 if not */
|
||||
|
@ -293,8 +289,7 @@ void Gui_RenderGui(double delta) {
|
|||
struct Screen* s;
|
||||
int i;
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
#ifdef CC_BUILD_DUALSCREEN
|
||||
Texture_Render(&touchBgTex);
|
||||
#endif
|
||||
|
@ -309,7 +304,7 @@ void Gui_RenderGui(double delta) {
|
|||
s->VTABLE->Render(s, delta);
|
||||
}
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
Gfx_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
}
|
||||
|
||||
|
||||
|
@ -477,7 +472,6 @@ int Screen_DoPointerDown(void* screen, int id, int x, int y) {
|
|||
struct Screen* s = (struct Screen*)screen;
|
||||
struct Widget** widgets = s->widgets;
|
||||
int i, count = s->numWidgets;
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
/* iterate backwards (because last elements rendered are shown over others) */
|
||||
for (i = count - 1; i >= 0; i--)
|
||||
|
@ -493,9 +487,6 @@ int Screen_DoPointerDown(void* screen, int id, int x, int y) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
|
@ -541,15 +541,17 @@ static void DrawTitleText(struct FontDesc* font, const char* text, struct Contex
|
|||
}
|
||||
|
||||
#ifdef CC_BUILD_DUALSCREEN
|
||||
extern cc_bool launcherTop;
|
||||
|
||||
void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2D* ctx) {
|
||||
/* Put title on top screen */
|
||||
Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
struct Context2D topCtx;
|
||||
struct Bitmap bmp;
|
||||
launcherTop = true;
|
||||
|
||||
ctx = &topCtx;
|
||||
bmp.width = max(Window_Main.Width, 1);
|
||||
bmp.height = max(Window_Main.Height, 1);
|
||||
bmp.width = Window_Alt.Width;
|
||||
bmp.height = Window_Alt.Height;
|
||||
Window_AllocFramebuffer(&bmp);
|
||||
Context2D_Wrap(ctx, &bmp);
|
||||
|
||||
|
@ -558,8 +560,8 @@ void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2
|
|||
Rect2D rect = { 0, 0, bmp.width, bmp.height };
|
||||
Window_DrawFramebuffer(rect, &bmp);
|
||||
|
||||
Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
Window_FreeFramebuffer(&bmp);
|
||||
launcherTop = false;
|
||||
}
|
||||
#else
|
||||
void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2D* ctx) {
|
||||
|
|
|
@ -79,7 +79,7 @@ static void Menu_RenderBounds(void) {
|
|||
Then using wolfram alpha to solve the glblendfunc equation */
|
||||
PackedCol topCol = PackedCol_Make(24, 24, 24, 105);
|
||||
PackedCol bottomCol = PackedCol_Make(51, 51, 98, 162);
|
||||
Gfx_Draw2DGradient(0, 0, Window_Main.Width, Window_Main.Height, topCol, bottomCol);
|
||||
Gfx_Draw2DGradient(0, 0, Window_UI.Width, Window_UI.Height, topCol, bottomCol);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -293,7 +293,6 @@ static void HUDScreen_Init(void* screen) {
|
|||
TextWidget_Init(&s->line1);
|
||||
TextWidget_Init(&s->line2);
|
||||
|
||||
s->hotbar.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->line1.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->line2.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
|
||||
|
@ -342,9 +341,9 @@ static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) {
|
|||
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/64.0f) };
|
||||
int extent;
|
||||
|
||||
extent = (int)(CH_EXTENT * Gui_Scale(Window_UI.Height / 480.0f));
|
||||
tex.x = (Window_UI.Width / 2) - extent;
|
||||
tex.y = (Window_UI.Height / 2) - extent;
|
||||
extent = (int)(CH_EXTENT * Gui_Scale(Window_Main.Height / 480.0f));
|
||||
tex.x = (Window_Main.Width / 2) - extent;
|
||||
tex.y = (Window_Main.Height / 2) - extent;
|
||||
|
||||
tex.Width = extent * 2;
|
||||
tex.Height = extent * 2;
|
||||
|
@ -373,7 +372,7 @@ static void HUDScreen_Render(void* screen, double delta) {
|
|||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
if (Game_HideGui) return;
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
Gfx_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
|
||||
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
||||
Gfx_BindDynamicVb(s->vb);
|
||||
|
@ -399,7 +398,7 @@ static void HUDScreen_Render(void* screen, double delta) {
|
|||
}
|
||||
}
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
}
|
||||
|
||||
static const struct ScreenVTABLE HUDScreen_VTABLE = {
|
||||
|
@ -814,7 +813,7 @@ static void TabListOverlay_Render(void* screen, double delta) {
|
|||
|
||||
if (Game_HideGui || !IsOnlyChatActive()) return;
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
Gfx_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
|
||||
Gfx_Draw2DGradient(s->x, s->y, s->width, s->height, topCol, bottomCol);
|
||||
|
||||
|
@ -831,7 +830,7 @@ static void TabListOverlay_Render(void* screen, double delta) {
|
|||
offset += 4;
|
||||
}
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
}
|
||||
|
||||
static void TabListOverlay_Free(void* screen) {
|
||||
|
@ -1166,11 +1165,11 @@ static void ChatScreen_DrawChat(struct ChatScreen* s, double delta) {
|
|||
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
if (!Input_TouchMode) return;
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
Elem_Render(&s->more, delta);
|
||||
Elem_Render(&s->send, delta);
|
||||
Elem_Render(&s->cancel, delta);
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
Gfx_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -1485,7 +1484,7 @@ static void ChatScreen_Init(void* screen) {
|
|||
|
||||
static void ChatScreen_Render(void* screen, double delta) {
|
||||
struct ChatScreen* s = (struct ChatScreen*)screen;
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
Gfx_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
|
||||
if (Game_HideGui && s->grabsInput) {
|
||||
Elem_Render(&s->input.base, delta);
|
||||
|
@ -1497,7 +1496,7 @@ static void ChatScreen_Render(void* screen, double delta) {
|
|||
|
||||
ChatScreen_DrawChat(s, delta);
|
||||
}
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
}
|
||||
|
||||
static void ChatScreen_Free(void* screen) {
|
||||
|
@ -2130,7 +2129,7 @@ static void DisconnectScreen_Update(void* screen, double delta) {
|
|||
static void DisconnectScreen_Render(void* screen, double delta) {
|
||||
PackedCol top = PackedCol_Make(64, 32, 32, 255);
|
||||
PackedCol bottom = PackedCol_Make(80, 16, 16, 255);
|
||||
Gfx_Draw2DGradient(0, 0, Window_Main.Width, Window_Main.Height, top, bottom);
|
||||
Gfx_Draw2DGradient(0, 0, Window_UI.Width, Window_UI.Height, top, bottom);
|
||||
|
||||
Screen_Render2Widgets(screen, delta);
|
||||
}
|
||||
|
|
|
@ -448,7 +448,7 @@ static void HotbarWidget_RenderEntries(struct HotbarWidget* w, int offset) {
|
|||
}
|
||||
|
||||
static int HotbarWidget_Render2(void* widget, int offset) {
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
struct HotbarWidget* w = (struct HotbarWidget*)widget;
|
||||
HotbarWidget_RenderOutline(w, offset );
|
||||
|
@ -462,7 +462,7 @@ static int HotbarWidget_Render2(void* widget, int offset) {
|
|||
}
|
||||
#endif
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
Gfx_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
return HOTBAR_MAX_VERTICES;
|
||||
}
|
||||
|
||||
|
|
11
src/Window.h
11
src/Window.h
|
@ -235,13 +235,4 @@ void GLContext_SetFpsLimit(cc_bool vsync, float minFrameMs);
|
|||
void GLContext_GetApiInfo(cc_string* info);
|
||||
#endif
|
||||
|
||||
enum Screen3DS { TOP_SCREEN, BOTTOM_SCREEN };
|
||||
#ifdef CC_BUILD_DUALSCREEN
|
||||
/* Selects which screen on the 3DS to render to. Returns the previous screen */
|
||||
enum Screen3DS Window_3DS_SetRenderScreen(enum Screen3DS screen);
|
||||
#else
|
||||
static inline
|
||||
enum Screen3DS Window_3DS_SetRenderScreen(enum Screen3DS screen) { return TOP_SCREEN; }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -14,13 +14,13 @@
|
|||
|
||||
static cc_bool launcherMode;
|
||||
static Result irrst_result;
|
||||
static enum Screen3DS renderScreen = TOP_SCREEN;
|
||||
static u16 top_width, top_height;
|
||||
static u16 btm_width, btm_height;
|
||||
|
||||
struct _DisplayData DisplayInfo;
|
||||
struct _WindowData WindowInfo;
|
||||
struct _WindowData Window_Alt;
|
||||
cc_bool launcherTop;
|
||||
|
||||
// Note from https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/gfx.h
|
||||
// * Please note that the 3DS uses *portrait* screens rotated 90 degrees counterclockwise.
|
||||
|
@ -54,28 +54,18 @@ void Window_Init(void) {
|
|||
|
||||
void Window_Free(void) { irrstExit(); }
|
||||
|
||||
enum Screen3DS Window_3DS_SetRenderScreen(enum Screen3DS screen) {
|
||||
enum Screen3DS prev = renderScreen;
|
||||
if (screen != prev)
|
||||
{
|
||||
renderScreen = screen;
|
||||
DisplayInfo.Width = (screen == TOP_SCREEN) ? 400 : 320;
|
||||
WindowInfo.Width = DisplayInfo.Width;
|
||||
if (screen == TOP_SCREEN)
|
||||
Gfx_3DS_DrawToTopScreen();
|
||||
else
|
||||
Gfx_3DS_DrawToBottomScreen();
|
||||
}
|
||||
return prev;
|
||||
void Window_Create2D(int width, int height) {
|
||||
DisplayInfo.Width = btm_width;
|
||||
Window_Main.Width = btm_width;
|
||||
Window_Alt.Width = top_width;
|
||||
launcherMode = true;
|
||||
}
|
||||
|
||||
void Window_Create2D(int width, int height) {
|
||||
Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
launcherMode = true;
|
||||
}
|
||||
void Window_Create3D(int width, int height) {
|
||||
Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
launcherMode = false;
|
||||
DisplayInfo.Width = top_width;
|
||||
Window_Main.Width = top_width;
|
||||
Window_Alt.Width = btm_width;
|
||||
launcherMode = false;
|
||||
}
|
||||
|
||||
void Window_SetTitle(const cc_string* title) { }
|
||||
|
@ -190,7 +180,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) {
|
|||
|
||||
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
|
||||
u16 width, height;
|
||||
gfxScreen_t screen = (renderScreen == TOP_SCREEN) ? GFX_TOP : GFX_BOTTOM;
|
||||
gfxScreen_t screen = launcherTop ? GFX_TOP : GFX_BOTTOM;
|
||||
|
||||
gfxSetDoubleBuffering(screen, false);
|
||||
u8* fb = gfxGetFramebuffer(screen, GFX_LEFT, &width, &height);
|
||||
|
|
Loading…
Reference in a new issue