graphene

diff src/opengl.cc @ 1:f85a59195206

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 24 Jul 2015 01:28:00 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/opengl.cc	Fri Jul 24 01:28:00 2015 +0300
     1.3 @@ -0,0 +1,79 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <string.h>
     1.7 +#include "opengl.h"
     1.8 +
     1.9 +namespace gph {
    1.10 +
    1.11 +GLCaps glcaps;
    1.12 +
    1.13 +static void fill_glcaps();
    1.14 +static void print_glcaps(GLCaps *caps);
    1.15 +
    1.16 +bool init_opengl()
    1.17 +{
    1.18 +	glewInit();
    1.19 +	fill_glcaps();
    1.20 +	return true;
    1.21 +}
    1.22 +
    1.23 +static void fill_glcaps()
    1.24 +{
    1.25 +	memset(&glcaps, 0, sizeof glcaps);
    1.26 +
    1.27 +	glcaps.version = strdup((const char*)glGetString(GL_VERSION));
    1.28 +	glcaps.renderer = strdup((const char*)glGetString(GL_RENDERER));
    1.29 +	glcaps.vendor = strdup((const char*)glGetString(GL_VENDOR));
    1.30 +
    1.31 +	glcaps.sdr = GLEW_ARB_shading_language_100;
    1.32 +	if(glcaps.sdr) {
    1.33 +		glcaps.sdr_ver = strdup((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
    1.34 +	}
    1.35 +
    1.36 +	glcaps.fbo = GLEW_ARB_framebuffer_object || GLEW_EXT_framebuffer_object;
    1.37 +	glcaps.tex_float = GLEW_ARB_texture_float;
    1.38 +	glcaps.npow2_tex = GLEW_ARB_texture_non_power_of_two;
    1.39 +	glcaps.fsaa = GLEW_ARB_multisample;
    1.40 +
    1.41 +	glGetIntegerv(GL_MAX_TEXTURE_UNITS, &glcaps.max_tex_units);
    1.42 +	if(glcaps.fbo) {
    1.43 +		glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glcaps.max_mrt);
    1.44 +	}
    1.45 +	if(glcaps.fsaa) {
    1.46 +		glGetIntegerv(GL_MAX_SAMPLES, &glcaps.max_samples);
    1.47 +	} else {
    1.48 +		glcaps.max_samples = 1;
    1.49 +	}
    1.50 +	if(GLEW_EXT_texture_filter_anisotropic) {
    1.51 +		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glcaps.max_aniso);
    1.52 +	} else {
    1.53 +		glcaps.max_aniso = 1.0f;
    1.54 +	}
    1.55 +
    1.56 +	print_glcaps(&glcaps);
    1.57 +}
    1.58 +
    1.59 +static void print_glcaps(GLCaps *caps)
    1.60 +{
    1.61 +	printf("OpenGL %s - %s - %s\n", caps->version, caps->vendor, caps->renderer);
    1.62 +
    1.63 +	printf("--- capabilities ---\n");
    1.64 +	printf("       GLSL shaders: %s\n", caps->sdr ? "yes" : "no");
    1.65 +	if(caps->sdr) {
    1.66 +		printf("       GLSL version: %s\n", caps->sdr_ver);
    1.67 +	}
    1.68 +	printf("framebuffer objects: %s\n", caps->fbo ? "yes" : "no");
    1.69 +	if(caps->fbo) {
    1.70 +		printf(" max render targets: %d\n", caps->max_mrt);
    1.71 +	}
    1.72 +	printf("       antialiasing: %s\n", caps->fsaa ? "yes" : "no");
    1.73 +	if(caps->fsaa) {
    1.74 +		printf("        max samples: %d\n", caps->max_samples);
    1.75 +	}
    1.76 +	printf("     float textures: %s\n", caps->tex_float ? "yes" : "no");
    1.77 +	printf("  non-pow2 textures: %s\n", caps->npow2_tex ? "yes" : "no");
    1.78 +	printf("      texture units: %d\n", caps->max_tex_units);
    1.79 +	printf("--------------------\n");
    1.80 +}
    1.81 +
    1.82 +}	// namespace gph