2006-04-12 01:59:08 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : ogl.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : OpenGL helper functions.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
// license: GPL; see lib/license.txt
|
2006-04-12 01:59:08 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
#ifndef INCLUDED_OGL
|
|
|
|
#define INCLUDED_OGL
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
#if OS_WIN
|
2006-06-22 20:26:08 +02:00
|
|
|
// wgl.h is a private header and should only be included from here.
|
|
|
|
// if this isn't defined, it'll complain.
|
|
|
|
#define WGL_HEADER_NEEDED
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "lib/sysdep/win/wgl.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
2004-05-06 19:14:30 +02:00
|
|
|
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
//
|
2005-06-17 00:21:12 +02:00
|
|
|
// bring in the platform's OpenGL headers (with fixes, if necessary)
|
2004-06-03 20:38:14 +02:00
|
|
|
//
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-10-12 06:22:44 +02:00
|
|
|
#if OS_MACOSX || OS_MAC
|
2004-05-06 19:14:30 +02:00
|
|
|
# include <OpenGL/gl.h>
|
|
|
|
# include <OpenGL/glu.h>
|
2003-11-03 17:22:45 +01:00
|
|
|
#else
|
2004-05-06 19:14:30 +02:00
|
|
|
# include <GL/gl.h>
|
|
|
|
# include <GL/glu.h>
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// if gl.h provides real prototypes for 1.2 / 1.3 functions,
|
|
|
|
// exclude the corresponding function pointers in glext_funcs.h
|
2003-11-25 03:26:06 +01:00
|
|
|
#ifdef GL_VERSION_1_2
|
|
|
|
#define REAL_GL_1_2
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef GL_VERSION_1_3
|
2005-09-30 00:40:13 +02:00
|
|
|
#define REAL_GL_1_3
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
|
|
|
|
2005-10-12 06:22:44 +02:00
|
|
|
// this must come after GL/gl.h include, so we can't combine the
|
|
|
|
// including GL/glext.h.
|
2003-11-03 17:22:45 +01:00
|
|
|
#undef GL_GLEXT_PROTOTYPES
|
2005-10-12 06:22:44 +02:00
|
|
|
|
|
|
|
#if OS_MACOSX || OS_MAC
|
2004-05-06 19:14:30 +02:00
|
|
|
# include <OpenGL/glext.h>
|
2003-11-03 17:22:45 +01:00
|
|
|
#else
|
2004-05-06 19:14:30 +02:00
|
|
|
# include <GL/glext.h>
|
2005-08-09 18:32:23 +02:00
|
|
|
# if OS_WIN
|
2004-06-09 15:46:39 +02:00
|
|
|
# include <GL/wglext.h>
|
2005-10-12 06:22:44 +02:00
|
|
|
# define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
|
2005-06-17 00:21:12 +02:00
|
|
|
# endif
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
/**
|
|
|
|
* initialization: import extension function pointers and do feature detect.
|
|
|
|
* call before using any other function, and after each video mode change.
|
|
|
|
* fails if OpenGL not ready for use.
|
|
|
|
**/
|
|
|
|
extern void ogl_Init(void);
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-06-17 00:21:12 +02:00
|
|
|
// extensions
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* check if an extension is supported by the OpenGL implementation.
|
|
|
|
*
|
|
|
|
* takes subsequently added core support for some extensions into account
|
|
|
|
* (in case drivers forget to advertise extensions).
|
|
|
|
*
|
|
|
|
* @param ext extension string; exact case.
|
|
|
|
* @return bool.
|
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern bool ogl_HaveExtension(const char* ext);
|
2005-06-17 00:21:12 +02:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* make sure the OpenGL implementation version matches or is newer than
|
|
|
|
* the given version.
|
|
|
|
*
|
|
|
|
* @param version version string; format: ("%d.%d", major, minor).
|
|
|
|
* example: "1.2".
|
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern bool ogl_HaveVersion(const char* version);
|
2005-06-17 00:21:12 +02:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* check if a list of extensions are all supported (as determined by
|
2007-05-02 14:07:08 +02:00
|
|
|
* ogl_HaveExtension).
|
2006-06-25 17:31:58 +02:00
|
|
|
*
|
|
|
|
* @param dummy value ignored; varargs requires a placeholder.
|
|
|
|
* follow it by a list of const char* extension string parameters,
|
|
|
|
* terminated by a 0 pointer.
|
|
|
|
* @return 0 if all are present; otherwise, the first extension in the
|
|
|
|
* list that's not supported (useful for reporting errors).
|
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern const char* ogl_HaveExtensions(int dummy, ...);
|
2005-06-17 00:21:12 +02:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* get a list of all supported extensions.
|
|
|
|
*
|
|
|
|
* useful for crash logs / system information.
|
|
|
|
*
|
|
|
|
* @return read-only C string of unspecified length containing all
|
|
|
|
* advertised extension names, separated by space.
|
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern const char* ogl_ExtensionString(void);
|
2005-06-17 00:21:12 +02:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
// declare extension function pointers
|
2005-08-09 18:32:23 +02:00
|
|
|
#if OS_WIN
|
2004-05-06 19:14:30 +02:00
|
|
|
# define CALL_CONV __stdcall
|
2003-11-03 17:22:45 +01:00
|
|
|
#else
|
2004-05-06 19:14:30 +02:00
|
|
|
# define CALL_CONV
|
2003-11-03 17:22:45 +01:00
|
|
|
#endif
|
2007-05-26 19:10:28 +02:00
|
|
|
#define FUNC(ret, name, params) EXTERN_C ret (CALL_CONV *p##name) params;
|
|
|
|
#define FUNC2(ret, nameARB, nameCore, version, params) EXTERN_C ret (CALL_CONV *p##nameARB) params;
|
2003-11-03 17:22:45 +01:00
|
|
|
#include "glext_funcs.h"
|
2005-06-14 05:33:16 +02:00
|
|
|
#undef FUNC2
|
2003-11-03 17:22:45 +01:00
|
|
|
#undef FUNC
|
|
|
|
// leave CALL_CONV defined for ogl.cpp
|
|
|
|
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// errors
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* raise a warning (break into the debugger) if an OpenGL error is pending.
|
|
|
|
* resets the OpenGL error state afterwards.
|
|
|
|
*
|
|
|
|
* when an error is reported, insert calls to this in a binary-search scheme
|
|
|
|
* to quickly narrow down the actual error location.
|
|
|
|
*
|
|
|
|
* reports a bogus invalid_operation error if called before OpenGL is
|
|
|
|
* initialized, so don't!
|
|
|
|
*
|
|
|
|
* disabled in release mode for efficiency and to avoid annoying errors.
|
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern void ogl_WarnIfError(void);
|
2006-06-25 17:31:58 +02:00
|
|
|
#ifdef NDEBUG
|
2007-05-02 14:07:08 +02:00
|
|
|
# define ogl_WarnIfError()
|
2004-08-06 16:58:58 +02:00
|
|
|
#endif
|
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* ignore and reset the specified OpenGL error.
|
|
|
|
*
|
|
|
|
* this is useful for suppressing annoying error messages, e.g.
|
|
|
|
* "invalid enum" for GL_CLAMP_TO_EDGE even though we've already
|
|
|
|
* warned the user that their OpenGL implementation is too old.
|
|
|
|
*
|
|
|
|
* call after the fact, i.e. the error has been raised. if another or
|
|
|
|
* different error is pending, those are reported immediately.
|
|
|
|
*
|
|
|
|
* @param err_to_ignore: one of the glGetError enums.
|
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern void ogl_SquelchError(GLenum err_to_ignore);
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// implementation limits / feature detect
|
2005-08-09 18:32:23 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
extern GLint ogl_max_tex_size; /// [pixels]
|
|
|
|
extern GLint ogl_max_tex_units; /// limit on GL_TEXTUREn
|
2005-08-09 18:32:23 +02:00
|
|
|
|
2006-06-25 17:31:58 +02:00
|
|
|
/**
|
2007-05-02 14:07:08 +02:00
|
|
|
* set sysdep/gfx.h gfx_card and gfx_drv_ver. called by gfx_detect.
|
|
|
|
*
|
2006-06-25 17:31:58 +02:00
|
|
|
* fails if OpenGL not ready for use.
|
2007-05-02 14:07:08 +02:00
|
|
|
* gfx_card and gfx_drv_ver are unchanged on failure.
|
|
|
|
*
|
|
|
|
* @return LibError
|
2006-06-25 17:31:58 +02:00
|
|
|
**/
|
2007-05-02 14:07:08 +02:00
|
|
|
extern LibError ogl_get_gfx_info(void);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
#endif // #ifndef INCLUDED_OGL
|