Skip to content

Commit

Permalink
Integrate GLEW to the Visual Studio project
Browse files Browse the repository at this point in the history
I also removed USE_GL_RENDERING (OpenGL rendering is now used
unconditionally), moved initialization of gl::context out of the
constructor, and added some light logging about OpenGL (so that, in the
future with hardware-specific issues, we have a way to know which hardware
is affected).

This commit breaks build with anything except Visual Studio due to
requiring OpenGL and GLEW but not linking to them.
  • Loading branch information
jyrkive committed Sep 27, 2018
1 parent ae4ef05 commit 695c8ee
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 117 deletions.
20 changes: 10 additions & 10 deletions projectfiles/VC14/wesnoth.vcxproj
Expand Up @@ -119,7 +119,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\src;..\..\..\external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;DEBUG_LUA;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;GLEW_STATIC;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;DEBUG_LUA;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>UninitializedLocalUsageCheck</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
Expand All @@ -136,7 +136,7 @@
</ResourceCompile>
<Link>
<AdditionalOptions>/SAFESEH:NO %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;$(IntDir)liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;opengl32.lib;glew32s.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;$(IntDir)liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\..\external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>MSVCR90;MSVCRT;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
Expand All @@ -156,7 +156,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\..\src;..\..\..\external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;GLEW_STATIC;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand All @@ -175,7 +175,7 @@
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;$(IntDir)liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;opengl32.lib;glew32s.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;$(IntDir)liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\..\external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
Expand All @@ -199,7 +199,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\src;..\..\..\external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;DEBUG_LUA;MSVC_DO_UNIT_TESTS;BOOST_TEST_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;GLEW_STATIC;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;DEBUG_LUA;MSVC_DO_UNIT_TESTS;BOOST_TEST_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
Expand All @@ -215,7 +215,7 @@
<PreprocessorDefinitions>_MSC_VER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;Debug\liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;opengl32.lib;glew32s.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;Debug\liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)test.exe</OutputFile>
<AdditionalLibraryDirectories>..\..\..\external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
Expand All @@ -235,7 +235,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\..\src;..\..\..\external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;MSVC_DO_UNIT_TESTS;BOOST_TEST_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;GLEW_STATIC;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;MSVC_DO_UNIT_TESTS;BOOST_TEST_DYN_LINK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand All @@ -254,7 +254,7 @@
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;Release\liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;opengl32.lib;glew32s.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;Release\liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)test.exe</OutputFile>
<AdditionalLibraryDirectories>..\..\..\external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
Expand All @@ -281,7 +281,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<WholeProgramOptimization>false</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\..\src;..\..\..\external\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;GLEW_STATIC;_WINSOCK_DEPRECATED_NO_WARNINGS;BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=_WIN32_WINNT_WIN7;HAVE_PYTHON;USE_GZIP;NO_HAVE_FRIBIDI;HAVE_LIBPNG;NOMINMAX;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
Expand All @@ -300,7 +300,7 @@
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;$(IntDir)liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_image.lib;opengl32.lib;glew32s.lib;SDL2_ttf.lib;SDL2_mixer.lib;libcrypto.lib;cairo.lib;winmm.lib;ws2_32.lib;pango-1.0.lib;pangocairo-1.0.lib;gobject-2.0.lib;glib-2.0.lib;libpng.lib;$(IntDir)liblua.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\..\external\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
Expand Down
4 changes: 0 additions & 4 deletions src/editor/editor_display.cpp
Expand Up @@ -35,11 +35,7 @@ editor_display::editor_display(editor_controller& controller, const config& them
, 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)
Expand Down
4 changes: 0 additions & 4 deletions src/events.cpp
Expand Up @@ -623,11 +623,7 @@ void run_event_loop()
//
CVideo& video = CVideo::get_singleton();

#ifdef USE_GL_RENDERING
gl::clear_screen();
#else
video.clear_screen();
#endif

raise_draw_event();

