add support for OpenGL extensions

This commit is contained in:
Ted John 2016-06-05 12:41:23 +01:00
parent 3a7ab9b20a
commit 8edc97bebe
4 changed files with 121 additions and 6 deletions

View File

@ -42,6 +42,7 @@
<ClCompile Include="src\diagnostic.c" />
<ClCompile Include="src\drawing\drawing.c" />
<ClCompile Include="src\drawing\drawing_fast.cpp" />
<ClCompile Include="src\drawing\engines\OpenGLAPI.cpp" />
<ClCompile Include="src\drawing\engines\OpenGLDrawingEngine.cpp" />
<ClCompile Include="src\drawing\engines\SoftwareDrawingEngine.cpp" />
<ClCompile Include="src\drawing\font.c" />
@ -336,6 +337,7 @@
<ClInclude Include="src\cursors.h" />
<ClInclude Include="src\diagnostic.h" />
<ClInclude Include="src\drawing\drawing.h" />
<ClInclude Include="src\drawing\engines\OpenGLAPI.h" />
<ClInclude Include="src\drawing\font.h" />
<ClInclude Include="src\drawing\IDrawingContext.h" />
<ClInclude Include="src\drawing\IDrawingEngine.h" />

View File

@ -0,0 +1,73 @@
#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
#include <SDL_platform.h>
#define NO_EXTERN_GLAPI
#include "OpenGLAPI.h"
#if __WINDOWS__
#include <SDL_video.h>
#include "../../core/Console.hpp"
#pragma comment(lib, "opengl32.lib")
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()
{
SetupOpenGLFunction(glCreateShader);
SetupOpenGLFunction(glDeleteShader);
return nullptr;
}
#endif /* __WINDOWS__ */
bool OpenGLAPI::Initialise()
{
#if __WINDOWS__
const char * failedProcName = TryLoadAllProcAddresses();
if (failedProcName != nullptr)
{
Console::Error::WriteFormat("Failed to load %s.\n", failedProcName);
return false;
}
#endif
return true;
}

View File

@ -0,0 +1,39 @@
#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
#pragma once
#include <SDL_opengl.h>
#if __WINDOWS__
#ifdef NO_EXTERN_GLAPI
#define GLAPI_DECL
#define GLAPI_SET = nullptr
#else
#define GLAPI_DECL extern
#define GLAPI_SET
#endif
GLAPI_DECL PFNGLCREATESHADERPROC glCreateShader GLAPI_SET;
GLAPI_DECL PFNGLDELETESHADERPROC glDeleteShader GLAPI_SET;
#endif /* __WINDOWS__ */
namespace OpenGLAPI
{
bool Initialise();
}

View File

@ -18,13 +18,9 @@
#include <vector>
#include <SDL_platform.h>
#ifdef __WINDOWS__
#include <windows.h>
#pragma comment(lib, "opengl32.lib")
#endif
#include <sdl_opengl.h>
#include "OpenGLAPI.h"
#include "../../core/Exception.hpp"
#include "../../core/Math.hpp"
#include "../../core/Memory.hpp"
#include "../IDrawingContext.h"
@ -131,6 +127,11 @@ public:
_context = SDL_GL_CreateContext(_window);
SDL_GL_MakeCurrent(_window, _context);
if (!OpenGLAPI::Initialise())
{
throw Exception("Unable to initialise OpenGL.");
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}