graphene

view src/opengl.cc @ 6:9fbbc96e6fbe

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 31 Jul 2015 04:59:28 +0300
parents
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "opengl.h"
6 namespace gph {
8 GLCaps glcaps;
10 static void fill_glcaps();
11 static void print_glcaps(GLCaps *caps);
13 bool init_opengl()
14 {
15 glewInit();
16 fill_glcaps();
17 return true;
18 }
20 static void fill_glcaps()
21 {
22 memset(&glcaps, 0, sizeof glcaps);
24 glcaps.version = strdup((const char*)glGetString(GL_VERSION));
25 glcaps.renderer = strdup((const char*)glGetString(GL_RENDERER));
26 glcaps.vendor = strdup((const char*)glGetString(GL_VENDOR));
28 glcaps.sdr = GLEW_ARB_shading_language_100;
29 if(glcaps.sdr) {
30 glcaps.sdr_ver = strdup((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
31 }
33 glcaps.fbo = GLEW_ARB_framebuffer_object || GLEW_EXT_framebuffer_object;
34 glcaps.tex_float = GLEW_ARB_texture_float;
35 glcaps.npow2_tex = GLEW_ARB_texture_non_power_of_two;
36 glcaps.fsaa = GLEW_ARB_multisample;
38 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glcaps.max_tex_units);
39 if(glcaps.fbo) {
40 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glcaps.max_mrt);
41 }
42 if(glcaps.fsaa) {
43 glGetIntegerv(GL_MAX_SAMPLES, &glcaps.max_samples);
44 } else {
45 glcaps.max_samples = 1;
46 }
47 if(GLEW_EXT_texture_filter_anisotropic) {
48 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glcaps.max_aniso);
49 } else {
50 glcaps.max_aniso = 1.0f;
51 }
53 print_glcaps(&glcaps);
54 }
56 static void print_glcaps(GLCaps *caps)
57 {
58 printf("OpenGL %s - %s - %s\n", caps->version, caps->vendor, caps->renderer);
60 printf("--- capabilities ---\n");
61 printf(" GLSL shaders: %s\n", caps->sdr ? "yes" : "no");
62 if(caps->sdr) {
63 printf(" GLSL version: %s\n", caps->sdr_ver);
64 }
65 printf("framebuffer objects: %s\n", caps->fbo ? "yes" : "no");
66 if(caps->fbo) {
67 printf(" max render targets: %d\n", caps->max_mrt);
68 }
69 printf(" antialiasing: %s\n", caps->fsaa ? "yes" : "no");
70 if(caps->fsaa) {
71 printf(" max samples: %d\n", caps->max_samples);
72 }
73 printf(" float textures: %s\n", caps->tex_float ? "yes" : "no");
74 printf(" non-pow2 textures: %s\n", caps->npow2_tex ? "yes" : "no");
75 printf(" texture units: %d\n", caps->max_tex_units);
76 printf("--------------------\n");
77 }
79 } // namespace gph