Skip to content

Instantly share code, notes, and snippets.

Created September 2, 2016 06:59
Show Gist options
  • Save anonymous/67f42faa92741cd7ca5b5ba0966b4ab9 to your computer and use it in GitHub Desktop.
Save anonymous/67f42faa92741cd7ca5b5ba0966b4ab9 to your computer and use it in GitHub Desktop.
emscripten webgl 2 errors
#define GL_GLEXT_PROTOTYPES
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES3/gl3.h>
#include <stdio.h>
#include <emscripten.h>
#include <emscripten/html5.h>
#define GL_CALL( x ) \
{ \
x; \
GLenum error = glGetError(); \
if( error != GL_NO_ERROR ) \
printf( "GL ERROR: %d, %s\n", (int)error, #x ); \
} \
int main()
{
emscripten_set_canvas_size( 100, 100 );
EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
attrs.enableExtensionsByDefault = 1;
attrs.majorVersion = 2;
attrs.minorVersion = 0;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( 0, &attrs );
emscripten_webgl_make_context_current(context);
EM_BOOL enabled = emscripten_webgl_enable_extension( context, "EXT_texture_filter_anisotropic" );
printf("anisotropy enabled: %d\n", enabled);
// Anisotropy
//
GLfloat maxAnisotropy;
GL_CALL( glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy) );
printf("max anisotropy: %f\n", maxAnisotropy);
// Vertex Arrays
//
GLuint vao1;
GL_CALL( glGenVertexArrays( 1, &vao1 ) );
GL_CALL( glBindVertexArray( vao1 ) );
printf( "vao1: %d\n", vao1 );
GLint vao2;
GL_CALL( glGetIntegerv( GL_VERTEX_ARRAY_BINDING, &vao2 ) );
printf( "vao2: %d\n", vao2 );
// Sampler Objects
//
GLuint sampler;
GL_CALL( glGenSamplers( 1, &sampler ) );
GL_CALL( glSamplerParameteri( sampler, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (int)maxAnisotropy ) );
GL_CALL( glBindSampler( 0, sampler ) );
GLint sampler2;
GL_CALL( glGetIntegerv( GL_SAMPLER_BINDING, &sampler2 ) );
printf( "sampler2: %d\n", sampler2 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment