Some initial code (disabled for now) for setting up an OGL context
In the interests of getting this all done faster, I've decided to postpone work on the OGL implementation for now and focus on the SDL_Renderer version. This contains some basic code (include-guarded) for setting up an OGL context for the main SDL window.
This commit is contained in:
parent
61dcb43ee6
commit
8a82d43855
13 changed files with 224 additions and 1 deletions
|
@ -43,6 +43,7 @@
|
|||
<Add option="-D_WIN32_WINDOWS" />
|
||||
<Add option="-D_WIN32_WINNT=0x0501" />
|
||||
<Add option="-D_WIN32_IE=0x0501" />
|
||||
<Add option="-DGLEW_STATIC" />
|
||||
<Add directory="../../src" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
|
@ -79,6 +80,8 @@
|
|||
<Add library="libboost_zlib-mgw51-mt-1_64" />
|
||||
<Add library="libcrypto-1_1" />
|
||||
<Add library="winmm" />
|
||||
<Add library="libglew32" />
|
||||
<Add library="opengl32" />
|
||||
<Add directory="./" />
|
||||
</Linker>
|
||||
<Unit filename="../../packaging/windows/wesnoth.rc">
|
||||
|
@ -733,6 +736,8 @@
|
|||
<Unit filename="../../src/gui/widgets/list.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/listbox.cpp" />
|
||||
<Unit filename="../../src/gui/widgets/listbox.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/map_viewer.cpp" />
|
||||
<Unit filename="../../src/gui/widgets/map_viewer.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/matrix.cpp" />
|
||||
<Unit filename="../../src/gui/widgets/matrix.hpp" />
|
||||
<Unit filename="../../src/gui/widgets/menu_button.cpp" />
|
||||
|
@ -901,6 +906,10 @@
|
|||
<Unit filename="../../src/multiplayer_error_codes.hpp" />
|
||||
<Unit filename="../../src/network_asio.cpp" />
|
||||
<Unit filename="../../src/network_asio.hpp" />
|
||||
<Unit filename="../../src/ogl/context.cpp" />
|
||||
<Unit filename="../../src/ogl/context.hpp" />
|
||||
<Unit filename="../../src/ogl/utils.cpp" />
|
||||
<Unit filename="../../src/ogl/utils.hpp" />
|
||||
<Unit filename="../../src/overlay.hpp" />
|
||||
<Unit filename="../../src/pathfind/astarsearch.cpp" />
|
||||
<Unit filename="../../src/pathfind/pathfind.cpp" />
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
ogl/context.cpp
|
||||
ogl/utils.cpp
|
||||
sdl/exception.cpp
|
||||
sdl/rect.cpp
|
||||
sdl/surface.cpp
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "editor/controller/editor_controller.hpp"
|
||||
#include "editor/editor_display.hpp"
|
||||
#include "lexical_cast.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "team.hpp"
|
||||
#include "terrain/builder.hpp"
|
||||
|
@ -32,7 +33,11 @@ editor_display::editor_display(editor_controller& controller, reports& reports_o
|
|||
, brush_locations_()
|
||||
, controller_(controller)
|
||||
{
|
||||
#ifdef USE_GL_RENDERING
|
||||
gl::clear_screen();
|
||||
#else
|
||||
video().clear_screen();
|
||||
#endif
|
||||
}
|
||||
|
||||
void editor_display::add_brush_loc(const map_location& hex)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "cursor.hpp"
|
||||
#include "desktop/clipboard.hpp"
|
||||
#include "log.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "quit_confirmation.hpp"
|
||||
#include "video.hpp"
|
||||
#include "sdl/userevent.hpp"
|
||||
|
@ -658,7 +659,11 @@ void pump()
|
|||
const bool is_draw_event = event.type == DRAW_EVENT || event.type == DRAW_ALL_EVENT;
|
||||
|
||||
if(is_draw_event) {
|
||||
#ifdef USE_GL_RENDERING
|
||||
gl::clear_screen();
|
||||
#else
|
||||
CVideo::get_singleton().clear_screen();
|
||||
#endif
|
||||
}
|
||||
|
||||
for(auto global_handler : event_contexts.front().handlers) {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "map/label.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "font/standard_colors.hpp"
|
||||
#include "reports.hpp"
|
||||
#include "resources.hpp"
|
||||
|
@ -80,7 +81,11 @@ game_display::game_display(game_board& board, std::weak_ptr<wb::manager> wb,
|
|||
needs_rebuild_(false)
|
||||
{
|
||||
replace_overlay_map(&overlay_map_);
|
||||
#ifdef USE_GL_RENDERING
|
||||
gl::clear_screen();
|
||||
#else
|
||||
video().clear_screen();
|
||||
#endif
|
||||
}
|
||||
|
||||
game_display::~game_display()
|
||||
|
|
57
src/ogl/context.cpp
Normal file
57
src/ogl/context.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifdef USE_GL_RENDERING
|
||||
|
||||
#include "ogl/context.hpp"
|
||||
|
||||
#include <SDL_video.h>
|
||||
|
||||
namespace gl
|
||||
{
|
||||
context::context(sdl::window* window)
|
||||
: gl_context_(SDL_GL_CreateContext(*window))
|
||||
{
|
||||
// Set flags.
|
||||
set_context_flags();
|
||||
|
||||
// Initialize GLEW.
|
||||
// TODO: should this be moved somewhere else?
|
||||
glewExperimental = GL_TRUE;
|
||||
glewInit();
|
||||
}
|
||||
|
||||
context::~context()
|
||||
{
|
||||
SDL_GL_DeleteContext(gl_context_);
|
||||
}
|
||||
|
||||
void context::set_context_flags()
|
||||
{
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
|
||||
// Turn on double buffering.
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
// Enable VSync (sync buffer refresh with monitor refresh rate).
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // USE_GL_RENDERING
|
51
src/ogl/context.hpp
Normal file
51
src/ogl/context.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef USE_GL_RENDERING
|
||||
|
||||
#include "sdl/window.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace gl
|
||||
{
|
||||
/** Encapsulates the management of an OpenGL context for the current window. */
|
||||
class context
|
||||
{
|
||||
public:
|
||||
context(const context&) = delete;
|
||||
context& operator=(const context&) = delete;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param window The SDL window to attach a context to.
|
||||
*/
|
||||
context(sdl::window* window);
|
||||
|
||||
~context();
|
||||
|
||||
private:
|
||||
/** Sets any relevant flags for the GL context. */
|
||||
void set_context_flags();
|
||||
|
||||
/** The window's OpenGL context. */
|
||||
SDL_GLContext gl_context_;
|
||||
};
|
||||
|
||||
} // namespace gl
|
||||
|
||||
#endif // USE_GL_RENDERING
|
31
src/ogl/utils.cpp
Normal file
31
src/ogl/utils.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifdef USE_GL_RENDERING
|
||||
|
||||
#include "ogl/utils.hpp"
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace gl
|
||||
{
|
||||
void clear_screen()
|
||||
{
|
||||
// Fully alpha black
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
} // namespace gl
|
||||
|
||||
#endif // USE_GL_RENDERING
|
25
src/ogl/utils.hpp
Normal file
25
src/ogl/utils.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
Copyright (C) 2017 by the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef USE_GL_RENDERING
|
||||
|
||||
namespace gl
|
||||
{
|
||||
/** Fills the screen with fully-transparent black. */
|
||||
void clear_screen();
|
||||
|
||||
} // namespace gl
|
||||
|
||||
#endif // USE_GL_RENDERING
|
|
@ -35,6 +35,7 @@
|
|||
#include "log.hpp"
|
||||
#include "map/label.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "playturn.hpp"
|
||||
#include "random_deterministic.hpp"
|
||||
#include "replay_helper.hpp"
|
||||
|
@ -273,7 +274,11 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
const bool is_victory = get_end_level_data_const().is_victory;
|
||||
|
||||
if(gamestate().gamedata_.phase() <= game_data::PRESTART) {
|
||||
#ifdef USE_GL_RENDERING
|
||||
gl::clear_screen();
|
||||
#else
|
||||
gui_->video().clear_screen();
|
||||
#endif
|
||||
}
|
||||
|
||||
ai_testing::log_game_end();
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "sdl/surface.hpp"
|
||||
#include "sdl/window.hpp"
|
||||
|
||||
#include "ogl/utils.hpp"
|
||||
#include "sdl/surface.hpp"
|
||||
#include "sdl/exception.hpp"
|
||||
|
||||
#include <SDL_render.h>
|
||||
|
@ -36,6 +37,7 @@ window::window(const std::string& title,
|
|||
throw exception("Failed to create a SDL_Window object.", true);
|
||||
}
|
||||
|
||||
#ifndef USE_GL_RENDERING
|
||||
if(!SDL_CreateRenderer(window_, -1, render_flags)) {
|
||||
throw exception("Failed to create a SDL_Renderer object.", true);
|
||||
}
|
||||
|
@ -66,6 +68,7 @@ window::window(const std::string& title,
|
|||
fill(0,0,0);
|
||||
|
||||
render();
|
||||
#endif
|
||||
}
|
||||
|
||||
window::~window()
|
||||
|
@ -132,7 +135,11 @@ void window::fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
|||
|
||||
void window::render()
|
||||
{
|
||||
#ifdef USE_GL_RENDERING
|
||||
SDL_GL_SwapWindow(*this);
|
||||
#else
|
||||
SDL_RenderPresent(*this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void window::set_title(const std::string& title)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "font/sdl_ttf.hpp"
|
||||
#include "image.hpp"
|
||||
#include "log.hpp"
|
||||
#include "ogl/utils.hpp"
|
||||
#include "preferences/general.hpp"
|
||||
#include "sdl/point.hpp"
|
||||
#include "sdl/render_utils.hpp"
|
||||
|
@ -86,6 +87,9 @@ void trigger_full_redraw()
|
|||
|
||||
CVideo::CVideo(FAKE_TYPES type)
|
||||
: window()
|
||||
#ifdef USE_GL_RENDERING
|
||||
, gl_context()
|
||||
#endif
|
||||
, fake_screen_(false)
|
||||
, help_string_(0)
|
||||
, updated_locked_(0)
|
||||
|
@ -202,6 +206,9 @@ void CVideo::init_window()
|
|||
|
||||
// Add any more default flags here
|
||||
window_flags |= SDL_WINDOW_RESIZABLE;
|
||||
#ifdef USE_GL_RENDERING
|
||||
video_flags |= SDL_WINDOW_OPENGL;
|
||||
#endif
|
||||
|
||||
if(preferences::fullscreen()) {
|
||||
window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
|
@ -220,6 +227,14 @@ void CVideo::init_window()
|
|||
SDL_GetCurrentDisplayMode(window->get_display_index(), ¤tDisplayMode);
|
||||
refresh_rate_ = currentDisplayMode.refresh_rate != 0 ? currentDisplayMode.refresh_rate : 60;
|
||||
|
||||
#ifdef USE_GL_RENDERING
|
||||
// Initialize an OpenGL context for the window.
|
||||
gl_context.reset(new gl::context(window.get()));
|
||||
|
||||
gl::clear_screen();
|
||||
render_screen();
|
||||
#endif
|
||||
|
||||
event_handler_.join_global();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "events.hpp"
|
||||
#include "exceptions.hpp"
|
||||
#include "lua_jailbreak_exception.hpp"
|
||||
#include "ogl/context.hpp"
|
||||
|
||||
#include <SDL_render.h>
|
||||
|
||||
|
@ -246,6 +247,11 @@ private:
|
|||
/** The SDL window object. */
|
||||
std::unique_ptr<sdl::window> window;
|
||||
|
||||
#ifdef USE_GL_RENDERING
|
||||
/** The OpenGL context attached to the SDL window. */
|
||||
std::unique_ptr<gl::context> gl_context;
|
||||
#endif
|
||||
|
||||
/** Initializes the SDL video subsystem. */
|
||||
void initSDL();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue