1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#include <iostream>
#include <map>
#include <array>
#include <set>
#include <cstring>
#include <GLFW/glfw3.h>
#include <glbinding-aux/Meta.h>
#include <glbinding/AbstractFunction.h>
#include <glbinding-aux/ContextInfo.h>
#include <glbinding/Version.h>
#include <glbinding/glbinding.h>
#include <glbinding/gl/gl.h>
#include <glbinding-aux/ValidVersions.h>
#include <glbinding-aux/types_to_string.h>
using namespace gl;
using namespace glbinding;
void error(int errnum, const char * errmsg)
{
std::cerr << errnum << ": " << errmsg << std::endl;
}
void print(
const Version & version
, const bool forward
, const bool core
, const Version & result
, const bool isForward
, const bool isCore)
{
std::cout << " "
<< version << " " << (forward ? "f" : "-") << " " << (core ? "c" : "-") << " " << result << (isForward ? "f" : "") << (isCore ? "c" : "") << std::endl;
}
bool isCore(const Version & version)
{
if (version<glbinding::Version(3,2))
{
return false;
}
GLint value = 0;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value);
return (value & static_cast<unsigned int>(GL_CONTEXT_CORE_PROFILE_BIT)) > 0;
}
Version printVersionOfContextRequest(
const Version & version
, const bool forward
, const bool core)
{
if (version < Version(3, 2) && (forward || core))
{
print(version, forward, core, Version(), false, false);
return Version();
}
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, false);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, version.majorVersion());
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, version.minorVersion());
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, forward);
if (core)
{
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
}
GLFWwindow * window = glfwCreateWindow(320, 240, "", nullptr, nullptr);
if (!window)
{
print(version, forward, core, Version(), false, false);
return Version();
}
glfwMakeContextCurrent(window);
glbinding::initialize(glfwGetProcAddress, true);
auto result = aux::ContextInfo::version();
glfwMakeContextCurrent(window);
print(version, forward, core, result, forward, isCore(result));
glfwMakeContextCurrent(nullptr);
glfwDestroyWindow(window);
return result;
}
int main(int argc, char * argv[])
{
glfwSetErrorCallback(error);
if (!glfwInit())
return 1;
std::cout << std::endl << "test: requesting all context configurations ..." << std::endl
<< std::endl << " scheme: <requested_version> <forward> <core> <created_version>" << std::endl << std::endl;
std::map<Version, std::array<Version, 4>> markdown;
for (const auto & version : aux::ValidVersions::versions())
{
markdown[version][0] = printVersionOfContextRequest(version, false, false);
markdown[version][1] = printVersionOfContextRequest(version, false, true);
markdown[version][2] = printVersionOfContextRequest(version, true, false);
markdown[version][3] = printVersionOfContextRequest(version, true, true);
std::cout << std::endl;
}
auto printMarkdown = false;
for (int i = 0; i < argc; ++i)
printMarkdown |= (strcmp(argv[i], "--markdown") == 0);
if (printMarkdown)
{
std::cout << "printing markdown formatted results ..." << std::endl;
std::cout << std::endl << "|";
for (const auto & version : aux::ValidVersions::versions())
std::cout << version << (version != aux::ValidVersions::latest() ? "<br>" : "");
for (int i = 0; i < 4; ++i)
{
std::cout << "|";
for (const auto & version : aux::ValidVersions::versions())
std::cout << markdown[version][i] << (version != aux::ValidVersions::latest() ? "<br>" : "");
}
std::cout << "|" << std::endl << std::endl;
}
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, false);
#ifdef SYSTEM_DARWIN
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
GLFWwindow * window = glfwCreateWindow(320, 240, "", nullptr, nullptr);
if (!window)
{
glfwTerminate();
return -1;
}
glfwHideWindow(window);
glfwMakeContextCurrent(window);
glbinding::initialize(glfwGetProcAddress, false); // only resolve functions that are actually used (lazy)
// print some gl infos (query)
std::cout
<< "OpenGL Version: " << aux::ContextInfo::version() << std::endl
<< "OpenGL Vendor: " << aux::ContextInfo::vendor() << std::endl
<< "OpenGL Renderer: " << aux::ContextInfo::renderer() << std::endl
<< "OpenGL Revision: " << aux::Meta::glRevision() << " (gl.xml)" << std::endl << std::endl;
glfwTerminate();
return 0;
}
|