Files
OpenRCT2-Web/src/drawing/engines/opengl/OpenGLAPI.cpp
T

126 lines
4.0 KiB
C++
Raw Normal View History

2016-06-05 12:41:23 +01:00
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 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 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
2016-06-05 23:43:58 +01:00
#ifndef DISABLE_OPENGL
2016-06-05 12:41:23 +01:00
#define NO_EXTERN_GLAPI
#include "OpenGLAPI.h"
#if OPENGL_NO_LINK
2016-06-05 12:41:23 +01:00
#include <SDL_video.h>
2016-06-06 23:57:01 +01:00
#include "../../../core/Console.hpp"
2016-06-05 12:41:23 +01:00
template <typename T>
static inline bool SetProc(T * func, const char * name)
{
T address = (T)SDL_GL_GetProcAddress(name);
if (address == nullptr)
{
return false;
}
*func = address;
return true;
}
#define SetupOpenGLFunction(func) \
{ \
if (!SetProc(&func, "" #func "")) \
{ \
return "" #func ""; \
} \
}
static const char * TryLoadAllProcAddresses()
{
2016-06-06 19:03:18 +01:00
// 1.1 functions
2016-06-08 23:13:49 +01:00
SetupOpenGLFunction(glActiveTexture);
2016-06-06 19:03:18 +01:00
SetupOpenGLFunction(glBegin);
SetupOpenGLFunction(glBindTexture);
SetupOpenGLFunction(glBlendFunc);
SetupOpenGLFunction(glClear);
SetupOpenGLFunction(glClearColor);
2016-06-11 02:24:39 +01:00
SetupOpenGLFunction(glCullFace);
2016-06-06 19:03:18 +01:00
SetupOpenGLFunction(glDeleteTextures);
SetupOpenGLFunction(glDisable);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glDrawArrays);
2016-06-06 19:03:18 +01:00
SetupOpenGLFunction(glEnable);
SetupOpenGLFunction(glEnd);
SetupOpenGLFunction(glGenTextures);
2016-06-08 21:24:39 +01:00
SetupOpenGLFunction(glGetError);
2016-06-11 02:24:39 +01:00
SetupOpenGLFunction(glReadPixels);
2016-06-06 19:03:18 +01:00
SetupOpenGLFunction(glTexImage2D);
SetupOpenGLFunction(glTexParameteri);
SetupOpenGLFunction(glViewport);
// 2.0+ functions
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glAttachShader);
SetupOpenGLFunction(glBindBuffer);
2016-06-08 21:24:39 +01:00
SetupOpenGLFunction(glBindFragDataLocation);
2016-06-11 02:24:39 +01:00
SetupOpenGLFunction(glBindFramebuffer);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glBindVertexArray);
SetupOpenGLFunction(glBufferData);
SetupOpenGLFunction(glCompileShader);
SetupOpenGLFunction(glCreateProgram);
2016-06-05 12:41:23 +01:00
SetupOpenGLFunction(glCreateShader);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glDeleteBuffers);
2016-06-11 02:24:39 +01:00
SetupOpenGLFunction(glDeleteFramebuffers);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glDeleteProgram);
2016-06-05 12:41:23 +01:00
SetupOpenGLFunction(glDeleteShader);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glDeleteVertexArrays);
SetupOpenGLFunction(glDetachShader);
SetupOpenGLFunction(glEnableVertexAttribArray);
2016-06-11 02:24:39 +01:00
SetupOpenGLFunction(glFramebufferTexture2D);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glGetAttribLocation);
SetupOpenGLFunction(glGenBuffers);
2016-06-11 02:24:39 +01:00
SetupOpenGLFunction(glGenFramebuffers);
2016-06-08 21:24:39 +01:00
SetupOpenGLFunction(glGetProgramInfoLog);
SetupOpenGLFunction(glGetProgramiv);
2016-06-06 23:57:01 +01:00
SetupOpenGLFunction(glGetShaderInfoLog);
SetupOpenGLFunction(glGetShaderiv);
SetupOpenGLFunction(glGetUniformLocation);
SetupOpenGLFunction(glGenVertexArrays);
SetupOpenGLFunction(glLinkProgram);
SetupOpenGLFunction(glShaderSource);
SetupOpenGLFunction(glUniform1i);
SetupOpenGLFunction(glUniform2i);
SetupOpenGLFunction(glUniform4f);
SetupOpenGLFunction(glUniform4i);
SetupOpenGLFunction(glUseProgram);
2016-06-08 21:24:39 +01:00
SetupOpenGLFunction(glVertexAttribIPointer);
2016-06-08 23:13:49 +01:00
SetupOpenGLFunction(glVertexAttribPointer);
2016-06-05 12:41:23 +01:00
return nullptr;
}
#endif /* #if OPENGL_NO_LINK */
2016-06-05 12:41:23 +01:00
bool OpenGLAPI::Initialise()
{
#ifdef OPENGL_NO_LINK
2016-06-05 12:41:23 +01:00
const char * failedProcName = TryLoadAllProcAddresses();
if (failedProcName != nullptr)
{
Console::Error::WriteFormat("Failed to load %s.\n", failedProcName);
return false;
}
#endif
return true;
}
2016-06-05 23:43:58 +01:00
#endif /* DISABLE_OPENGL */