Add SDL to power software backend

This commit is contained in:
Luke Benstead 2021-04-06 11:47:34 +01:00
parent 79c3ad74e7
commit cd4a7e0cf0
2 changed files with 36 additions and 5 deletions

View File

@ -30,6 +30,9 @@ set(
if(PLATFORM_DREAMCAST)
set(SOURCES ${SOURCES} GL/platforms/sh4.c)
else()
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
link_libraries(${SDL2_LIBRARIES})
set(SOURCES ${SOURCES} GL/platforms/x86.c)
endif()

View File

@ -1,3 +1,5 @@
#include <SDL.h>
#include <stdlib.h>
#include <string.h>
@ -7,8 +9,25 @@
static size_t AVAILABLE_VRAM = 16 * 1024 * 1024;
static Matrix4x4 MATRIX;
void InitGPU(_Bool autosort, _Bool fsaa) {
static VideoMode vid_mode = {
640, 480
};
void InitGPU(_Bool autosort, _Bool fsaa) {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window *window = SDL_CreateWindow(
"GLdc",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
vid_mode.width, vid_mode.height,
SDL_WINDOW_SHOWN
);
SDL_Renderer *renderer = SDL_CreateRenderer(
window, -1, SDL_RENDERER_ACCELERATED
);
}
void SceneBegin() {
@ -29,6 +48,18 @@ void SceneListFinish() {
void SceneFinish() {
/* Only sensible place to hook the quit signal */
SDL_Event e = {0};
while (SDL_PollEvent(&e))
switch (e.type) {
case SDL_QUIT:
exit(0);
break;
default:
break;
}
}
void UploadMatrix4x4(const Matrix4x4* mat) {
@ -43,10 +74,6 @@ void DownloadMatrix4x4(Matrix4x4* mat) {
memcpy(mat, &MATRIX, sizeof(Matrix4x4));
}
static VideoMode vid_mode = {
640, 480
};
const VideoMode* GetVideoMode() {
return &vid_mode;
}
@ -59,6 +86,7 @@ void* GPUMemoryAlloc(size_t size) {
if(size > AVAILABLE_VRAM) {
return NULL;
} else {
AVAILABLE_VRAM -= size;
return malloc(size);
}
}