switch to software renderer if hardware not detected

This commit is contained in:
BADIM-PC\Vadim 2017-11-02 23:08:40 +03:00
parent 5c6d87525f
commit b43bfe06fb
3 changed files with 32 additions and 41 deletions

View File

@ -31,6 +31,8 @@ extern "C" {
#define TIC80_WIDTH 240
#define TIC80_HEIGHT 136
#define TIC80_FULLWIDTH 256
#define TIC80_FULLHEIGHT (TIC80_FULLWIDTH*9/16)
typedef struct
{
@ -47,15 +49,8 @@ typedef struct
s32 count;
} sound;
u32 screen[TIC80_WIDTH * TIC80_HEIGHT];
u32 border[TIC80_HEIGHT];
u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT];
struct
{
s8 x;
s8 y;
s8 rows[TIC80_HEIGHT];
} offset;
} tic80;
typedef union

View File

@ -47,7 +47,6 @@
#include "ext/md5.h"
#define STUDIO_UI_SCALE 3
#define STUDIO_UI_BORDER 16
#define MAX_CONTROLLERS 4
#define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
@ -78,6 +77,7 @@ static struct
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Renderer* softwareRenderer;
SDL_Texture* texture;
SDL_AudioSpec audioSpec;
@ -192,6 +192,7 @@ static struct
.window = NULL,
.renderer = NULL,
.softwareRenderer = NULL,
.texture = NULL,
.audioDevice = 0,
@ -2173,10 +2174,10 @@ static void tick()
SDL_SystemCursor cursor = studio.mouse.system;
studio.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
{
const u8* pal = (u8*)(paletteBlit() + tic_tool_peek4(studio.tic->ram.vram.mapping, studio.tic->ram.vram.vars.border & 0xf));
SDL_SetRenderDrawColor(studio.renderer, pal[2], pal[1], pal[0], SDL_ALPHA_OPAQUE);
}
// {
// const u8* pal = (u8*)(paletteBlit() + tic_tool_peek4(studio.tic->ram.vram.mapping, studio.tic->ram.vram.vars.border & 0xf));
// SDL_SetRenderDrawColor(studio.renderer, pal[2], pal[1], pal[0], SDL_ALPHA_OPAQUE);
// }
SDL_RenderClear(studio.renderer);
@ -2228,7 +2229,7 @@ static void initTouchGamepad()
if(!studio.gamepad.texture)
{
studio.gamepad.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING,
textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT));
textureLog2(TIC80_FULLWIDTH), textureLog2(TIC80_FULLHEIGHT));
SDL_SetTextureBlendMode(studio.gamepad.texture, SDL_BLENDMODE_BLEND);
}
@ -2327,8 +2328,8 @@ static void onFSInitialized(FileSystem* fs)
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
studio.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
(TIC80_WIDTH+STUDIO_UI_BORDER) * STUDIO_UI_SCALE,
(TIC80_HEIGHT+STUDIO_UI_BORDER) * STUDIO_UI_SCALE,
(TIC80_FULLWIDTH) * STUDIO_UI_SCALE,
(TIC80_FULLHEIGHT) * STUDIO_UI_SCALE,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
#if defined(__ARM_LINUX__)
| SDL_WINDOW_FULLSCREEN_DESKTOP
@ -2361,13 +2362,11 @@ static void onFSInitialized(FileSystem* fs)
// set the window icon before renderer is created (issues on Linux)
setWindowIcon();
#if defined(__ARM_LINUX__)
s32 renderFlags = SDL_RENDERER_SOFTWARE;
#else
s32 renderFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
#endif
studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(!studio.renderer)
studio.softwareRenderer = studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_SOFTWARE);
studio.renderer = SDL_CreateRenderer(studio.window, -1, renderFlags);
studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING,
textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT));
@ -2415,6 +2414,8 @@ s32 main(s32 argc, char **argv)
createFileSystem(onFSInitialized);
if(studio.softwareRenderer)
{
u64 nextTick = SDL_GetPerformanceCounter();
const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE;
@ -2429,7 +2430,9 @@ s32 main(s32 argc, char **argv)
SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency()));
else nextTick -= delay;
}
}
// TODO: check if window minimised
else while(!studio.quitFlag) tick();
#endif

View File

@ -139,19 +139,12 @@ static void blit(tic80* tic)
tic80_local* tic80 = (tic80_local*)tic;
u32* screen = tic->screen;
u32* border = tic->border;
tic->offset.x = tic80->memory->ram.vram.vars.offset.x;
tic->offset.y = tic80->memory->ram.vram.vars.offset.y;
for (s32 r = 0, pos = 0; r < TIC80_HEIGHT; r++, screen += TIC80_WIDTH)
{
tic80->memory->api.scanline(tic80->memory, r);
const u32* pal = paletteBlit(tic80->memory);
tic->offset.rows[r] = tic80->memory->ram.vram.vars.offset.x;
*border++ = pal[tic_tool_peek4(tic80->memory->ram.vram.mapping, tic80->memory->ram.vram.vars.border & 0xf)];
for (u32* ptr = screen, c = 0; c < TIC80_WIDTH; c++, ptr++)
*ptr = pal[tic_tool_peek4(tic80->memory->ram.vram.screen.data, pos++)];
}