/*
 * cbgl: the slice of OpenGL 1.x that Chromium B.S.U. draws with, implemented on top of WebGL 1 /
 * OpenGL ES 2 for the fredygames.com build: glBegin/glEnd with colors, normals and two texture
 * units, the three matrix stacks, gluPerspective, display lists, GL_QUADS, sphere-map texture
 * coordinates, the MODULATE/DECAL/REPLACE texture environments and the alpha test. The build
 * force-includes this header in every file of the game (-include cbgl.h), so the game's own calls land
 * here unchanged.
 *
 * Written in 2026 by FredyGames for the fredygames.com build of Chromium B.S.U.; distributed with the
 * game under the Clarified Artistic License (see COPYING).
 */
#ifndef CBGL_H_
#define CBGL_H_

#include <GL/gl.h>
#include <GL/glu.h>

#ifdef __cplusplus
extern "C" {
#endif

void cbgl_Begin(GLenum mode);
void cbgl_End(void);
void cbgl_Vertex3f(GLfloat x, GLfloat y, GLfloat z);
void cbgl_Vertex3fv(const GLfloat *v);
void cbgl_TexCoord2f(GLfloat s, GLfloat t);
void cbgl_MultiTexCoord2f(GLenum unit, GLfloat s, GLfloat t);
void cbgl_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
void cbgl_Color4fv(const GLfloat *c);
void cbgl_Normal3f(GLfloat x, GLfloat y, GLfloat z);
void cbgl_Normal3fv(const GLfloat *n);
void cbgl_PushMatrix(void);
void cbgl_PopMatrix(void);
void cbgl_LoadIdentity(void);
void cbgl_MatrixMode(GLenum mode);
void cbgl_Translatef(GLfloat x, GLfloat y, GLfloat z);
void cbgl_Scalef(GLfloat x, GLfloat y, GLfloat z);
void cbgl_Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
void cbgl_Perspective(GLdouble fovy, GLdouble aspect, GLdouble znear, GLdouble zfar);
GLuint cbgl_GenLists(GLsizei range);
void cbgl_DeleteLists(GLuint list, GLsizei range);
void cbgl_NewList(GLuint list, GLenum mode);
void cbgl_EndList(void);
void cbgl_CallList(GLuint list);
void cbgl_Enable(GLenum cap);
void cbgl_Disable(GLenum cap);
void cbgl_AlphaFunc(GLenum func, GLclampf ref);
void cbgl_TexEnvf(GLenum target, GLenum pname, GLfloat param);
void cbgl_TexGeni(GLenum coord, GLenum pname, GLint param);
void cbgl_ActiveTexture(GLenum unit);
void cbgl_BindTexture(GLenum target, GLuint texture);
void cbgl_DeleteTextures(GLsizei n, const GLuint *textures);
void cbgl_TexParameteri(GLenum target, GLenum pname, GLint param);
void cbgl_TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
                     GLint border, GLenum format, GLenum type, const GLvoid *pixels);
GLint cbgl_Build2DMipmaps(GLenum target, GLint internalformat, GLsizei width, GLsizei height,
                          GLenum format, GLenum type, const void *data);

#ifdef __cplusplus
}
#endif

#ifndef CBGL_IMPLEMENTATION
#define glBegin cbgl_Begin
#define glEnd cbgl_End
#define glVertex3f cbgl_Vertex3f
#define glVertex3fv cbgl_Vertex3fv
#define glVertex2f(x, y) cbgl_Vertex3f((x), (y), 0.0f)
#define glTexCoord2f cbgl_TexCoord2f
#define glMultiTexCoord2fARB cbgl_MultiTexCoord2f
#define glColor4f cbgl_Color4f
#define glColor4fv cbgl_Color4fv
#define glColor3f(r, g, b) cbgl_Color4f((r), (g), (b), 1.0f)
#define glNormal3f cbgl_Normal3f
#define glNormal3fv cbgl_Normal3fv
#define glPushMatrix cbgl_PushMatrix
#define glPopMatrix cbgl_PopMatrix
#define glLoadIdentity cbgl_LoadIdentity
#define glMatrixMode cbgl_MatrixMode
#define glTranslatef cbgl_Translatef
#define glScalef cbgl_Scalef
#define glRotatef cbgl_Rotatef
#define gluPerspective cbgl_Perspective
#define glGenLists cbgl_GenLists
#define glDeleteLists cbgl_DeleteLists
#define glNewList cbgl_NewList
#define glEndList cbgl_EndList
#define glCallList cbgl_CallList
#define glEnable cbgl_Enable
#define glDisable cbgl_Disable
#define glAlphaFunc cbgl_AlphaFunc
#define glTexEnvf cbgl_TexEnvf
#define glTexGeni cbgl_TexGeni
#define glActiveTextureARB cbgl_ActiveTexture
#define glBindTexture cbgl_BindTexture
#define glDeleteTextures cbgl_DeleteTextures
#define glTexParameteri cbgl_TexParameteri
#define glTexImage2D cbgl_TexImage2D
#define gluBuild2DMipmaps cbgl_Build2DMipmaps
/* Desktop-only state with no WebGL equivalent: texture border colors (the game draws with
   GL_CLAMP_TO_EDGE, so the border is never sampled), point and line sizes (the game never draws
   points or lines) and the error strings of the debug output. */
#define glTexParameterfv(target, pname, params) ((void)0)
#define glPointSize(size) ((void)0)
#define glLineWidth(width) ((void)0)
#define gluErrorString(error) ((const GLubyte *)"")
#endif

#endif
