Skip to content

Commit

Permalink
First OpenGL try
Browse files Browse the repository at this point in the history
  • Loading branch information
leiradel committed Mar 28, 2018
1 parent 925994d commit 1193d49
Show file tree
Hide file tree
Showing 12 changed files with 807 additions and 265 deletions.
80 changes: 32 additions & 48 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ bool Application::init(const char* title, int width, int height)
kAllocatorInited,
kSdlInited,
kWindowInited,
kRendererInited,
kAudioDeviceInited,
kFifoInited,
kAudioInited,
Expand Down Expand Up @@ -117,8 +116,16 @@ bool Application::init(const char* title, int width, int height)
inited = kSdlInited;

// Setup window
if (SDL_GL_LoadLibrary(NULL) != 0)
{
_logger.printf(RETRO_LOG_ERROR, "SDL_GL_LoadLibrary: %s", SDL_GetError());
goto error;
}

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

_window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

Expand All @@ -128,55 +135,24 @@ bool Application::init(const char* title, int width, int height)
goto error;
}

int major, minor;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
_logger.printf(RETRO_LOG_ERROR, "Got OpenGL %d.%d", major, minor);

inited = kWindowInited;

{
int numdrivers = SDL_GetNumRenderDrivers();
_logger.printf(RETRO_LOG_INFO, "Render driver count: %d", numdrivers);

for (int i = 0; i < numdrivers; i++)
SDL_GLContext context = SDL_GL_CreateContext(_window);

if (SDL_GL_MakeCurrent(_window, context) != 0)
{
SDL_RendererInfo drinfo;
SDL_GetRenderDriverInfo(i, &drinfo);

_logger.printf(RETRO_LOG_INFO, "Driver %d name: %s", i, drinfo.name);

if (drinfo.flags & SDL_RENDERER_SOFTWARE)
{
_logger.printf(RETRO_LOG_INFO, " the renderer is a software fallback");
}

if (drinfo.flags & SDL_RENDERER_ACCELERATED)
{
_logger.printf(RETRO_LOG_INFO, " the renderer uses hardware acceleration");
}

if (drinfo.flags & SDL_RENDERER_PRESENTVSYNC)
{
_logger.printf(RETRO_LOG_INFO, " present is synchronized with the refresh rate");
}

if (drinfo.flags & SDL_RENDERER_TARGETTEXTURE)
{
_logger.printf(RETRO_LOG_INFO, " the renderer supports rendering to texture");
}
_logger.printf(RETRO_LOG_ERROR, "SDL_GL_MakeCurrent: %s", SDL_GetError());
goto error;
}
}

_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_GL_SetSwapInterval(1);

if (_renderer == NULL)
{
_logger.printf(RETRO_LOG_ERROR, "SDL_CreateRenderer: %s", SDL_GetError());
goto error;
}
int major, minor;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
_logger.printf(RETRO_LOG_ERROR, "Got OpenGL %d.%d", major, minor);

inited = kRendererInited;
inited = kWindowInited;

// Init audio
SDL_AudioSpec want;
Expand Down Expand Up @@ -238,7 +214,7 @@ bool Application::init(const char* title, int width, int height)

inited = kKeyBindsInited;

if (!_video.init(&_logger, &_config, _renderer))
if (!_video.init(&_logger, &_config))
{
goto error;
}
Expand Down Expand Up @@ -285,7 +261,6 @@ bool Application::init(const char* title, int width, int height)
case kAudioInited: _audio.destroy();
case kFifoInited: _fifo.destroy();
case kAudioDeviceInited: SDL_CloseAudioDevice(_audioDev);
case kRendererInited: SDL_DestroyRenderer(_renderer);
case kWindowInited: SDL_DestroyWindow(_window);
case kSdlInited: SDL_Quit();
case kAllocatorInited: _allocator.destroy();
Expand Down Expand Up @@ -327,6 +302,10 @@ void Application::run()
case SDL_KEYDOWN:
handle(&event.key);
break;

case SDL_WINDOWEVENT:
handle(&event.window);
break;
}
}

Expand Down Expand Up @@ -370,9 +349,7 @@ void Application::run()
RA_DoAchievementsFrame();
}

SDL_RenderClear(_renderer);
_video.draw();
SDL_RenderPresent(_renderer);

RA_HandleHTTPResults();

Expand Down Expand Up @@ -435,7 +412,6 @@ void Application::destroy()
_fifo.destroy();

SDL_CloseAudioDevice(_audioDev);
SDL_DestroyRenderer(_renderer);
SDL_DestroyWindow(_window);
SDL_Quit();

Expand Down Expand Up @@ -1560,6 +1536,14 @@ void Application::handle(const SDL_SysWMEvent* syswm)
}
}

void Application::handle(const SDL_WindowEvent* window)
{
if (window->event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
_video.windowResized(window->data1, window->data2);
}
}

void Application::handle(const SDL_KeyboardEvent* key)
{
unsigned extra;
Expand Down
2 changes: 1 addition & 1 deletion src/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Application
void loadRecentList();
std::string serializeRecentList();
void handle(const SDL_SysWMEvent* syswm);
void handle(const SDL_WindowEvent* window);
void handle(const SDL_KeyboardEvent* key);

Fsm _fsm;
Expand All @@ -109,7 +110,6 @@ class Application
System _system;

SDL_Window* _window;
SDL_Renderer* _renderer;
SDL_AudioSpec _audioSpec;
SDL_AudioDeviceID _audioDev;

Expand Down
2 changes: 1 addition & 1 deletion src/Emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum class System
kPlayStation1 = PlayStation,
kNeoGeoPocket = NeoGeo,
kVirtualBoy = VirtualBoy,
kGameGear = Xbox360, //GameGear,
kGameGear = GameGear,
kArcade = Arcade,
kNintendo64 = N64
};
Expand Down
Loading

0 comments on commit 1193d49

Please sign in to comment.