Skip to content

Commit

Permalink
split up opengl.h so it works with pragma once + gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
darglein committed Nov 12, 2019
1 parent 9d127cb commit a42470a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 78 deletions.
1 change: 1 addition & 0 deletions src/saiga/opengl/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "saiga/opengl/error.h"

#include "saiga/core/util/tostring.h"
#include "saiga/opengl/opengl_helper.h"

#include <iostream>

Expand Down
85 changes: 10 additions & 75 deletions src/saiga/opengl/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gl.h>

#include "saiga/config.h"

Expand All @@ -18,77 +18,12 @@

#include <glbinding/ProcAddress.h>
#include <glbinding/gl/gl.h>
#include <vector>
// 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<std::string> 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
File renamed without changes.
79 changes: 79 additions & 0 deletions src/saiga/opengl/opengl_helper.h
Original file line number Diff line number Diff line change
@@ -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 <vector>
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<std::string> 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
2 changes: 1 addition & 1 deletion src/saiga/opengl/shader/shaderPartLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
Expand Down
4 changes: 2 additions & 2 deletions src/saiga/opengl/window/OpenGLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit a42470a

Please sign in to comment.