34#ifndef _ACF_UTILS_GLUTILS_H_
35#define _ACF_UTILS_GLUTILS_H_
54#define MAT4_ALLOC_ALIGN 32
56#define MAT4_ALLOC_ALIGN 16
136 return (quads->vbo != 0);
144#define glutils_init_2D_quads(__quads, __p, __t, __num_pts) \
145 glutils_init_2D_quads_impl((__quads), log_basename(__FILE__), \
146 __LINE__, (__p), (__t), (__num_pts))
148 const char *filename,
int line,
const vect2_t *p,
const vect2_t *t,
152#define glutils_update_2D_quads(__quads, __p, __t, __num_pts) \
153 glutils_update_2D_quads_impl((__quads), log_basename(__FILE__), \
154 __LINE__, (__p), (__t), (__num_pts))
156 const char *filename,
int line,
const vect2_t *p,
const vect2_t *t,
170#define glutils_init_3D_quads(__quads, __p, __t, __num_pts) \
171 glutils_init_3D_quads_impl((__quads), log_basename(__FILE__), \
172 __LINE__, (__p), (__t), (__num_pts))
174 const char *filename,
int line,
const vect3_t *p,
const vect2_t *t,
183#define glutils_update_3D_quads(__quads, __p, __t, __num_pts) \
184 glutils_update_3D_quads_impl((__quads), log_basename(__FILE__), \
185 __LINE__, (__p), (__t), (__num_pts))
187 const char *filename,
int line,
const vect3_t *p,
const vect2_t *t,
209#define glutils_init_3D_lines(__lines, __p, __num_pts) \
210 glutils_init_3D_lines_impl((__lines), log_basename(__FILE__), \
211 __LINE__, (__p), (__num_pts))
213 const char *filename,
int line,
const vect3_t *p,
size_t num_pts);
224 glutils_cache_t *cache,
const vect2_t *p,
const vect2_t *t,
size_t num_pts);
226 glutils_cache_t *cache,
const vect3_t *p,
const vect2_t *t,
size_t num_pts);
228 glutils_cache_t *cache,
const vect3_t *p,
size_t num_pts);
232#define GLUTILS_VALIDATE_INDICES(indices, num_idx, num_vtx) \
234 for (unsigned i = 0; i < (num_idx); i++) { \
235 VERIFY_MSG((indices)[i] < (num_vtx), "invalid index " \
236 "specification encountered, index %d (value %d) " \
237 "is outside of vertex range %d", i, (indices)[i], \
296#define TEXSZ_MK_TOKEN(name) \
297 static const char *__texsz_token_ ## name = #name
303#define TEXSZ_DECL_TOKEN_GLOB(name) \
304 extern const char *__texsz_token_ ## name
310#define TEXSZ_DEF_TOKEN_GLOB(name) \
311 const char *__texsz_token_ ## name = #name
326#define TEXSZ_ALLOC(__token_id, __format, __type, __w, __h) \
327 TEXSZ_ALLOC_INSTANCE(__token_id, NULL, NULL, -1, (__format), \
328 (__type), (__w), (__h))
334#define TEXSZ_FREE(__token_id, __format, __type, __w, __h) \
335 TEXSZ_FREE_INSTANCE(__token_id, NULL, (__format), \
336 (__type), (__w), (__h))
361#define TEXSZ_ALLOC_INSTANCE(__token_id, __instance, __filename, __line, \
362 __format, __type, __w, __h) \
363 glutils_texsz_alloc(__texsz_token_ ## __token_id, (__instance), \
364 (__filename), (__line), (__format), (__type), (__w), (__h))
373#define TEXSZ_FREE_INSTANCE(__token_id, __instance, __format, __type, \
375 glutils_texsz_free(__texsz_token_ ## __token_id, (__instance), \
376 (__format), (__type), (__w), (__h))
383#define TEXSZ_ALLOC_BYTES(__token_id, __bytes) \
384 TEXSZ_ALLOC_BYTES_INSTANCE(__token_id, NULL, NULL, -1, (__bytes))
390#define TEXSZ_FREE_BYTES(__token_id, __bytes) \
391 TEXSZ_FREE_BYTES_INSTANCE(__token_id, NULL, (__bytes))
398#define TEXSZ_ALLOC_BYTES_INSTANCE(__token_id, __instance, __filename, \
400 glutils_texsz_alloc_bytes(__texsz_token_ ## __token_id, (__instance), \
401 (__filename), (__line), (__bytes))
408#define TEXSZ_FREE_BYTES_INSTANCE(__token_id, __instance, __bytes) \
409 glutils_texsz_free_bytes(__texsz_token_ ## __token_id, (__instance), \
415 const char *filename,
int line, GLenum format, GLenum type,
416 unsigned w,
unsigned h);
418 GLenum format, GLenum type,
unsigned w,
unsigned h);
420 const void *instance,
const char *filename,
int line, int64_t bytes);
422 const void *instance, int64_t bytes);
434#define IF_TEXSZ(__xxx) \
436 if (glutils_texsz_inited()) { \
442#ifndef _LACF_RENDER_DEBUG
450#define _LACF_RENDER_DEBUG 0
493#if _LACF_RENDER_DEBUG
494#define GLUTILS_ASSERT_NO_ERROR() VERIFY3U(glGetError(), ==, GL_NO_ERROR)
495#define GLUTILS_ASSERT(_x_) VERIFY(_x_)
496#define GLUTILS_ASSERT_MSG(_x_, ...) VERIFY(_x_, __VA_ARGS__)
497#define GLUTILS_ASSERT3S(_x_, _y_, _z_) VERIFY3S(_x_, _y_, _z_)
498#define GLUTILS_ASSERT3U(_x_, _y_, _z_) VERIFY3U(_x_, _y_, _z_)
499#define GLUTILS_ASSERT3P(_x_, _y_, _z_) VERIFY3P(_x_, _y_, _z_)
500#define GLUTILS_RESET_ERRORS() glutils_reset_errors()
502#define GLUTILS_ASSERT_NO_ERROR()
503#define GLUTILS_ASSERT(_x_)
504#define GLUTILS_ASSERT_MSG(_x_, ...)
505#define GLUTILS_ASSERT3S(_x_, _y_, _z_)
506#define GLUTILS_ASSERT3U(_x_, _y_, _z_)
507#define GLUTILS_ASSERT3P(_x_, _y_, _z_)
508#define GLUTILS_RESET_ERRORS()
520 while (glGetError() != GL_NO_ERROR)
554#if _LACF_RENDER_DEBUG && !APL
556PRINTF_ATTR(2) static inline
void
563 va_start(ap, format);
564 len = vsnprintf(buf_stack,
sizeof (buf_stack), format, ap);
567 if (len >= (
int)
sizeof (buf_stack)) {
570 va_start(ap, format);
571 vsnprintf(buf_heap, len + 1, format, ap);
574 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, msgid, len,
579 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, msgid, len,
592ALWAYS_INLINE_ATTR PRINTF_ATTR(2) static inline
void
600ALWAYS_INLINE_ATTR
static inline void
632 GLboolean normalized,
size_t stride,
size_t offset)
635 glEnableVertexAttribArray(index);
636 glVertexAttribPointer(index, size, type, normalized,
637 stride, (
void *)offset);
652 glDisableVertexAttribArray(index);
656 GLint *int_fmt, GLint *fmt, GLint *type);
void glutils_nl_draw(glutils_nl_t *nl, float width, GLuint prog)
static void glutils_reset_errors(void)
void glutils_texsz_init(void)
static void glutils_disable_vtx_attr_ptr(GLint index)
uint64_t glutils_texsz_get(void)
void glutils_draw_lines(glutils_lines_t *lines, GLint prog)
glutils_nl_t * glutils_nl_alloc_3D(const vec3 *pts, size_t num_pts)
void glutils_texsz_alloc(const char *token, const void *instance, const char *filename, int line, GLenum format, GLenum type, unsigned w, unsigned h)
bool_t glutils_nsight_debugger_present(void)
void glutils_sys_init(void)
glutils_nl_t * glutils_nl_alloc_2D(const vec2 *pts, size_t num_pts)
void glutils_update_3D_quads_impl(glutils_quads_t *quads, const char *filename, int line, const vect3_t *p, const vect2_t *t, size_t num_pts)
void glutils_init_3D_quads_impl(glutils_quads_t *quads, const char *filename, int line, const vect3_t *p, const vect2_t *t, size_t num_pts)
bool_t glutils_texsz_inited(void)
void glutils_init_2D_quads_impl(glutils_quads_t *quads, const char *filename, int line, const vect2_t *p, const vect2_t *t, size_t num_pts)
void glutils_destroy_lines(glutils_lines_t *lines)
void glutils_cache_destroy(glutils_cache_t *cache)
static void glutils_debug_pop(void)
static void glutils_debug_push(GLuint msgid, const char *format,...)
void glutils_init_3D_lines_impl(glutils_lines_t *lines, const char *filename, int line, const vect3_t *p, size_t num_pts)
void glutils_disable_all_vtx_attrs(void)
void glutils_destroy_quads(glutils_quads_t *quads)
glutils_quads_t * glutils_cache_get_2D_quads(glutils_cache_t *cache, const vect2_t *p, const vect2_t *t, size_t num_pts)
static bool_t glutils_quads_inited(const glutils_quads_t *quads)
glutils_lines_t * glutils_cache_get_3D_lines(glutils_cache_t *cache, const vect3_t *p, size_t num_pts)
void(* glutils_texsz_enum_cb_t)(const char *token, int64_t bytes, void *userinfo)
void glutils_update_2D_quads_impl(glutils_quads_t *quads, const char *filename, int line, const vect2_t *p, const vect2_t *t, size_t num_pts)
glutils_quads_t * glutils_cache_get_3D_quads(glutils_cache_t *cache, const vect3_t *p, const vect2_t *t, size_t num_pts)
GLuint glutils_make_quads_IBO(size_t num_vtx)
static void glutils_enable_vtx_attr_ptr(GLint index, GLint size, GLenum type, GLboolean normalized, size_t stride, size_t offset)
void glutils_draw_quads(glutils_quads_t *quads, GLint prog)
void glutils_disable_all_client_state(void)
bool_t glutils_png2gltexfmt(int png_color_type, int png_bit_depth, GLint *int_fmt, GLint *fmt, GLint *type)
void glutils_texsz_fini(void)
void glutils_texsz_enum(glutils_texsz_enum_cb_t cb, void *userinfo)
void glutils_texsz_alloc_bytes(const char *token, const void *instance, const char *filename, int line, int64_t bytes)
glutils_cache_t * glutils_cache_new(size_t cap_bytes)
void glutils_texsz_free_bytes(const char *token, const void *instance, int64_t bytes)
void glutils_texsz_free(const char *token, const void *instance, GLenum format, GLenum type, unsigned w, unsigned h)
void glutils_vp2pvm(GLfloat pvm[16])
void glutils_nl_free(glutils_nl_t *nl)
static void * safe_malloc(size_t size)