2021-02-06 10:02:58 +00:00
|
|
|
#include "StdAfx.h"
|
2021-02-06 16:55:08 +00:00
|
|
|
#include "frontends/sdl/renderer/sdlrendererframe.h"
|
2021-02-06 10:02:58 +00:00
|
|
|
#include "frontends/sdl/utils.h"
|
|
|
|
#include "frontends/common2/programoptions.h"
|
|
|
|
|
|
|
|
#include "Interface.h"
|
|
|
|
#include "Core.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
SDLRendererFrame::SDLRendererFrame(const common2::EmulatorOptions & options)
|
2021-02-23 19:32:00 +00:00
|
|
|
: SDLFrame(options)
|
2021-02-06 10:02:58 +00:00
|
|
|
{
|
2021-02-25 16:04:50 +00:00
|
|
|
const common2::Geometry & geometry = options.geometry;
|
2021-02-20 15:21:53 +00:00
|
|
|
|
|
|
|
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, SDL_WINDOW_RESIZABLE), SDL_DestroyWindow);
|
2021-02-06 10:02:58 +00:00
|
|
|
if (!myWindow)
|
|
|
|
{
|
2021-02-06 16:55:08 +00:00
|
|
|
throw std::runtime_error(SDL_GetError());
|
2021-02-06 10:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetApplicationIcon();
|
|
|
|
|
|
|
|
myRenderer.reset(SDL_CreateRenderer(myWindow.get(), options.sdlDriver, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), SDL_DestroyRenderer);
|
|
|
|
if (!myRenderer)
|
|
|
|
{
|
2021-02-06 16:55:08 +00:00
|
|
|
throw std::runtime_error(SDL_GetError());
|
2021-02-06 10:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Uint32 format = SDL_PIXELFORMAT_ARGB8888;
|
|
|
|
printRendererInfo(std::cerr, myRenderer, format, options.sdlDriver);
|
|
|
|
|
2021-02-09 16:02:36 +00:00
|
|
|
Video & video = GetVideo();
|
|
|
|
|
|
|
|
const int width = video.GetFrameBufferWidth();
|
|
|
|
const int height = video.GetFrameBufferHeight();
|
|
|
|
const int sw = video.GetFrameBufferBorderlessWidth();
|
|
|
|
const int sh = video.GetFrameBufferBorderlessHeight();
|
|
|
|
|
2021-02-06 10:02:58 +00:00
|
|
|
myTexture.reset(SDL_CreateTexture(myRenderer.get(), format, SDL_TEXTUREACCESS_STATIC, width, height), SDL_DestroyTexture);
|
|
|
|
|
|
|
|
myRect.x = video.GetFrameBufferBorderWidth();
|
|
|
|
myRect.y = video.GetFrameBufferBorderHeight();
|
|
|
|
myRect.w = sw;
|
2021-02-07 14:00:45 +00:00
|
|
|
myRect.h = sh;
|
2021-02-06 10:02:58 +00:00
|
|
|
myPitch = width * sizeof(bgra_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDLRendererFrame::UpdateTexture()
|
|
|
|
{
|
|
|
|
SDL_UpdateTexture(myTexture.get(), nullptr, myFramebuffer.data(), myPitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDLRendererFrame::RenderPresent()
|
|
|
|
{
|
|
|
|
SDL_RenderCopyEx(myRenderer.get(), myTexture.get(), &myRect, nullptr, 0.0, nullptr, SDL_FLIP_VERTICAL);
|
|
|
|
SDL_RenderPresent(myRenderer.get());
|
|
|
|
}
|