From a42470a7a2d5959d335265ac69d253e411eaebe7 Mon Sep 17 00:00:00 2001 From: Darius Rueckert Date: Tue, 12 Nov 2019 14:06:31 +0100 Subject: [PATCH] split up opengl.h so it works with pragma once + gcc --- src/saiga/opengl/error.cpp | 1 + src/saiga/opengl/opengl.h | 85 +++---------------- .../opengl/{opengl.cpp => opengl_helper.cpp} | 0 src/saiga/opengl/opengl_helper.h | 79 +++++++++++++++++ src/saiga/opengl/shader/shaderPartLoader.h | 2 +- src/saiga/opengl/window/OpenGLWindow.h | 4 +- 6 files changed, 93 insertions(+), 78 deletions(-) rename src/saiga/opengl/{opengl.cpp => opengl_helper.cpp} (100%) create mode 100644 src/saiga/opengl/opengl_helper.h diff --git a/src/saiga/opengl/error.cpp b/src/saiga/opengl/error.cpp index a18adbbe1..f3c1ce691 100644 --- a/src/saiga/opengl/error.cpp +++ b/src/saiga/opengl/error.cpp @@ -7,6 +7,7 @@ #include "saiga/opengl/error.h" #include "saiga/core/util/tostring.h" +#include "saiga/opengl/opengl_helper.h" #include diff --git a/src/saiga/opengl/opengl.h b/src/saiga/opengl/opengl.h index 3b0b3a925..0f2d1d532 100644 --- a/src/saiga/opengl/opengl.h +++ b/src/saiga/opengl/opengl.h @@ -4,11 +4,11 @@ * See LICENSE file for more information. */ -// I'm not sure why, but this pragma once doesn't work with precompiled headers and GCC 8/9. -// TODO: Check after a new gcc version comes out. -//#pragma once -#ifndef SAIGA_OPENGL_OPENGL_H -#define SAIGA_OPENGL_OPENGL_H +#pragma once + +// Include this file, if you want to use the OpenGL API. +// Do not directly include the loader library (glbinding/) or any other +// gl specific headers such as #include "saiga/config.h" @@ -18,77 +18,12 @@ #include #include -#include -// make sure nobody else includes gl.h after this -#define __gl_h_ -using namespace gl; -#define GLFW_INCLUDE_NONE - - - -namespace Saiga -{ -SAIGA_OPENGL_API std::ostream& operator<<(std::ostream& os, GLenum g); - -SAIGA_OPENGL_API void initOpenGL(glbinding::GetProcAddress func); -SAIGA_OPENGL_API void terminateOpenGL(); -SAIGA_OPENGL_API bool OpenGLisInitialized(); - -SAIGA_OPENGL_API int getVersionMajor(); -SAIGA_OPENGL_API int getVersionMinor(); -SAIGA_OPENGL_API void printOpenGLVersion(); - -SAIGA_OPENGL_API int getExtensionCount(); -SAIGA_OPENGL_API bool hasExtension(const std::string& ext); -SAIGA_OPENGL_API std::vector getExtensions(); - - - -enum class OpenGLVendor -{ - Nvidia, - Ati, - Intel, - Mesa, - Unknown -}; -SAIGA_OPENGL_API OpenGLVendor getOpenGLVendor(); - -struct SAIGA_OPENGL_API OpenGLParameters -{ - enum class Profile - { - ANY, - CORE, - COMPATIBILITY - }; - Profile profile = Profile::CORE; - - bool debug = true; - - // Throw an assertion if we get an opengl error. - bool assertAtError = false; - - // all functionality deprecated in the requested version of OpenGL is removed - bool forwardCompatible = false; - - int versionMajor = 3; - int versionMinor = 2; - - /** - * Reads all paramters from the given config file. - * Creates the file with the default values if it doesn't exist. - */ - void fromConfigFile(const std::string& file); -}; - -// called from OpenGLWindow::OpenGLWindow() -SAIGA_LOCAL void initSaigaGL(const OpenGLParameters& params); -SAIGA_LOCAL void cleanupSaigaGL(); +// glbinding places all gl functions into the gl namespace. +using namespace gl; -} // namespace Saiga +// Make sure g nobody else includes gl.h after this. +#define __gl_h_ +#define GLFW_INCLUDE_NONE #define SAIGA_OPENGL_INCLUDED - -#endif diff --git a/src/saiga/opengl/opengl.cpp b/src/saiga/opengl/opengl_helper.cpp similarity index 100% rename from src/saiga/opengl/opengl.cpp rename to src/saiga/opengl/opengl_helper.cpp diff --git a/src/saiga/opengl/opengl_helper.h b/src/saiga/opengl/opengl_helper.h new file mode 100644 index 000000000..40a131760 --- /dev/null +++ b/src/saiga/opengl/opengl_helper.h @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2017 Darius Rückert + * Licensed under the MIT License. + * See LICENSE file for more information. + */ + +// I'm not sure why, but this pragma once doesn't work with precompiled headers and GCC 8/9. +// TODO: Check after a new gcc version comes out. +#pragma once + +#include "opengl.h" + +#include +namespace Saiga +{ +SAIGA_OPENGL_API std::ostream& operator<<(std::ostream& os, GLenum g); + +SAIGA_OPENGL_API void initOpenGL(glbinding::GetProcAddress func); +SAIGA_OPENGL_API void terminateOpenGL(); +SAIGA_OPENGL_API bool OpenGLisInitialized(); + +SAIGA_OPENGL_API int getVersionMajor(); +SAIGA_OPENGL_API int getVersionMinor(); +SAIGA_OPENGL_API void printOpenGLVersion(); + +SAIGA_OPENGL_API int getExtensionCount(); +SAIGA_OPENGL_API bool hasExtension(const std::string& ext); +SAIGA_OPENGL_API std::vector getExtensions(); + + + +enum class OpenGLVendor +{ + Nvidia, + Ati, + Intel, + Mesa, + Unknown +}; + +SAIGA_OPENGL_API OpenGLVendor getOpenGLVendor(); + +struct SAIGA_OPENGL_API OpenGLParameters +{ + enum class Profile + { + ANY, + CORE, + COMPATIBILITY + }; + Profile profile = Profile::CORE; + + bool debug = true; + + // Throw an assertion if we get an opengl error. + bool assertAtError = false; + + // all functionality deprecated in the requested version of OpenGL is removed + bool forwardCompatible = false; + + int versionMajor = 3; + int versionMinor = 2; + + /** + * Reads all paramters from the given config file. + * Creates the file with the default values if it doesn't exist. + */ + void fromConfigFile(const std::string& file); +}; + +// called from OpenGLWindow::OpenGLWindow() +SAIGA_LOCAL void initSaigaGL(const OpenGLParameters& params); +SAIGA_LOCAL void cleanupSaigaGL(); + +} // namespace Saiga + +#define SAIGA_OPENGL_INCLUDED + +//#endif diff --git a/src/saiga/opengl/shader/shaderPartLoader.h b/src/saiga/opengl/shader/shaderPartLoader.h index 82181eed7..b0de1f1de 100644 --- a/src/saiga/opengl/shader/shaderPartLoader.h +++ b/src/saiga/opengl/shader/shaderPartLoader.h @@ -7,7 +7,7 @@ #pragma once #include "saiga/core/math/math.h" -#include "saiga/opengl/opengl.h" +#include "saiga/opengl/opengl_helper.h" #include "saiga/opengl/shader/shaderpart.h" #include diff --git a/src/saiga/opengl/window/OpenGLWindow.h b/src/saiga/opengl/window/OpenGLWindow.h index 1d54f142b..b2b88d1ce 100644 --- a/src/saiga/opengl/window/OpenGLWindow.h +++ b/src/saiga/opengl/window/OpenGLWindow.h @@ -6,9 +6,9 @@ #pragma once -#include "saiga/opengl/imgui/imgui_opengl.h" -#include "saiga/opengl/opengl.h" #include "saiga/core/window/WindowBase.h" +#include "saiga/opengl/imgui/imgui_opengl.h" +#include "saiga/opengl/opengl_helper.h" namespace Saiga {