21 unsigned width,
unsigned height,
29 inputEventGenerator_, cliComm_, videoSystem_)
31 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
32 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
33 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
34 #if OPENGL_VERSION == OPENGL_ES_2_0
35 #define VERSION_STRING "openGL ES 2.0"
36 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
37 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
38 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
39 #elif OPENGL_VERSION == OPENGL_2_1
40 #define VERSION_STRING "openGL 2.1"
41 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
42 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
43 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
44 #elif OPENGL_VERSION == OPENGL_3_3
45 #define VERSION_STRING "openGL 3.3"
46 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
47 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
48 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
51 int flags = SDL_WINDOW_OPENGL;
55 glContext = SDL_GL_CreateContext(
window.get());
72 glewExperimental = GL_TRUE;
75 GLenum glew_error = glewInit();
76 if (glew_error != GLEW_OK) {
78 "Failed to init GLEW: ",
79 reinterpret_cast<const char*
>(
80 glewGetErrorString(glew_error)));
84 setViewPort(
gl::ivec2(width, height), fullscreen);
91 vSyncObserver.update(
getDisplay().getRenderSettings().getVSyncSetting());
93 #if OPENGL_VERSION == OPENGL_3_3
97 glGenVertexArrays(1, &vao);
98 glBindVertexArray(vao);
107 SDL_GL_DeleteContext(glContext);
123 glReadPixels(
x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer.
data());
126 VLA(
const void*, rowPointers, h);
127 for (
auto i :
xrange(h)) {
128 uint8_t* out = &buffer[w * 4 * i];
129 const uint8_t* in = out;
130 rowPointers[h - 1 - i] = out;
132 for (
auto j :
xrange(w)) {
133 out[3 * j + 0] = in[4 * j + 0];
134 out[3 * j + 1] = in[4 * j + 1];
135 out[3 * j + 2] = in[4 * j + 2];
139 PNG::save(w, h, rowPointers,
filename);
144 SDL_GL_SwapWindow(
window.get());
149 return std::make_unique<GLSnow>(
getDisplay());
155 const bool openGL =
true;
157 return std::make_unique<OSDConsoleRenderer>(
158 reactor, console, width, height, openGL);
163 return std::make_unique<GLOSDGUILayer>(gui);
168 return std::make_unique<SDLGLOffScreenSurface>(*
this);
171 void SDLGLVisibleSurface::VSyncObserver::update(
const Setting&
setting) noexcept
174 auto& syncSetting = visSurface.getDisplay().getRenderSettings().getVSyncSetting();
179 int interval = syncSetting.getBoolean() ? -1 : 0;
181 if ((SDL_GL_SetSwapInterval(interval) < 0) && (interval == -1)) {
185 SDL_GL_SetSwapInterval(1);
189 void SDLGLVisibleSurface::setViewPort(
gl::ivec2 logicalSize,
bool fullscreen)
207 SDL_GL_GetDrawableSize(
window.get(), &w, &h);
216 glViewport(vx, vy, vw, vh);
Represents the output window/screen of openMSX.
RenderSettings & getRenderSettings()
Thrown when a subsystem initialisation fails.
const T * data() const
Returns pointer to the start of the memory buffer.
A frame buffer where pixels can be written to.
gl::ivec2 getLogicalSize() const
gl::ivec2 getViewOffset() const
void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize)
void setOpenGlPixelFormat()
gl::ivec2 getViewSize() const
Contains the main loop of openMSX.
BooleanSetting & getVSyncSetting()
VSync [on, off] ATM this only works when using the SDLGL-PP renderer.
bool getFullScreen() const
Visible surface for SDL openGL renderers.
~SDLGLVisibleSurface() override
void saveScreenshot(const std::string &filename) override
Save the content of this OutputSurface to a PNG file.
std::unique_ptr< Layer > createSnowLayer() override
std::unique_ptr< OutputSurface > createOffScreenSurface() override
Create an off-screen OutputSurface which has similar properties as this VisibleSurface.
std::unique_ptr< Layer > createConsoleLayer(Reactor &reactor, CommandConsole &console) override
std::unique_ptr< Layer > createOSDGUILayer(OSDGUI &gui) override
void fullScreenUpdated(bool fullscreen) override
void finish() override
When a complete frame is finished, call this method.
static void saveScreenshotGL(const OutputSurface &output, const std::string &filename)
SDLGLVisibleSurface(unsigned width, unsigned height, Display &display, RTScheduler &rtScheduler, EventDistributor &eventDistributor, InputEventGenerator &inputEventGenerator, CliComm &cliComm, VideoSystem &videoSystem)
Common functionality for the plain SDL and SDLGL VisibleSurface classes.
void createSurface(int width, int height, unsigned flags)
void detach(Observer< T > &observer)
void attach(Observer< T > &observer)
Display & getDisplay() const
std::optional< Context > context
This file implemented 3 utility functions:
constexpr const char *const filename
constexpr KeyMatrixPosition x
Keyboard bindings.
#define OUTER(type, member)
#define VLA(TYPE, NAME, LENGTH)
constexpr auto xrange(T e)