Expand Down
5 changes: 0 additions & 5 deletions src/game_display.cpp
Expand Up @@ -71,12 +71,7 @@ game_display::game_display(game_board& board, std::weak_ptr<wb::manager> wb,
, mode_(RUNNING)
, needs_rebuild_(false)
{
#ifdef USE_GL_RENDERING
gl::clear_screen();
#else
video().clear_screen();
#endif

}

game_display::~game_display()
Expand Down
53 changes: 40 additions & 13 deletions src/ogl/context.cpp
Expand Up @@ -11,29 +11,58 @@
See the COPYING file for more details.
*/

#ifdef USE_GL_RENDERING

#include "ogl/context.hpp"

#include <SDL_video.h>
#include "log.hpp"

#include <GL/glew.h>
#include <SDL.h>

#include <iostream>
#include <stdexcept>

static lg::log_domain log_opengl("opengl");
#define LOG_GL LOG_STREAM(info, log_opengl)
#define ERR_GL LOG_STREAM(err, log_opengl)

namespace gl
{
context::context(sdl::window* window)
: gl_context_(SDL_GL_CreateContext(*window))

context::~context()
{
SDL_GL_DeleteContext(gl_context_);
}

void context::init(sdl::window* window)
{
// Set flags.
set_context_flags();

// Attempt to create the context.
gl_context_ = SDL_GL_CreateContext(*window);
if(gl_context_ == nullptr) {
ERR_GL << "Error creating OpenGL context: too old hardware/drivers?\n";
ERR_GL << SDL_GetError() << std::endl;
throw std::runtime_error("error creating OpenGL context");
}

// Initialize GLEW.
// TODO: should this be moved somewhere else?
glewExperimental = GL_TRUE;
glewInit();
}
GLenum result = glewInit();
if(result != GLEW_OK) {
ERR_GL << "Error initializing GLEW\n";
throw std::runtime_error("error initializing GLEW");
}

context::~context()
{
SDL_GL_DeleteContext(gl_context_);
// Print some information.
GLint profile;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
bool core_profile = profile & GL_CONTEXT_CORE_PROFILE_BIT;

LOG_GL << "Using OpenGL " << (core_profile ? "core profile " : "") <<
"version " << glGetString(GL_VERSION) << std::endl;
LOG_GL << "GPU: " <<
glGetString(GL_VENDOR) << " " << glGetString(GL_RENDERER) << std::endl;
}

void context::set_context_flags()
Expand All @@ -53,5 +82,3 @@ void context::set_context_flags()
}

}

#endif // USE_GL_RENDERING
19 changes: 4 additions & 15 deletions src/ogl/context.hpp
Expand Up @@ -13,39 +13,28 @@

#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() = default;
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();

void init(sdl::window* window);

private:
/** Sets any relevant flags for the GL context. */
void set_context_flags();

/** The window's OpenGL context. */
SDL_GLContext gl_context_;
SDL_GLContext gl_context_ = nullptr;
};

} // namespace gl

#endif // USE_GL_RENDERING
6 changes: 1 addition & 5 deletions src/ogl/utils.cpp
Expand Up @@ -11,11 +11,9 @@
See the COPYING file for more details.
*/

#ifdef USE_GL_RENDERING

#include "ogl/utils.hpp"

#include <GL/gl.h>
#include <GL/glew.h>

namespace gl
{
Expand All @@ -27,5 +25,3 @@ void clear_screen()
}

} // namespace gl

#endif // USE_GL_RENDERING
4 changes: 0 additions & 4 deletions src/ogl/utils.hpp
Expand Up @@ -13,13 +13,9 @@

#pragma once

#ifdef USE_GL_RENDERING

namespace gl
{
/** Fills the screen with fully-transparent black. */
void clear_screen();

} // namespace gl

#endif // USE_GL_RENDERING
4 changes: 0 additions & 4 deletions src/playsingle_controller.cpp
Expand Up @@ -269,11 +269,7 @@ 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();
Expand Down
38 changes: 1 addition & 37 deletions src/sdl/window.cpp
Expand Up @@ -27,45 +27,13 @@ window::window(const std::string& title,
const int y,
const int w,
const int h,
const uint32_t window_flags,
const uint32_t render_flags)
const uint32_t window_flags)
: window_(SDL_CreateWindow(title.c_str(), x, y, w, h, window_flags))
, info_()
{
if(!window_) {
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);
}

if(SDL_GetRendererInfo(*this, &info_) != 0) {
throw exception("Failed to retrieve the information of the renderer.",
true);
}

if(info_.num_texture_formats == 0) {
throw exception("The renderer has no texture information available.\n",
false);
}

if(!(info_.flags & SDL_RENDERER_TARGETTEXTURE)) {
throw exception("Render-to-texture not supported or enabled!", false);
}

// Set default blend mode to blend.
SDL_SetRenderDrawBlendMode(*this, SDL_BLENDMODE_BLEND);

// In fullscreen mode, do not minimize on focus loss.
// Minimizing was reported as bug #1606 with blocker priority.
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");

fill(0,0,0);

render();
#endif
}

window::~window()
Expand Down Expand Up @@ -132,11 +100,7 @@ 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)
Expand Down
4 changes: 1 addition & 3 deletions src/sdl/window.hpp
Expand Up @@ -61,15 +61,13 @@ class window
* @param w Used as w for @ref SDL_CreateWindow.
* @param h Used as x for @ref SDL_CreateWindow.
* @param window_flags Used as flags for @ref SDL_CreateWindow.
* @param render_flags Used as flags for @ref SDL_CreateRenderer.
*/
window(const std::string& title,
const int x,
const int y,
const int w,
const int h,
const uint32_t window_flags,
const uint32_t render_flags);
const uint32_t window_flags);

~window();

Expand Down

0 comments on commit 695c8ee

Please sign in to comment.