]> git.bts.cx Git - benzene.git/blob - src_platform/playdate/bz/renderer/renderer.c
Sprites
[benzene.git] / src_platform / playdate / bz / renderer / renderer.c
1 #include <bz/renderer/renderer_internal.h>
2
3 #include <bz/gfx/gfx_internal.h>
4 #include <bz/math/math.h>
5 #include <bz/memory/arena.h>
6 #include <bz/renderer/render_pass_internal.h>
7 #include <playdate/entrypoint.h>
8
9 struct BZRendererPass {
10 size_t idx;
11 BZRenderPassID pass;
12 };
13
14 /*static SDL_Window *window;
15 static SDL_Renderer *renderer;
16 static SDL_Texture *renderTexture;
17 static SDL_Texture *renderTextureIntermediate;
18 static size_t intermediateWidth, intermediateHeight;
19 static int outputWidth, outputHeight;*/
20 //static SDL_Surface *windowSurface;
21 //static SDL_Surface *drawSurface;
22
23 //const static size_t kMaxRenderPasses = 8;
24 //static size_t numRenderPasses = 0;
25 #define kMaxRenderPasses 1 // FIXME
26 static BZRendererPass rendererPasses[kMaxRenderPasses];
27
28 #define GAME_WIDTH 200 // 256 //128 //320 //128 // 400 // 128
29 #define GAME_HEIGHT 120 // 128 //128 //180 //128 // 240 // 128
30
31 //#define RENDERER_WIDTH 256 //128 //320 //128 // 400 // 128
32 //#define RENDERER_HEIGHT 128 //128 //180 //128 // 240 // 128
33
34 #define RENDERER_WIDTH 400 // 1280
35 #define RENDERER_HEIGHT 240 // 720
36
37 #define SCREEN_WIDTH 400 * 1 // 1280
38 #define SCREEN_HEIGHT 240 * 1 // 720
39
40 //#define SCREEN_SCALE 4
41
42 void bzRendererInit() {//const BZRendererConfiguration *configuration, const char *title) {
43
44 for (size_t i = 0; i < kMaxRenderPasses; ++i) {
45 rendererPasses[i].pass = NULL;
46 }
47
48 prepare palettes
49 bzGfxPrepareCanvasBuffer(kBZSystemMemoryArena, GAME_WIDTH, GAME_HEIGHT);
50 }
51
52 void bzRendererTeardown() {
53 }
54
55 BZRendererPassID bzRendererRegisterPass(BZRenderPassID renderPass) {
56 for (size_t i = 0; i < kMaxRenderPasses; ++i) {
57 if (rendererPasses[i].pass == NULL) {
58 rendererPasses[i].pass = renderPass;
59 return &rendererPasses[i];
60 }
61 }
62 return NULL;
63 }
64
65 void bzRendererUnregisterPass(BZRendererPassID rendererPass) {
66 rendererPass->pass = NULL;
67 }
68
69 void bzRendererBlit() {
70 uint8_t *pixels = playdate->graphics->getFrame();
71 for (size_t i = 0; i < kMaxRenderPasses; ++i) {
72 BZRenderPass *renderPass = rendererPasses[i].pass;
73 if (renderPass != NULL) {
74 if (renderPass->softwareHook != NULL) {
75 renderPass->softwareHook((uint32_t *)pixels/*drawSurface->pixels*/, 2, 2);
76 }
77 }
78 }
79 }
80
81 void bzRendererVBlank() {
82 playdate->system->drawFPS(0,0);
83 playdate->graphics->markUpdatedRows(0, 240); // FIXME
84 }