Skip to content

Commit

Permalink
Add first NOT-WORKING (WIP) pass on OpenGL renderer in win32
Browse files Browse the repository at this point in the history
  • Loading branch information
JaceCear committed Jan 11, 2025
1 parent b132e62 commit 997dec5
Show file tree
Hide file tree
Showing 14 changed files with 604 additions and 373 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ ifeq ($(PLATFORM),sdl)
else ifeq ($(PLATFORM),sdl_win32)
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -lmingw32 -L$(ROOT_DIR)/$(SDL_MINGW_LIB) -lSDL2main -lSDL2.dll -lwinmm -lkernel32 -lxinput -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
else
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -lgdi32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -lgdi32 -lwinmm -lxinput -lopengl32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
endif
endif

Expand Down
11 changes: 9 additions & 2 deletions graphics.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ tileset_%.4bpp: tileset_%.png
tiles.8bpp: tiles.png
$(GFX) $< $@ -ignore_trailing

ifeq ($(PLATFORM),win32)
# For experimental OpenGL renderer
GFX_CVT_FLAGS :=
else
GFX_CVT_FLAGS := -split_into_oam_shapes
endif

graphics/obj_tiles/4bpp/%.4bpp: graphics/obj_tiles/4bpp/%.png
$(GFX) $< $@ -split_into_oam_shapes
$(GFX) $< $@ $(GFX_CVT_FLAGS)

graphics/obj_tiles/8bpp/%.8bpp: graphics/obj_tiles/8bpp/%.png
$(GFX) $< $@ -split_into_oam_shapes
$(GFX) $< $@ $(GFX_CVT_FLAGS)
10 changes: 10 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
#define TAS_TESTING 0
#define TAS_TESTING_WIDESCREEN_HACK 1

#define RENDERER_SOFTWARE 0
#define RENDERER_OPENGL 1
#define RENDERER_COUNT 2
#if PLATFORM_WIN32 && !PLATFORM_SDL
// TODO: Only win32 for now
#define RENDERER RENDERER_OPENGL
#else
#define RENDERER RENDERER_SOFTWARE
#endif

#endif // GUARD_SA2_CONFIG_H
8 changes: 8 additions & 0 deletions include/platform/shared/input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef GUARD_PLATFORM_SHARED_INPUT_H
#define GUARD_PLATFORM_SHARED_INPUT_H

#include "sprite.h" // for Sprite

u16 GetXInputKeys();

#endif // GUARD_PLATFORM_SHARED_INPUT_H
10 changes: 10 additions & 0 deletions include/platform/shared/opengl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef GUARD_PLATFORM_SHARED_OPENGL_H
#define GUARD_PLATFORM_SHARED_OPENGL_H

#include "sprite.h" // for Sprite

void OpenGL_OnInit();
void OpenGL_DisplaySprite(Sprite *sprite, u8 oamPaletteNum);
void OpenGL_Render(void *tempBufferPixels, int windowWidth, int windowHeight);

#endif // GUARD_PLATFORM_SHARED_OPENGL_H
9 changes: 9 additions & 0 deletions src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ NONMATCH("asm/non_matching/engine/sub_8002B20.inc", bool32 sub_8002B20(void))
s32 j;
u16 k;

#if (RENDERER == RENDERER_OPENGL)
// TEMP
return TRUE;
#endif

while (gBackgroundsCopyQueueCursor != gBackgroundsCopyQueueIndex) {
Background *bg;

Expand Down Expand Up @@ -626,6 +631,7 @@ END_NONMATCH

void UpdateBgAnimationTiles(Background *bg)
{
#if (RENDERER == RENDERER_SOFTWARE)
Tilemap *tilemap = gTilemapsRef[bg->tilemapId];
if (tilemap->animFrameCount > 0) {
if (tilemap->animDelay <= ++bg->animDelayCounter) {
Expand Down Expand Up @@ -660,6 +666,7 @@ void UpdateBgAnimationTiles(Background *bg)
}
}
}
#endif
}

// Differences to UpdateSpriteAnimation:
Expand Down Expand Up @@ -845,6 +852,7 @@ NONMATCH("asm/non_matching/engine/sub_80039E4.inc", bool32 sub_80039E4(void))
return TRUE;
#endif

#if (RENDERER == RENDERER_SOFTWARE)
if (gUnknown_03005390 != 0) {
OamDataShort oam;
s32 r5;
Expand Down Expand Up @@ -983,6 +991,7 @@ NONMATCH("asm/non_matching/engine/sub_80039E4.inc", bool32 sub_80039E4(void))

gUnknown_03005390 = 0;
}
#endif

