21#define GL_GLEXT_PROTOTYPES
23# define GL_SILENCE_DEPRECATION
24# include <OpenGL/gl3.h>
28#include "../3rdparty/opengl/glext.h"
49#define GL(function) static decltype(&function) _ ## function
54GL(glDebugMessageControl);
55GL(glDebugMessageCallback);
84GL(glClearBufferSubData);
93GL(glDeleteVertexArrays);
101GL(glGetProgramInfoLog);
108GL(glGetShaderInfoLog);
109GL(glGetUniformLocation);
115GL(glGetAttribLocation);
116GL(glEnableVertexAttribArray);
117GL(glDisableVertexAttribArray);
118GL(glVertexAttribPointer);
119GL(glBindFragDataLocation);
135GetOGLProcAddressProc GetOGLProcAddress;
137static std::optional<std::string_view> GlGetString(GLenum name)
139 auto str =
reinterpret_cast<const char *
>(_glGetString(name));
140 if (str ==
nullptr)
return {};
168 static PFNGLGETSTRINGIPROC glGetStringi =
nullptr;
169 static bool glGetStringi_loaded =
false;
173 if (!glGetStringi_loaded) {
175 glGetStringi_loaded =
true;
178 if (glGetStringi !=
nullptr) {
181 _glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts);
183 for (GLint i = 0; i < num_exts; i++) {
184 const char *entry =
reinterpret_cast<const char *
>(glGetStringi(GL_EXTENSIONS, i));
185 if (entry !=
nullptr && entry == extension)
return true;
187 }
else if (
auto str = GlGetString(GL_EXTENSIONS); str.has_value()) {
220 f =
reinterpret_cast<F
>(GetOGLProcAddress(name));
230 if (!
BindGLProc(_glGetString,
"glGetString"))
return false;
231 if (!
BindGLProc(_glGetIntegerv,
"glGetIntegerv"))
return false;
232 if (!
BindGLProc(_glGetError,
"glGetError"))
return false;
243 if (!
BindGLProc(_glDisable,
"glDisable"))
return false;
244 if (!
BindGLProc(_glEnable,
"glEnable"))
return false;
245 if (!
BindGLProc(_glViewport,
"glViewport"))
return false;
246 if (!
BindGLProc(_glTexImage1D,
"glTexImage1D"))
return false;
247 if (!
BindGLProc(_glTexImage2D,
"glTexImage2D"))
return false;
248 if (!
BindGLProc(_glTexParameteri,
"glTexParameteri"))
return false;
249 if (!
BindGLProc(_glTexSubImage1D,
"glTexSubImage1D"))
return false;
250 if (!
BindGLProc(_glTexSubImage2D,
"glTexSubImage2D"))
return false;
251 if (!
BindGLProc(_glBindTexture,
"glBindTexture"))
return false;
252 if (!
BindGLProc(_glDeleteTextures,
"glDeleteTextures"))
return false;
253 if (!
BindGLProc(_glGenTextures,
"glGenTextures"))
return false;
254 if (!
BindGLProc(_glPixelStorei,
"glPixelStorei"))
return false;
255 if (!
BindGLProc(_glClear,
"glClear"))
return false;
256 if (!
BindGLProc(_glClearColor,
"glClearColor"))
return false;
257 if (!
BindGLProc(_glBlendFunc,
"glBlendFunc"))
return false;
258 if (!
BindGLProc(_glDrawArrays,
"glDrawArrays"))
return false;
270 if (!
BindGLProc(_glActiveTexture,
"glActiveTexture"))
return false;
272 if (!
BindGLProc(_glActiveTexture,
"glActiveTextureARB"))
return false;
285 if (!
BindGLProc(_glGenBuffers,
"glGenBuffers"))
return false;
286 if (!
BindGLProc(_glDeleteBuffers,
"glDeleteBuffers"))
return false;
287 if (!
BindGLProc(_glBindBuffer,
"glBindBuffer"))
return false;
288 if (!
BindGLProc(_glBufferData,
"glBufferData"))
return false;
289 if (!
BindGLProc(_glBufferSubData,
"glBufferSubData"))
return false;
290 if (!
BindGLProc(_glMapBuffer,
"glMapBuffer"))
return false;
291 if (!
BindGLProc(_glUnmapBuffer,
"glUnmapBuffer"))
return false;
293 if (!
BindGLProc(_glGenBuffers,
"glGenBuffersARB"))
return false;
294 if (!
BindGLProc(_glDeleteBuffers,
"glDeleteBuffersARB"))
return false;
295 if (!
BindGLProc(_glBindBuffer,
"glBindBufferARB"))
return false;
296 if (!
BindGLProc(_glBufferData,
"glBufferDataARB"))
return false;
297 if (!
BindGLProc(_glBufferSubData,
"glBufferSubDataARB"))
return false;
298 if (!
BindGLProc(_glMapBuffer,
"glMapBufferARB"))
return false;
299 if (!
BindGLProc(_glUnmapBuffer,
"glUnmapBufferARB"))
return false;
303 BindGLProc(_glClearBufferSubData,
"glClearBufferSubData");
305 _glClearBufferSubData =
nullptr;
321 if (!
BindGLProc(_glGenVertexArrays,
"glGenVertexArrays"))
return false;
322 if (!
BindGLProc(_glDeleteVertexArrays,
"glDeleteVertexArrays"))
return false;
323 if (!
BindGLProc(_glBindVertexArray,
"glBindVertexArray"))
return false;
325 if (!
BindGLProc(_glGenVertexArrays,
"glGenVertexArraysAPPLE"))
return false;
326 if (!
BindGLProc(_glDeleteVertexArrays,
"glDeleteVertexArraysAPPLE"))
return false;
327 if (!
BindGLProc(_glBindVertexArray,
"glBindVertexArrayAPPLE"))
return false;
340 if (!
BindGLProc(_glCreateProgram,
"glCreateProgram"))
return false;
341 if (!
BindGLProc(_glDeleteProgram,
"glDeleteProgram"))
return false;
342 if (!
BindGLProc(_glLinkProgram,
"glLinkProgram"))
return false;
343 if (!
BindGLProc(_glUseProgram,
"glUseProgram"))
return false;
344 if (!
BindGLProc(_glGetProgramiv,
"glGetProgramiv"))
return false;
345 if (!
BindGLProc(_glGetProgramInfoLog,
"glGetProgramInfoLog"))
return false;
346 if (!
BindGLProc(_glCreateShader,
"glCreateShader"))
return false;
347 if (!
BindGLProc(_glDeleteShader,
"glDeleteShader"))
return false;
348 if (!
BindGLProc(_glShaderSource,
"glShaderSource"))
return false;
349 if (!
BindGLProc(_glCompileShader,
"glCompileShader"))
return false;
350 if (!
BindGLProc(_glAttachShader,
"glAttachShader"))
return false;
351 if (!
BindGLProc(_glGetShaderiv,
"glGetShaderiv"))
return false;
352 if (!
BindGLProc(_glGetShaderInfoLog,
"glGetShaderInfoLog"))
return false;
353 if (!
BindGLProc(_glGetUniformLocation,
"glGetUniformLocation"))
return false;
354 if (!
BindGLProc(_glUniform1i,
"glUniform1i"))
return false;
355 if (!
BindGLProc(_glUniform1f,
"glUniform1f"))
return false;
356 if (!
BindGLProc(_glUniform2f,
"glUniform2f"))
return false;
357 if (!
BindGLProc(_glUniform4f,
"glUniform4f"))
return false;
359 if (!
BindGLProc(_glGetAttribLocation,
"glGetAttribLocation"))
return false;
360 if (!
BindGLProc(_glEnableVertexAttribArray,
"glEnableVertexAttribArray"))
return false;
361 if (!
BindGLProc(_glDisableVertexAttribArray,
"glDisableVertexAttribArray"))
return false;
362 if (!
BindGLProc(_glVertexAttribPointer,
"glVertexAttribPointer"))
return false;
365 if (!
BindGLProc(_glCreateProgram,
"glCreateProgramObjectARB"))
return false;
366 if (!
BindGLProc(_glDeleteProgram,
"glDeleteObjectARB"))
return false;
367 if (!
BindGLProc(_glLinkProgram,
"glLinkProgramARB"))
return false;
368 if (!
BindGLProc(_glUseProgram,
"glUseProgramObjectARB"))
return false;
369 if (!
BindGLProc(_glGetProgramiv,
"glGetObjectParameterivARB"))
return false;
370 if (!
BindGLProc(_glGetProgramInfoLog,
"glGetInfoLogARB"))
return false;
371 if (!
BindGLProc(_glCreateShader,
"glCreateShaderObjectARB"))
return false;
372 if (!
BindGLProc(_glDeleteShader,
"glDeleteObjectARB"))
return false;
373 if (!
BindGLProc(_glShaderSource,
"glShaderSourceARB"))
return false;
374 if (!
BindGLProc(_glCompileShader,
"glCompileShaderARB"))
return false;
375 if (!
BindGLProc(_glAttachShader,
"glAttachObjectARB"))
return false;
376 if (!
BindGLProc(_glGetShaderiv,
"glGetObjectParameterivARB"))
return false;
377 if (!
BindGLProc(_glGetShaderInfoLog,
"glGetInfoLogARB"))
return false;
378 if (!
BindGLProc(_glGetUniformLocation,
"glGetUniformLocationARB"))
return false;
379 if (!
BindGLProc(_glUniform1i,
"glUniform1iARB"))
return false;
380 if (!
BindGLProc(_glUniform1f,
"glUniform1fARB"))
return false;
381 if (!
BindGLProc(_glUniform2f,
"glUniform2fARB"))
return false;
382 if (!
BindGLProc(_glUniform4f,
"glUniform4fARB"))
return false;
384 if (!
BindGLProc(_glGetAttribLocation,
"glGetAttribLocationARB"))
return false;
385 if (!
BindGLProc(_glEnableVertexAttribArray,
"glEnableVertexAttribArrayARB"))
return false;
386 if (!
BindGLProc(_glDisableVertexAttribArray,
"glDisableVertexAttribArrayARB"))
return false;
387 if (!
BindGLProc(_glVertexAttribPointer,
"glVertexAttribPointerARB"))
return false;
392 BindGLProc(_glBindFragDataLocation,
"glBindFragDataLocation");
394 BindGLProc(_glBindFragDataLocation,
"glBindFragDataLocationEXT");
396 _glBindFragDataLocation =
nullptr;
410 if (!
BindGLProc(_glMapBufferRange,
"glMapBufferRange"))
return false;
413 if (!
BindGLProc(_glBufferStorage,
"glBufferStorage"))
return false;
415#ifndef NO_GL_BUFFER_SYNC
417 if (!
BindGLProc(_glClientWaitSync,
"glClientWaitSync"))
return false;
418 if (!
BindGLProc(_glFenceSync,
"glFenceSync"))
return false;
419 if (!
BindGLProc(_glDeleteSync,
"glDeleteSync"))
return false;
432void APIENTRY
DebugOutputCallback(GLenum, GLenum type, GLuint, GLenum severity, GLsizei,
const GLchar *message,
const void *)
435 std::string_view severity_str;
437 case GL_DEBUG_SEVERITY_HIGH: severity_str =
"high";
break;
438 case GL_DEBUG_SEVERITY_MEDIUM: severity_str =
"medium";
break;
439 case GL_DEBUG_SEVERITY_LOW: severity_str =
"low";
break;
443 std::string_view type_str =
"Other";
445 case GL_DEBUG_TYPE_ERROR: type_str =
"Error";
break;
446 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: type_str =
"Deprecated";
break;
447 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: type_str =
"Undefined behaviour";
break;
448 case GL_DEBUG_TYPE_PERFORMANCE: type_str =
"Performance";
break;
449 case GL_DEBUG_TYPE_PORTABILITY: type_str =
"Portability";
break;
458#ifndef NO_DEBUG_MESSAGES
462 BindGLProc(_glDebugMessageControl,
"glDebugMessageControl");
463 BindGLProc(_glDebugMessageCallback,
"glDebugMessageCallback");
465 BindGLProc(_glDebugMessageControl,
"glDebugMessageControlARB");
466 BindGLProc(_glDebugMessageCallback,
"glDebugMessageCallbackARB");
469 if (_glDebugMessageControl !=
nullptr && _glDebugMessageCallback !=
nullptr) {
471 _glEnable(GL_DEBUG_OUTPUT);
478 _glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_ERROR, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
479 _glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
480 _glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
495 GetOGLProcAddress = get_proc;
522 if (_glDeleteProgram !=
nullptr) {
528 if (_glDeleteVertexArrays !=
nullptr) _glDeleteVertexArrays(1, &this->
vao_quad);
529 if (_glDeleteBuffers !=
nullptr) {
530 _glDeleteBuffers(1, &this->
vbo_quad);
531 _glDeleteBuffers(1, &this->
vid_pbo);
532 _glDeleteBuffers(1, &this->
anim_pbo);
534 if (_glDeleteTextures !=
nullptr) {
544static std::tuple<uint8_t, uint8_t> DecodeVersion(std::string_view ver)
562 auto ver = GlGetString(GL_VERSION);
563 auto vend = GlGetString(GL_VENDOR);
564 auto renderer = GlGetString(GL_RENDERER);
566 if (!ver.has_value() || !vend.has_value() || !renderer.has_value())
return "OpenGL not supported";
570#ifndef GL_ALLOW_SOFTWARE_RENDERER
573 if (renderer->starts_with(
"llvmpipe") || renderer->starts_with(
"softpipe"))
return "Software renderer detected, not using OpenGL";
606 if (
IsOpenGLVersionAtLeast(3, 2) && _glBindFragDataLocation ==
nullptr)
return "OpenGL claims to support version 3.2 but doesn't have glBindFragDataLocation";
609#ifndef NO_GL_BUFFER_SYNC
620 GLint max_tex_size = 0;
621 _glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
622 if (std::max(screen_res.
width, screen_res.
height) > (uint)max_tex_size)
return "Max supported texture size is too small";
625 GLint max_tex_units = 0;
626 _glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_tex_units);
627 if (max_tex_units < 4)
return "Not enough simultaneous textures supported";
629 Debug(
Facility::Driver,
Severity::Warning,
"OpenGL shading language version: {}, texture units = {}", GlGetString(GL_SHADING_LANGUAGE_VERSION).value_or(
"Unknown version"), max_tex_units);
631 if (!this->
InitShaders())
return "Failed to initialize shaders";
636 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
637 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
638 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
639 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
640 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
641 _glBindTexture(GL_TEXTURE_2D, 0);
642 if (_glGetError() != GL_NO_ERROR)
return "Can't generate video buffer texture";
647 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
648 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
649 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
650 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
651 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
652 _glBindTexture(GL_TEXTURE_2D, 0);
653 if (_glGetError() != GL_NO_ERROR)
return "Can't generate animation buffer texture";
658 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
659 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
660 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 0);
661 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
662 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
663 _glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, 256, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
nullptr);
664 _glBindTexture(GL_TEXTURE_1D, 0);
665 if (_glGetError() != GL_NO_ERROR)
return "Can't generate palette lookup texture";
668 GLint tex_location = _glGetUniformLocation(this->
vid_program,
"colour_tex");
669 GLint palette_location = _glGetUniformLocation(this->
vid_program,
"palette");
670 GLint sprite_location = _glGetUniformLocation(this->
vid_program,
"sprite");
671 GLint screen_location = _glGetUniformLocation(this->
vid_program,
"screen");
673 _glUniform1i(tex_location, 0);
674 _glUniform1i(palette_location, 1);
676 _glUniform4f(sprite_location, 0.0f, 0.0f, 1.0f, 1.0f);
677 _glUniform2f(screen_location, 1.0f, 1.0f);
680 tex_location = _glGetUniformLocation(this->
pal_program,
"colour_tex");
681 palette_location = _glGetUniformLocation(this->
pal_program,
"palette");
682 sprite_location = _glGetUniformLocation(this->
pal_program,
"sprite");
683 screen_location = _glGetUniformLocation(this->
pal_program,
"screen");
685 _glUniform1i(tex_location, 0);
686 _glUniform1i(palette_location, 1);
687 _glUniform4f(sprite_location, 0.0f, 0.0f, 1.0f, 1.0f);
688 _glUniform2f(screen_location, 1.0f, 1.0f);
691 tex_location = _glGetUniformLocation(this->
remap_program,
"colour_tex");
692 palette_location = _glGetUniformLocation(this->
remap_program,
"palette");
693 GLint remap_location = _glGetUniformLocation(this->
remap_program,
"remap_tex");
699 _glUniform1i(tex_location, 0);
700 _glUniform1i(palette_location, 1);
701 _glUniform1i(remap_location, 2);
704 tex_location = _glGetUniformLocation(this->
sprite_program,
"colour_tex");
705 palette_location = _glGetUniformLocation(this->
sprite_program,
"palette");
706 remap_location = _glGetUniformLocation(this->
sprite_program,
"remap_tex");
707 GLint pal_location = _glGetUniformLocation(this->
sprite_program,
"pal");
714 _glUniform1i(tex_location, 0);
715 _glUniform1i(palette_location, 1);
716 _glUniform1i(remap_location, 2);
717 _glUniform1i(pal_location, 3);
721 _glGenBuffers(1, &this->
vid_pbo);
722 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
vid_pbo);
724 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
725 if (_glGetError() != GL_NO_ERROR)
return "Can't allocate pixel buffer for video buffer";
731 { 1.f, -1.f, 1.f, 1.f },
732 { 1.f, 1.f, 1.f, 0.f },
733 { -1.f, -1.f, 0.f, 1.f },
734 { -1.f, 1.f, 0.f, 0.f },
738 _glGenVertexArrays(1, &this->
vao_quad);
743 _glBindBuffer(GL_ARRAY_BUFFER, this->
vbo_quad);
744 _glBufferData(GL_ARRAY_BUFFER,
sizeof(vert_array), vert_array, GL_STATIC_DRAW);
745 if (_glGetError() != GL_NO_ERROR)
return "Can't generate VBO for fullscreen quad";
748 GLint loc_position = _glGetAttribLocation(this->
vid_program,
"position");
749 GLint colour_position = _glGetAttribLocation(this->
vid_program,
"colour_uv");
750 _glEnableVertexAttribArray(loc_position);
751 _glEnableVertexAttribArray(colour_position);
754 _glBindVertexArray(0);
759 this->PrepareContext();
765void OpenGLBackend::PrepareContext()
767 _glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
768 _glDisable(GL_DEPTH_TEST);
771 _glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
774std::string OpenGLBackend::GetDriverName()
776 auto renderer = GlGetString(GL_RENDERER);
777 auto version = GlGetString(GL_VERSION);
779 return fmt::format(
"{}, {}", renderer.value_or(
"Unknown renderer"), version.value_or(
"Unknown version"));
791 GLint result = GL_FALSE;
792 _glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
796 _glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
798 _glGetShaderInfoLog(shader, log_len,
nullptr, log_buf.
Allocate(log_len));
802 return result == GL_TRUE;
814 GLint result = GL_FALSE;
815 _glGetProgramiv(program, GL_LINK_STATUS, &result);
819 _glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_len);
821 _glGetProgramInfoLog(program, log_len,
nullptr, log_buf.
Allocate(log_len));
825 return result == GL_TRUE;
834 auto ver = GlGetString(GL_SHADING_LANGUAGE_VERSION);
835 if (!ver.has_value())
return false;
837 auto [glsl_major, glsl_minor] = DecodeVersion(*ver);
839 bool glsl_150 = (
IsOpenGLVersionAtLeast(3, 2) || glsl_major > 1 || (glsl_major == 1 && glsl_minor >= 5)) && _glBindFragDataLocation !=
nullptr;
842 GLuint vert_shader = _glCreateShader(GL_VERTEX_SHADER);
844 _glCompileShader(vert_shader);
848 GLuint frag_shader_rgb = _glCreateShader(GL_FRAGMENT_SHADER);
850 _glCompileShader(frag_shader_rgb);
854 GLuint frag_shader_pal = _glCreateShader(GL_FRAGMENT_SHADER);
856 _glCompileShader(frag_shader_pal);
860 GLuint remap_shader = _glCreateShader(GL_FRAGMENT_SHADER);
862 _glCompileShader(remap_shader);
866 GLuint sprite_shader = _glCreateShader(GL_FRAGMENT_SHADER);
868 _glCompileShader(sprite_shader);
874 _glAttachShader(this->
vid_program, frag_shader_rgb);
878 _glAttachShader(this->
pal_program, frag_shader_pal);
890 _glBindFragDataLocation(this->
vid_program, 0,
"colour");
891 _glBindFragDataLocation(this->
pal_program, 0,
"colour");
908 _glDeleteShader(vert_shader);
909 _glDeleteShader(frag_shader_rgb);
910 _glDeleteShader(frag_shader_pal);
911 _glDeleteShader(remap_shader);
912 _glDeleteShader(sprite_shader);
926 T *buf =
reinterpret_cast<T *
>(_glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE));
927 for (
size_t i = 0; i < len; i++) {
930 _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
942 if (!force && _screen.width == w && _screen.height == h)
return false;
945 int pitch =
Align(w, 4);
946 size_t line_pixel_count =
static_cast<size_t>(pitch) * h;
948 _glViewport(0, 0, w, h);
950 _glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch);
954 _glDeleteBuffers(1, &this->
vid_pbo);
955 _glGenBuffers(1, &this->
vid_pbo);
956 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
vid_pbo);
957 _glBufferStorage(GL_PIXEL_UNPACK_BUFFER, line_pixel_count * bpp / 8,
nullptr, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT | GL_CLIENT_STORAGE_BIT);
960 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
vid_pbo);
961 _glBufferData(GL_PIXEL_UNPACK_BUFFER, line_pixel_count * bpp / 8,
nullptr, GL_DYNAMIC_DRAW);
966 Colour black(0, 0, 0);
967 if (_glClearBufferSubData !=
nullptr) {
968 _glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_RGBA8, 0, line_pixel_count * bpp / 8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &black.data);
972 }
else if (bpp == 8) {
973 if (_glClearBufferSubData !=
nullptr) {
975 _glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_R8, 0, line_pixel_count, GL_RED, GL_UNSIGNED_BYTE, &b);
981 _glActiveTexture(GL_TEXTURE0);
984 _glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE,
nullptr);
986 _glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
nullptr);
988 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
994 _glDeleteBuffers(1, &this->
anim_pbo);
996 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
997 _glBufferStorage(GL_PIXEL_UNPACK_BUFFER, line_pixel_count,
nullptr, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT | GL_CLIENT_STORAGE_BIT);
999 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
1000 _glBufferData(GL_PIXEL_UNPACK_BUFFER, line_pixel_count,
nullptr, GL_DYNAMIC_DRAW);
1004 if (_glClearBufferSubData !=
nullptr) {
1006 _glClearBufferSubData(GL_PIXEL_UNPACK_BUFFER, GL_R8, 0, line_pixel_count, GL_RED, GL_UNSIGNED_BYTE, &b);
1012 _glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE,
nullptr);
1013 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1016 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
1017 _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
1018 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1024 _glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1026 _glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, &dummy);
1029 _glBindTexture(GL_TEXTURE_2D, 0);
1034 _screen.pitch = pitch;
1035 _screen.dst_ptr =
nullptr;
1039 _glUniform2f(this->
remap_screen_loc, (
float)_screen.width, (
float)_screen.height);
1041 _glClear(GL_COLOR_BUFFER_BIT);
1054 assert(first + length <= 256);
1056 _glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1057 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1058 _glActiveTexture(GL_TEXTURE1);
1060 _glTexSubImage1D(GL_TEXTURE_1D, 0, first, length, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pal + first);
1068 _glClear(GL_COLOR_BUFFER_BIT);
1070 _glDisable(GL_BLEND);
1073 _glActiveTexture(GL_TEXTURE0);
1075 _glActiveTexture(GL_TEXTURE1);
1079 _glActiveTexture(GL_TEXTURE2);
1089 _glBindVertexArray(this->
vao_quad);
1090 _glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1092 _glEnable(GL_BLEND);
1103 _cur_dpi = &_screen;
1119 OpenGLSpriteLRUCache &lru;
1122 OpenGLSpriteAllocator(OpenGLSpriteLRUCache &lru,
SpriteID sprite) : lru(lru), sprite(sprite) {}
1127void OpenGLBackend::PopulateCursorCache()
1141 for (
const auto &sc : _cursor.
sprites) {
1145 OpenGLSpriteAllocator allocator(this->
cursor_cache, sc.image.sprite);
1177#ifndef NO_GL_BUFFER_SYNC
1183 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
vid_pbo);
1184 this->
vid_buffer = _glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
1186 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
vid_pbo);
1187 this->
vid_buffer = _glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0,
static_cast<GLsizeiptr
>(_screen.pitch) * _screen.height *
BlitterFactory::GetCurrentBlitter()->GetScreenDepth() / 8, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
1199 if (this->
anim_pbo == 0)
return nullptr;
1201#ifndef NO_GL_BUFFER_SYNC
1206 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
1207 this->
anim_buffer = _glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);
1209 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
1210 this->
anim_buffer = _glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0,
static_cast<GLsizeiptr
>(_screen.pitch) * _screen.height, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
1224 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
vid_pbo);
1226 _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
1230#ifndef NO_GL_BUFFER_SYNC
1239 _glActiveTexture(GL_TEXTURE0);
1241 _glPixelStorei(GL_UNPACK_ROW_LENGTH, _screen.pitch);
1243 _glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_RED, GL_UNSIGNED_BYTE, (GLvoid*)(
size_t)(update_rect.top * _screen.pitch + update_rect.left));
1245 _glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (GLvoid*)(
size_t)(update_rect.top * _screen.pitch * 4 + update_rect.left * 4));
1248#ifndef NO_GL_BUFFER_SYNC
1262 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->
anim_pbo);
1264 _glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
1268#ifndef NO_GL_BUFFER_SYNC
1276 if (update_rect.left != update_rect.right) {
1277 _glActiveTexture(GL_TEXTURE0);
1279 _glPixelStorei(GL_UNPACK_ROW_LENGTH, _screen.pitch);
1280 _glTexSubImage2D(GL_TEXTURE_2D, 0, update_rect.left, update_rect.top, update_rect.right - update_rect.left, update_rect.bottom - update_rect.top, GL_RED, GL_UNSIGNED_BYTE, (GLvoid *)(
size_t)(update_rect.top * _screen.pitch + update_rect.left));
1282#ifndef NO_GL_BUFFER_SYNC
1292 gl_allocator.lru.
Insert(gl_allocator.sprite, std::make_unique<OpenGLSprite>(sprite_type, sprite));
1309 _glActiveTexture(GL_TEXTURE0 + 1);
1313 _glActiveTexture(GL_TEXTURE0 + 3);
1314 if (pal != PAL_NONE) {
1319 _glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1322 _glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE,
nullptr);
1324 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1337 _glUniform2f(this->
sprite_screen_loc, (
float)_screen.width, (
float)_screen.height);
1341 _glBindVertexArray(this->
vao_quad);
1342 _glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1362 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1363 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1364 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1365 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1366 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1369 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1370 _glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1373 const Colour rgb_pixel(0, 0, 0);
1375 _glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &rgb_pixel);
1380 _glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, &pal);
1383 std::array<uint8_t, 256> identity_pal;
1384 std::iota(std::begin(identity_pal), std::end(identity_pal), 0);
1389 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1390 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1391 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 0);
1392 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1393 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1394 _glTexImage1D(GL_TEXTURE_1D, 0, GL_R8, 256, 0, GL_RED, GL_UNSIGNED_BYTE, identity_pal.data());
1399 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1400 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1401 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 0);
1402 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1403 _glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1404 _glTexImage1D(GL_TEXTURE_1D, 0, GL_R8, 256, 0, GL_RED, GL_UNSIGNED_BYTE, identity_pal.data());
1409 _glBufferData(GL_PIXEL_UNPACK_BUFFER, 256, identity_pal.data(), GL_DYNAMIC_DRAW);
1410 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1412 return _glGetError() == GL_NO_ERROR;
1431 const auto &root_sprite = sprite.Root();
1432 this->dim.
width = root_sprite.width;
1433 this->dim.height = root_sprite.height;
1434 this->
x_offs = root_sprite.x_offs;
1435 this->
y_offs = root_sprite.y_offs;
1439 (void)_glGetError();
1442 _glActiveTexture(GL_TEXTURE0);
1443 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1451 _glGenTextures(1, &this->
tex[t]);
1452 _glBindTexture(GL_TEXTURE_2D, this->
tex[t]);
1454 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1455 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1456 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1);
1457 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1458 _glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1461 for (
int i = 0, w = this->dim.width, h = this->dim.height; i < levels; i++, w /= 2, h /= 2) {
1464 _glTexImage2D(GL_TEXTURE_2D, i, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE,
nullptr);
1466 _glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
nullptr);
1473 const auto &src_sprite = sprite[zoom];
1477 assert(_glGetError() == GL_NO_ERROR);
1483 _glDeleteTextures(
static_cast<GLsizei
>(this->
tex.size()), this->tex.data());
1498 _glActiveTexture(GL_TEXTURE0);
1499 _glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1500 _glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1504 size_t size =
static_cast<size_t>(width) * height;
1505 Colour *rgba = buf_rgba.
Allocate(size);
1506 for (
size_t i = 0; i < size; i++) {
1507 rgba[i].r = data[i].
r;
1508 rgba[i].g = data[i].
g;
1509 rgba[i].b = data[i].
b;
1510 rgba[i].a = data[i].
a;
1514 _glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, rgba);
1519 size_t pitch =
Align(width, 4);
1521 uint8_t *pal = buf_pal.
Allocate(pitch * height);
1523 for (uint y = 0; y < height; y++, pal += pitch, row += width) {
1524 for (uint x = 0; x < width; x++) {
1530 _glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, GL_RED, GL_UNSIGNED_BYTE, buf_pal.
GetBuffer());
1533 assert(_glGetError() == GL_NO_ERROR);
1553 _glActiveTexture(GL_TEXTURE0);
1555 _glActiveTexture(GL_TEXTURE0 + 2);
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
Iterate a range of enum values.
void Insert(const Tkey &key, Tdata &&item)
Insert a new data item with a specified key.
Platform-independent back-end class for OpenGL video drivers.
GLint sprite_rgb_loc
Uniform location for RGB mode flag.
void * anim_buffer
Pointer to the mapped animation buffer.
GLuint remap_program
Shader program for blending and rendering a RGBA + remap texture.
bool cursor_in_window
Cursor inside this window.
void Paint()
Render video buffer to the screen.
GLuint pal_program
Shader program for rendering a paletted video buffer.
OpenGLSpriteLRUCache cursor_cache
Cache of encoded cursor sprites.
std::vector< CursorSprite > cursor_sprites
Sprites comprising cursor.
GLint remap_screen_loc
Uniform location for screen size.
~OpenGLBackend() override
Free allocated resources.
static OpenGLBackend * instance
Singleton instance pointer.
uint8_t * GetAnimBuffer()
Get a pointer to the memory for the separate animation buffer.
void * GetVideoBuffer()
Get a pointer to the memory for the video driver to draw to.
bool persistent_mapping_supported
Persistent pixel buffer mapping supported.
GLuint vid_texture
Texture handle for the video buffer texture.
GLuint vao_quad
Vertex array object storing the rendering state for the fullscreen quad.
GLint sprite_zoom_loc
Uniform location for sprite zoom.
GLint remap_zoom_loc
Uniform location for sprite zoom.
bool Resize(int w, int h, bool force=false)
Change the size of the drawing window and allocate matching resources.
OpenGLBackend()
Construct OpenGL back-end class.
static std::optional< std::string_view > Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
Create and initialize the singleton back-end class.
void * vid_buffer
Pointer to the mapped video buffer.
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
GLuint anim_texture
Texture handle for the animation buffer texture.
void InternalClearCursorCache()
Clear all cached cursor sprites.
Sprite * Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
GLuint sprite_program
Shader program for blending and rendering a sprite to the video buffer.
void ReleaseAnimBuffer(const Rect &update_rect)
Update animation buffer texture after the animation buffer was filled.
GLuint vid_pbo
Pixel buffer object storing the memory used for the video driver to draw to.
GLsync sync_anim_mapping
Sync object for the persistently mapped animation buffer.
GLuint vbo_quad
Vertex buffer with a fullscreen quad.
bool clear_cursor_cache
A clear of the cursor cache is pending.
GLint remap_rgb_loc
Uniform location for RGB mode flag.
void ClearCursorCache()
Queue a request for cursor cache clear.
GLuint vid_program
Shader program for rendering a RGBA video buffer.
GLuint pal_texture
Palette lookup texture.
GLint remap_sprite_loc
Uniform location for sprite parameters.
bool InitShaders()
Create all needed shader programs.
void DrawMouseCursor()
Draw mouse cursor on screen.
Point cursor_pos
Cursor position.
GLint sprite_crash_loc
Uniform location for crash remap mode flag.
void ReleaseVideoBuffer(const Rect &update_rect)
Update video buffer texture after the video buffer was filled.
GLint sprite_sprite_loc
Uniform location for sprite parameters.
void RenderOglSprite(const OpenGLSprite *gl_sprite, PaletteID pal, int x, int y, ZoomLevel zoom)
Render a sprite to the back buffer.
PaletteID last_sprite_pal
Last uploaded remap palette.
GLuint anim_pbo
Pixel buffer object storing the memory used for the animation buffer.
GLsync sync_vid_mapping
Sync object for the persistently mapped video buffer.
std::optional< std::string_view > Init(const Dimension &screen_res)
Check for the needed OpenGL functionality and allocate all resources.
static void Destroy()
Free resources and destroy singleton back-end class.
GLint sprite_screen_loc
Uniform location for screen size.
void * AllocatePtr(size_t) override
Allocate memory for a sprite.
Class that encapsulates a RGBA texture together with a paletted remap texture.
bool BindTextures() const
Bind textures for rendering this sprite.
static EnumIndexArray< GLuint, Texture, Texture::End > dummy_tex
1x1 dummy textures to substitute for unused sprite components.
OpenGLSprite(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite)
Create an OpenGL sprite with a palette remap part.
Texture
Enum of all used OpenGL texture objects.
@ Remap
Remap texture part.
Dimension GetSize(ZoomLevel level) const
Query the sprite size at a certain zoom level.
static bool Create()
Create all common resources for sprite rendering.
~OpenGLSprite()
Delete the textures we allocated.
static GLuint pal_pbo
Pixel buffer object for remap upload.
static GLuint pal_identity
Identity texture mapping.
static GLuint pal_tex
Texture for palette remap.
int16_t y_offs
Number of pixels to shift the sprite downwards.
int16_t x_offs
Number of pixels to shift the sprite to the right.
void Update(uint width, uint height, uint level, const SpriteLoader::CommonPixel *data)
Update a single mip-map level with new pixel data.
EnumIndexArray< GLuint, Texture, Texture::End > tex
The texture objects.
static void Destroy()
Free all common resources for sprite rendering.
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
const T * GetBuffer() const
Get the currently allocated buffer.
T * Allocate(size_t count)
Get buffer of at least count times T.
Interface for something that can allocate memory for a sprite.
SpriteCollMap< Sprite > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
Parse data from a string / buffer.
@ SKIP_ALL_SEPARATORS
Read and discard all consecutive separators, do not include any in the result.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
std::string_view ReadUntil(std::string_view str, SeparatorUsage sep)
Read data until the first occurrence of 'str', and advance reader.
bool ReadIf(std::string_view str)
Check whether the next data matches 'str', and skip it.
T ReadIntegerBase(int base, T def=0, bool clamp=false)
Read and parse an integer in number 'base', and advance the reader.
Functions related to debugging.
bool IsVisibleSeverity(Facility facility, Severity severity)
Test if debug severity is visible for the given facility.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Driver
Driver message facility.
@ Warning
Warning, wrong but okay if you don't know.
@ Critical
Critical, user should know about this.
@ Debug2
Debug #2 - Low level debug messages.
@ Trace2
Trace information #2.
@ Error
Error, but we are recovering.
@ Trace3
Trace information #3.
#define T
Climate temperate.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Factory to 'query' all available blitters.
bool IsEmptyRect(const Rect &r)
Check if a rectangle is empty.
ZoomLevel _gui_zoom
GUI Zoom level.
Functions related to the gfx engine.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
SpriteType
Types of sprites that might be loaded.
@ Recolour
Recolour sprite.
@ Font
A sprite used for fonts.
@ Normal
The most basic (normal) sprite.
uint32_t PaletteID
The number of the palette.
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
bool IsOpenGLVersionAtLeast(uint8_t major, uint8_t minor)
Check if the current OpenGL version is equal or higher than a given one.
static bool BindBasicOpenGLProcs()
Bind OpenGL 1.0 and 1.1 functions.
static void ClearPixelBuffer(size_t len, T data)
Clear the bound pixel buffer to a specific value.
static const int MAX_CACHED_CURSORS
Maximum number of cursor sprites to cache.
static bool IsOpenGLExtensionSupported(std::string_view extension)
Check if an OpenGL extension is supported by the current context.
static bool BindPersistentBufferExtensions()
Bind extension functions for persistent buffer mapping.
static bool VerifyProgram(GLuint program)
Check a program for link errors and log them if necessary.
static uint8_t _gl_major_ver
Major OpenGL version.
static bool BindGLProc(F &f, const char *name)
Try loading an OpenGL function.
static bool BindVBAExtension()
Bind vertex array object extension functions.
void SetupDebugOutput()
Enable OpenGL debug messages if supported.
static uint8_t _gl_minor_ver
Minor OpenGL version.
static bool BindShaderExtensions()
Bind extension functions for shader support.
static bool BindBasicInfoProcs()
Bind basic information functions.
bool HasStringInExtensionList(std::string_view string, std::string_view substring)
Find a substring in a string made of space delimited elements.
static bool BindTextureExtensions()
Bind texture-related extension functions.
static bool VerifyShader(GLuint shader)
Check a shader for compilation errors and log them if necessary.
void DebugOutputCallback(GLenum, GLenum type, GLuint, GLenum severity, GLsizei, const GLchar *message, const void *)
Callback to receive OpenGL debug messages.
static bool BindVBOExtension()
Bind vertex buffer object extension functions.
OpenGL video driver support.
bool IsOpenGLVersionAtLeast(uint8_t major, uint8_t minor)
Check if the current OpenGL version is equal or higher than a given one.
static const char * _vertex_shader_sprite[]
Vertex shader that positions a sprite on screen.
static const char * _frag_shader_palette_150[]
GLSL 1.50 fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
static const char * _frag_shader_direct[]
Fragment shader that reads the fragment colour from a 32bpp texture.
static const char * _frag_shader_rgb_mask_blend[]
Fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
static const char * _frag_shader_palette[]
Fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
static const char * _frag_shader_rgb_mask_blend_150[]
GLSL 1.50 fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
static const char * _frag_shader_direct_150[]
GLSL 1.50 fragment shader that reads the fragment colour from a 32bpp texture.
static const char * _frag_shader_sprite_blend_150[]
GLSL 1.50 fragment shader that performs a palette lookup to read the colour from a sprite texture.
static const char * _frag_shader_sprite_blend[]
Fragment shader that performs a palette lookup to read the colour from a sprite texture.
static const char * _vertex_shader_sprite_150[]
GLSL 1.50 vertex shader that positions a sprite on screen.
A number of safeguards to prevent using unsafe methods.
void * GetRawSprite(SpriteID sprite, SpriteType type, SpriteAllocator *allocator, SpriteEncoder *encoder)
Reads a sprite (from disk or sprite cache).
Functions to cache sprites in memory.
@ Palette
Sprite has palette data.
This file contains all sprite-related enums and defines.
static constexpr uint8_t PALETTE_WIDTH
number of bits of the sprite containing the recolour palette
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
std::vector< CursorSprite > sprites
Sprites comprising cursor.
Point pos
logical mouse position
bool in_window
mouse inside this window, determines drawing logic
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Specification of a rectangle with absolute coordinates of all edges.
A simple 2D vertex with just position and texture.
Definition of a common pixel in OpenTTD's realm.
Data structure describing a sprite.
uint16_t width
Width of the sprite.
Functions related to zooming.
int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZoomLevel::Min).
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZoomLevel::Min) When shifting right,...
ZoomLevel
All zoom levels we know.