added ability to set some GL properties with config, added some more GL properties to log
This commit is contained in:
parent
d0bf52a03d
commit
0d00314f5a
|
@ -4,3 +4,4 @@ build/
|
|||
demo/2d_collision/2d_collision
|
||||
demo/squircle/squircle
|
||||
demo/cube/cube
|
||||
compile_commands.json
|
||||
|
|
|
@ -60,6 +60,16 @@ void Configuration::set_defaults()
|
|||
{"default-sfx-root", "resource/sfx"},
|
||||
{"default-bgm-root", "resource/bgm"}
|
||||
};
|
||||
sys_config["gl"] = {
|
||||
{"depth-size", 16},
|
||||
{"red-size", 8},
|
||||
{"green-size", 8},
|
||||
{"blue-size", 8},
|
||||
{"share-with-current-context", true},
|
||||
{"double-buffer", true},
|
||||
{"major-version", 3},
|
||||
{"minor-version", 2}
|
||||
},
|
||||
sys_config["recording"] = {
|
||||
{"enabled", false},
|
||||
{"screenshot-prefix", "screenshot-"},
|
||||
|
|
|
@ -161,12 +161,12 @@ void sb::Display::toggle_fullscreen() const
|
|||
{
|
||||
if (SDL_GetWindowFlags(const_cast<SDL_Window*>(window())) & SDL_WINDOW_FULLSCREEN)
|
||||
{
|
||||
sb::Log::log("fullscreen requested");
|
||||
sb::Log::log("exit fullscreen requested");
|
||||
SDL_SetWindowFullscreen(const_cast<SDL_Window*>(window()), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb::Log::log("exit fullscreen requested");
|
||||
sb::Log::log("fullscreen requested");
|
||||
SDL_SetWindowFullscreen(const_cast<SDL_Window*>(window()), SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
|
|
212
src/Game.cpp
212
src/Game.cpp
|
@ -51,17 +51,18 @@ Game::Game()
|
|||
sb::Log::log(log_message.str());
|
||||
glm::ivec2 window_size = configuration()["display"]["dimensions"].get<glm::ivec2>();
|
||||
|
||||
/* Set these before creating a window (see SDL_GLattr.html). Don't ask Emscripten for a specific GL context version. */
|
||||
/* Set GL context attributes before creating a window (see SDL_GLattr.html). Don't ask Emscripten for a specific GL context version. */
|
||||
#ifndef __EMSCRIPTEN__
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, configuration()["gl"]["major-version"]);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, configuration()["gl"]["minor-version"]);
|
||||
#endif
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, configuration()["gl"]["depth-size"]);
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, configuration()["gl"]["red-size"]);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, configuration()["gl"]["green-size"]);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, configuration()["gl"]["blue-size"]);
|
||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, configuration()["gl"]["share-with-current-context"]);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, configuration()["gl"]["double-buffer"]);
|
||||
|
||||
/* Set the profile to ES so that desktop and web builds are both using the same profile. This should be handled by a configuration
|
||||
* option in the fututre. */
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
|
@ -201,15 +202,13 @@ void Game::load_gl_context()
|
|||
sb::Log::log("vsync not supported");
|
||||
}
|
||||
GLenum error = glewInit();
|
||||
std::ostringstream message;
|
||||
if (error != GLEW_OK)
|
||||
{
|
||||
std::ostringstream message;
|
||||
message << "GLEW could not initialize " << glewGetErrorString(error);
|
||||
sb::Log::log(message, sb::Log::ERROR);
|
||||
}
|
||||
message << "OpenGL " << glGetString(GL_VERSION) << ", renderer " << glGetString(GL_RENDERER) << ", shading language " <<
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
sb::Log::log(message);
|
||||
log_gl_properties();
|
||||
is_gl_context = true;
|
||||
log_display_mode();
|
||||
}
|
||||
|
@ -330,9 +329,7 @@ void Game::log_renderer_info(SDL_RendererInfo& info)
|
|||
sb::Log::log(message);
|
||||
}
|
||||
|
||||
/* Write resolution, monitor refresh rate, and pixel format to the log. Code taken from SDL_GetCurrentDisplayMode.html
|
||||
* on the SDL wiki */
|
||||
void Game::log_display_mode()
|
||||
void Game::log_display_mode() const
|
||||
{
|
||||
SDL_DisplayMode current;
|
||||
std::ostringstream message;
|
||||
|
@ -346,152 +343,69 @@ void Game::log_display_mode()
|
|||
}
|
||||
else
|
||||
{
|
||||
if (ii > 0)
|
||||
{
|
||||
message << ", ";
|
||||
}
|
||||
message << "Display #" << ii << ": display mode is " << current.w << "x" << current.h << "px @ " <<
|
||||
current.refresh_rate << "hz " << get_pixel_format_string(current.format);
|
||||
sb::Log::log(message);
|
||||
current.refresh_rate << "hz " << SDL_GetPixelFormatName(current.format);
|
||||
}
|
||||
}
|
||||
sb::Log::log(message);
|
||||
}
|
||||
|
||||
void Game::log_gl_properties() const
|
||||
{
|
||||
std::ostringstream message;
|
||||
|
||||
message << "OpenGL " << glGetString(GL_VERSION) << ", renderer " << glGetString(GL_RENDERER) << ", shading language " <<
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION) << ", vendor " << glGetString(GL_VENDOR);
|
||||
|
||||
int attribute;
|
||||
int status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &attribute);
|
||||
if (!status) {
|
||||
message << ", SDL_GL_RED_SIZE: requested " << configuration()["gl"]["red-size"] << ", got " << attribute;
|
||||
} else {
|
||||
sb::Log::sdl_error("Failed to get SDL_GL_RED_SIZE");
|
||||
}
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &attribute);
|
||||
if (!status) {
|
||||
message << ", SDL_GL_GREEN_SIZE: requested " << configuration()["gl"]["green-size"] << ", got " << attribute;
|
||||
} else {
|
||||
sb::Log::sdl_error("Failed to get SDL_GL_GREEN_SIZE");
|
||||
}
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &attribute);
|
||||
if (!status) {
|
||||
message << ", SDL_GL_BLUE_SIZE: requested " << configuration()["gl"]["blue-size"] << ", got " << attribute;
|
||||
} else {
|
||||
sb::Log::sdl_error("Failed to get SDL_GL_BLUE_SIZE");
|
||||
}
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &attribute);
|
||||
if (!status) {
|
||||
message << ", SDL_GL_DEPTH_SIZE: requested " << configuration()["gl"]["depth-size"] << ", got " << attribute;
|
||||
} else {
|
||||
sb::Log::sdl_error("Failed to get SDL_GL_DEPTH_SIZE");
|
||||
}
|
||||
|
||||
sb::Log::log(message);
|
||||
|
||||
std::ostringstream debug_message;
|
||||
debug_message << "OpenGL extensions: " << glGetString(GL_EXTENSIONS);
|
||||
sb::Log::log(message, sb::Log::DEBUG);
|
||||
}
|
||||
|
||||
void Game::log_surface_format(SDL_Surface* surface, std::string preface)
|
||||
{
|
||||
SDL_PixelFormat* format = surface->format;
|
||||
std::string pixel_format = get_pixel_format_string(format->format);
|
||||
std::string pixel_format = SDL_GetPixelFormatName(format->format);
|
||||
SDL_Log("%s bpp: %i mask: %i %i %i %i format: %s", preface.c_str(),
|
||||
format->BytesPerPixel, format->Rmask, format->Gmask, format->Bmask,
|
||||
format->Amask, pixel_format.c_str());
|
||||
}
|
||||
|
||||
std::string Game::get_pixel_format_string(Uint32 format)
|
||||
{
|
||||
std::string pixel_format;
|
||||
if (format == SDL_PIXELFORMAT_UNKNOWN)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_UNKNOWN";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_INDEX1LSB)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_INDEX1LSB";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_INDEX1MSB)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_INDEX1MSB";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_INDEX4LSB)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_INDEX4LSB";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_INDEX4MSB)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_INDEX4MSB";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_INDEX8)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_INDEX8";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGB332)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGB332";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGB444)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGB444";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGB555)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGB555";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGR555)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGR555";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ARGB4444)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ARGB4444";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGBA4444)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGBA4444";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ABGR4444)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ABGR4444";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGRA4444)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGRA4444";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ARGB1555)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ARGB1555";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGBA5551)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGBA5551";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ABGR1555)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ABGR1555";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGRA5551)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGRA5551";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGB565)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGB565";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGR565)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGR565";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGB24)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGB24";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGR24)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGR24";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGB888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGB888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGBX8888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGBX8888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGR888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGR888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGRX8888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGRX8888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ARGB8888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ARGB8888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_RGBA8888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_RGBA8888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ABGR8888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ABGR8888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_BGRA8888)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_BGRA8888";
|
||||
}
|
||||
else if (format == SDL_PIXELFORMAT_ARGB2101010)
|
||||
{
|
||||
pixel_format = "SDL_PIXELFORMAT_ARGB2101010";
|
||||
}
|
||||
return pixel_format;
|
||||
}
|
||||
|
||||
const nlohmann::json& Game::configuration() const
|
||||
{
|
||||
return _configuration.config;
|
||||
|
|
14
src/Game.hpp
14
src/Game.hpp
|
@ -95,9 +95,19 @@ public:
|
|||
GLuint load_shader(const fs::path&, GLenum) const;
|
||||
bool link_shader(GLuint program) const;
|
||||
void log_renderer_info(SDL_RendererInfo&);
|
||||
void log_display_mode();
|
||||
|
||||
/*!
|
||||
* Write resolution, monitor refresh rate, and pixel format to the log. Taken from SDL_GetCurrentDisplayMode.html
|
||||
* on the SDL wiki.
|
||||
*/
|
||||
void log_display_mode() const;
|
||||
|
||||
/*!
|
||||
* Log properties of the GL context. Taken from `sdl_source/tests/testgles2.c`
|
||||
*/
|
||||
void log_gl_properties() const;
|
||||
|
||||
void log_surface_format(SDL_Surface*, std::string = "surface");
|
||||
std::string get_pixel_format_string(Uint32);
|
||||
const nlohmann::json& configuration() const;
|
||||
nlohmann::json& configuration();
|
||||
const SDL_Window* window() const;
|
||||
|
|
Loading…
Reference in New Issue