return TRUE;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,9 @@ static bool32 ProcessVramGraphicsCopyQueue(void)
if ((graphics->src != 0) && (graphics->dest != 0))
#endif
{
#if (RENDERER != RENDERER_OPENGL)
DmaCopy16(3, (void *)(graphics->src + offset), (void *)(graphics->dest + offset), COPY_CHUNK_SIZE);
#endif
graphics->size -= COPY_CHUNK_SIZE;
}
#ifdef BUG_FIX
Expand All @@ -733,7 +735,9 @@ static bool32 ProcessVramGraphicsCopyQueue(void)
if ((graphics->src != 0) && (graphics->dest != 0))
#endif
{
#if (RENDERER != RENDERER_OPENGL)
DmaCopy16(3, (void *)(graphics->src + offset), (void *)(graphics->dest + offset), graphics->size);
#endif
}
graphics->size = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/game/interactables_2/egg_utopia/cannon.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ NONMATCH("asm/non_matching/game/interactables_2/egg_utopia/sub_807E66C.inc", sta
s32 biggerX, biggerY, temp2, temp3;
s32 r4;
s16 playerX, playerY;
#ifndef NON_MATCHING
register Sprite_Cannon *r3 asm("r3") = cannon;
#else
Sprite_Cannon *r3 = cannon;
#endif
Sprite *s2 = &r3->sprite2;
if (!PLAYER_IS_ALIVE) {
return 0;
Expand Down
55 changes: 1 addition & 54 deletions src/platform/pret_sdl/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gba/types.h"
#include "lib/agb_flash/flash_internal.h"
#include "platform/shared/dma.h"
#include "platform/shared/input.h"

#if ENABLE_AUDIO
#include "platform/shared/audio/cgb_audio.h"
Expand Down Expand Up @@ -494,60 +495,6 @@ void ProcessSDLEvents(void)
}
}

#ifdef _WIN32
#define STICK_THRESHOLD 0.5f
u16 GetXInputKeys()
{
XINPUT_STATE state;
ZeroMemory(&state, sizeof(XINPUT_STATE));

DWORD dwResult = XInputGetState(0, &state);
u16 xinputKeys = 0;

if (dwResult == ERROR_SUCCESS) {
/* A */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) >> 12;
/* B */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_X) >> 13;
/* Start */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) >> 1;
/* Select */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) >> 3;
/* L */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) << 1;
/* R */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) >> 1;
/* Up */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) << 6;
/* Down */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) << 6;
/* Left */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) << 3;
/* Right */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) << 1;

/* Control Stick */
float xAxis = (float)state.Gamepad.sThumbLX / (float)SHRT_MAX;
float yAxis = (float)state.Gamepad.sThumbLY / (float)SHRT_MAX;

if (xAxis < -STICK_THRESHOLD)
xinputKeys |= DPAD_LEFT;
else if (xAxis > STICK_THRESHOLD)
xinputKeys |= DPAD_RIGHT;
if (yAxis < -STICK_THRESHOLD)
xinputKeys |= DPAD_DOWN;
else if (yAxis > STICK_THRESHOLD)
xinputKeys |= DPAD_UP;

/* Speedup */
// Note: 'speedup' variable is only (un)set on keyboard input
double oldTimeScale = timeScale;
timeScale = (state.Gamepad.bRightTrigger > 0x80 || speedUp) ? 5.0 : 1.0;

if (oldTimeScale != timeScale) {
if (timeScale > 1.0) {
SDL_PauseAudio(1);
} else {
SDL_ClearQueuedAudio(1);
SDL_PauseAudio(0);
}
}
}

return xinputKeys;
}
#endif // _WIN32

u16 Platform_GetKeyInput(void)
{
#ifdef _WIN32
Expand Down
44 changes: 44 additions & 0 deletions src/platform/shared/input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifdef _WIN32
#include <windows.h>
#include <xinput.h>
#include "gba/io_reg.h"
#include "gba/types.h"

#define STICK_THRESHOLD 0.5f
u16 GetXInputKeys()
{
XINPUT_STATE state;
ZeroMemory(&state, sizeof(XINPUT_STATE));

DWORD dwResult = XInputGetState(0, &state);
u16 xinputKeys = 0;

if (dwResult == ERROR_SUCCESS) {
/* A */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) >> 12;
/* B */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_X) >> 13;
/* Start */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) >> 1;
/* Select */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) >> 3;
/* L */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) << 1;
/* R */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) >> 1;
/* Up */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) << 6;
/* Down */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) << 6;
/* Left */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) << 3;
/* Right */ xinputKeys |= (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) << 1;

/* Control Stick */
float xAxis = (float)state.Gamepad.sThumbLX / (float)SHRT_MAX;
float yAxis = (float)state.Gamepad.sThumbLY / (float)SHRT_MAX;

if (xAxis < -STICK_THRESHOLD)
xinputKeys |= DPAD_LEFT;
else if (xAxis > STICK_THRESHOLD)
xinputKeys |= DPAD_RIGHT;
if (yAxis < -STICK_THRESHOLD)
xinputKeys |= DPAD_DOWN;
else if (yAxis > STICK_THRESHOLD)
xinputKeys |= DPAD_UP;
}

return xinputKeys;
}
#endif // _WIN32
Loading

0 comments on commit 997dec5

Please sign in to comment.