Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created November 6, 2013 00:25
Embed
What would you like to do?
GLX interface
#ifndef __GLX_H__
#define __GLX_H__
#ifdef __cplusplus
extern "C" {
#endif
// GLX utilities - simple GL (4.2 core) on X11 handler.
typedef struct glx_context glx_context;
// Creates a GLX context and opens a window with given title and width/height
glx_context * glx_init( char const * title, int w, int h );
// Shuts down a GLX context and frees it.
void glx_shutdown( glx_context * glx );
// Processes X11 events. Returns 1 if OK, 0 if user requested exit.
int glx_handle_events( glx_context * glx );
// GL swap buffers.
void glx_swap_buffers( glx_context * glx );
// Compile a shader from source / from a file
GLuint glx_compile_shader_source( GLenum type, char const * source );
GLuint glx_compile_shader_file( GLenum type, char const * filename );
// Compile a program from vertex/fragment shaders and fix the attribute bind points.
// - "attribs" is a NULL-terminated array of strings that specify your attributes
// in order - e.g. attribs = { "position", "texcoord", NULL } will bind "position"
// to attribute 0 and "texcoord" to attribute 1. Specify NULL if you don't care,
// or if you fix them in the vertex shader.
GLuint glx_simple_program( GLuint vert_shader, GLuint frag_shader, char const ** attribs );
// Program for a compute shader, either from source or a file.
GLuint glx_compute_program_source( char const * source );
GLuint glx_compute_program_file( char const * filename );
// Create a GL buffer of given type, size and with given initial data.
GLuint glx_make_buffer( GLenum type, size_t size, void const * initial, GLenum usage );
// Read back texture mip level contents via glGetTexImage (mallocs result buffer)
void * glx_read_texture_level( GLuint tex, GLint level );
// GLX timer measures how long GL calls take on the server (GPU) side
// Create, call bracket begin/end around area you want to capture, then "report" at the end.
typedef struct glx_timer glx_timer;
glx_timer * glx_timer_create( size_t warmup_frames ); // warmup_frames = no. of initial measurements to throw away
void glx_timer_destroy( glx_timer * timer );
void glx_timer_bracket_begin( glx_timer * timer );
void glx_timer_bracket_end( glx_timer * timer );
void glx_timer_report( glx_timer * timer, char const * label );
#ifdef __cplusplus
}
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment