Skip to content

Commit 04935b4

Browse files
committed
rendering: Adds SDL_gpu based rendering.
1 parent 54b04d0 commit 04935b4

File tree

13 files changed

+403
-24
lines changed

13 files changed

+403
-24
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "3rdparty/NaturalSort"]
55
path = 3rdparty/NaturalSort
66
url = https://github.com/scopeInfinity/NaturalSort.git
7+
[submodule "3rdparty/pbgl"]
8+
path = 3rdparty/pbgl
9+
url = https://github.com/abaire/pbgl.git
10+
[submodule "3rdparty/sdl-gpu"]
11+
path = 3rdparty/sdl-gpu
12+
url = https://github.com/abaire/sdl-gpu.git

3rdparty/pbgl

Submodule pbgl added at f47dd37

3rdparty/sdl-gpu

Submodule sdl-gpu added at fceafc0

Includes/font.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
#include <string>
55
#include <utility>
66
#include <vector>
7-
#include "3rdparty/SDL_FontCache/SDL_FontCache.h"
87
#include "renderer.hpp"
98

9+
// clang-format off
10+
#pragma clang diagnostic push
11+
#pragma clang diagnostic ignored "-Wunused-function"
12+
#include "3rdparty/SDL_FontCache/SDL_FontCache.h"
13+
#pragma clang diagnostic pop
14+
// clang-format on
15+
1016
class Font {
1117
private:
1218
FC_Font* fcFont;

Includes/renderer.hpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@
44
#include <SDL.h>
55
#include <vector>
66

7-
int min(int lhs, int rhs);
8-
int max(int lhs, int rhs);
7+
// clang-format off
8+
#ifdef FC_USE_SDL_GPU
9+
#pragma clang diagnostic push
10+
#pragma clang diagnostic ignored "-Wunused-function"
11+
#include "SDL_gpu.h"
12+
#pragma clang diagnostic pop
13+
#endif
14+
// clang-format on
15+
16+
#ifdef FC_USE_SDL_GPU
17+
typedef GPU_Image NX_Texture;
18+
typedef GPU_Rect NX_Rect;
19+
typedef GPU_Target NX_Target;
20+
#else
21+
typedef SDL_Texture NX_Texture;
22+
typedef SDL_Rect NX_Rect;
23+
typedef SDL_Renderer NX_Target;
24+
#endif
925

1026
class Renderer {
1127
public:
@@ -17,28 +33,35 @@ class Renderer {
1733
int clear();
1834
void flip();
1935

36+
#ifdef FC_USE_SDL_GPU
37+
GPU_Target* getRenderer() { return renderer; }
38+
#else
2039
SDL_Renderer* getRenderer() { return renderer; }
40+
#endif
2141
int getWidth() const { return width; }
2242
int getHeight() const { return height; }
2343

2444
int setDrawColor(uint8_t r = 0x40, uint8_t g = 0x40, uint8_t b = 0xE0, uint8_t a = 0x00);
2545

26-
void drawTexture(SDL_Texture* tex, SDL_Rect& src, SDL_Rect& dst);
27-
void drawTexture(SDL_Texture* tex, SDL_Rect& dst);
28-
void drawTexture(SDL_Texture* tex, int x, int y);
46+
void drawTexture(NX_Texture* tex, NX_Rect& src, NX_Rect& dst);
47+
void drawTexture(NX_Texture* tex, NX_Rect& dst);
48+
void drawTexture(NX_Texture* tex, int x, int y);
2949

30-
void fillRectangle(const SDL_Rect& dst);
50+
void fillRectangle(const NX_Rect& dst);
3151
void fillRectangle(const SDL_FRect& dst);
3252

3353
void blitSurface(SDL_Surface* bg, SDL_Surface* fg, int offset);
3454

3555
void drawBackground();
3656

3757
private:
38-
SDL_Renderer* renderer = nullptr;
58+
NX_Target* renderer = nullptr;
59+
NX_Texture* background = nullptr;
60+
3961
SDL_Window* window = nullptr;
40-
SDL_Texture* background = nullptr;
62+
#ifndef FC_USE_SDL_GPU
4163
Uint32 renderFlags = 0;
64+
#endif
4265
Uint32 windowFlags = 0;
4366

4467
int height = 0;
@@ -48,6 +71,10 @@ class Renderer {
4871
size_t menuItemCount = 0;
4972
size_t lowerHalf = 0;
5073
size_t upperHalf = 0;
74+
75+
#ifdef FC_USE_SDL_GPU
76+
SDL_Color drawColor;
77+
#endif
5178
};
5279

5380
#endif

Makefile

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ SRCS += \
2828
$(SRCDIR)/wipeCache.cpp \
2929
$(SRCDIR)/xbeLauncher.cpp \
3030
$(SRCDIR)/xbeScanner.cpp \
31+
$(CURDIR)/nxdk-sdl-gpu/nxdkSDLGPU.cpp \
3132
$(CURDIR)/3rdparty/SDL_FontCache/SDL_FontCache.c
3233

3334
NXDK_DIR ?= $(CURDIR)/../nxdk
@@ -38,21 +39,41 @@ NXDK_DISABLE_AUTOMOUNT_D = y
3839

3940
GEN_XISO = ${XBE_TITLE}.iso
4041

41-
CXXFLAGS += -I$(CURDIR) -I$(INCDIR) -Wall -Wextra -std=gnu++11
42-
CFLAGS += -std=gnu11
42+
CXXFLAGS += -I$(CURDIR) -I$(INCDIR) -I$(SDL_GPU_DIR)/include -I$(PBGL_DIR)/include -Wall -Wextra -std=gnu++11 -DFC_USE_SDL_GPU
43+
CFLAGS += -I$(SDL_GPU_DIR)/include -std=gnu11 -DFC_USE_SDL_GPU
4344

4445
ifneq ($(DEBUG),y)
4546
CFLAGS += -O2
4647
CXXFLAGS += -O2
4748
endif
4849

49-
new_all: copy_resources all
50+
CLEANRULES = clean-resources clean-gl
5051

5152
include $(NXDK_DIR)/Makefile
5253

53-
copy_resources: $(OUTPUT_DIR)/config.json
54-
@cp $(RESOURCEDIR)/480.png $(RESOURCEDIR)/720.png $(RESOURCEDIR)/vegur.ttf $(OUTPUT_DIR)
54+
override PBGL_DIR := 3rdparty/pbgl
55+
include 3rdparty/pbgl/Makefile
56+
57+
override SDL_GPU_DIR := 3rdparty/sdl-gpu
58+
include nxdk-sdl-gpu/Makefile.inc
59+
60+
RESOURCES = \
61+
$(OUTPUT_DIR)/config.json \
62+
$(OUTPUT_DIR)/480.png \
63+
$(OUTPUT_DIR)/720.png
64+
65+
TARGET += $(RESOURCES)
66+
$(GEN_XISO): $(RESOURCES)
5567

5668
$(OUTPUT_DIR)/config.json: $(CURDIR)/sampleconfig.json
5769
@mkdir -p $(OUTPUT_DIR)
5870
cp $(CURDIR)/sampleconfig.json $(OUTPUT_DIR)/config.json
71+
$(OUTPUT_DIR)/%: $(RESOURCEDIR)/%
72+
$(VE)cp -r '$<' '$@'
73+
74+
.PHONY: clean-resources
75+
clean-resources:
76+
$(VE)rm -rf $(OUTPUT_DIR)/NeXThemes
77+
78+
.PHONY: clean-gl
79+
clean-gl: clean-sdl-gpu clean-pbgl

Sources/font.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#include "font.hpp"
22
#include <cassert>
3-
#include "3rdparty/SDL_FontCache/SDL_FontCache.h"
4-
#include "infoLog.hpp"
3+
54

65
Font::Font(Renderer& renderer, const char* path) : renderer(renderer) {
76
fcFont = FC_CreateFont();
87
assert(fcFont);
8+
#ifdef FC_USE_SDL_GPU
9+
bool load_success = FC_LoadFont(fcFont, path, 20, FC_MakeColor(250, 250, 250, 255),
10+
TTF_STYLE_NORMAL);
11+
#else
912
bool load_success = FC_LoadFont(fcFont, renderer.getRenderer(), path, 20,
1013
FC_MakeColor(250, 250, 250, 255), TTF_STYLE_NORMAL);
14+
#endif
1115
assert(load_success);
1216
}
1317

Sources/menu.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
#include "settingsMenu.hpp"
66
#include "xbeLauncher.hpp"
77
#include "xbeScanner.hpp"
8+
#ifdef NXDK
9+
// clang-format off
10+
#ifdef FC_USE_SDL_GPU
11+
#pragma clang diagnostic push
12+
#pragma clang diagnostic ignored "-Wunused-function"
13+
#include "SDL_gpu.h"
14+
#pragma clang diagnostic pop
15+
#endif
16+
// clang-format on
17+
#endif
818

919
// Character used in the config.json to separate multiple path entries.
1020
#define PATH_DELIMITER ','
@@ -384,13 +394,20 @@ void Menu::render(Font& font) {
384394
dimensions = font.draw(menutext, coordinates);
385395

386396
if (i == this->currentMenu->getSelected()) {
397+
#ifdef FC_USE_SDL_GPU
398+
GPU_Rect rect = { std::get<0>(coordinates) - 10, std::get<1>(coordinates),
399+
std::get<0>(dimensions) + 20, std::get<1>(dimensions) };
400+
SDL_Color color = { 0xFF, 0xFF, 0xFF, 0xFF };
401+
GPU_Rectangle2(renderer.getRenderer(), rect, color);
402+
#else
387403
SDL_Rect rect;
388404
rect.w = std::get<0>(dimensions) + 20;
389405
rect.h = std::get<1>(dimensions);
390406
rect.x = std::get<0>(coordinates) - 10;
391407
rect.y = std::get<1>(coordinates);
392408
renderer.setDrawColor(0xFF, 0xFF, 0xFF, 0xFF);
393409
SDL_RenderDrawRect(renderer.getRenderer(), &rect);
410+
#endif
394411
}
395412

396413
coordinates = std::pair<float, float>(

0 commit comments

Comments
 (0)