File: main.cpp

package info (click to toggle)
glbinding 3.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,972 kB
  • sloc: cpp: 224,461; javascript: 1,615; sh: 114; makefile: 98
file content (156 lines) | stat: -rw-r--r-- 4,002 bytes parent folder | download | duplicates (2)
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

#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#include <GLFW/glfw3.h>

#include <glbinding/AbstractFunction.h>
#include <glbinding/Version.h>
#include <glbinding/glbinding.h>

#include <glbinding/gl/gl.h>

#include <glbinding-aux/Meta.h>
#include <glbinding-aux/ContextInfo.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 printExtensions(const std::set<std::string> & extensions)
{
    size_t column = 8;

    for (auto it = extensions.begin(); it != extensions.end(); ++it)
    {
        const auto & extensionString = *it;

        if (column > 8 && column + extensionString.size() > 78)
        {
            std::cout << std::endl << "\t";
            column = 8;
        }

        std::cout << extensionString;

        auto endOfIt = it;
        ++endOfIt;
        if (endOfIt != extensions.end())
        {
            std::cout << ", ";

            column += extensionString.size();
        }
        else
        {
            std::cout << std::endl;
        }
    }
}

void printInfos()
{
    // gather available extensions

    std::set<std::string> unknownExts;

    const auto supportedExtensions = aux::ContextInfo::extensions(unknownExts);

    auto extensionsByVersion = std::map<Version, std::set<GLextension>>();

    auto versions = aux::Meta::versions();
    versions.insert(Version{}); // provide NONE Version for extensions without associated version

    for (const auto & version : versions)
    {
        const auto extensions = aux::Meta::extensions(version);
        if (extensions.empty())
            continue;

        extensionsByVersion[version] = extensions;
    }

    if (!unknownExts.empty())
    {
        std::cout << std::endl << "Miscellaneous: " << unknownExts.size() << " Extensions" << std::endl << "\t";

        printExtensions(unknownExts);
    }

    for (const auto & pair : extensionsByVersion)
    {
        auto supported = size_t(0);
        const auto required = pair.second.size();
        std::set<std::string> extensionStrings;
        for (const auto & ext : pair.second)
        {
            supported += supportedExtensions.find(ext) != supportedExtensions.cend() ? 1 : 0;
            extensionStrings.insert(aux::Meta::getString(ext));
        }

        if (pair.first.isNull())
        {
            std::cout << std::endl << "Unassociated: " << supported << " Extensions" << std::endl << "\t";
        }
        else
        {
            std::cout << std::endl << "Feature " << pair.first.toString() << (supported == required ? " (supported)" : "") << ": " << supported << " of " << required << " Extensions" << std::endl << "\t";
        }

        printExtensions(extensionStrings);
    }
}

int main()
{
    glfwSetErrorCallback(error);

    if (!glfwInit())
        return 1;

    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

    auto window = glfwCreateWindow(320, 240, "", nullptr, nullptr);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }
    glfwHideWindow(window);

    glfwMakeContextCurrent(window);

	glbinding::initialize(glfwGetProcAddress, true);

    printInfos();

	// print some gl infos (query)

	std::cout << std::endl
		<< "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;
}