2006-04-12 01:59:08 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : ogl.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : OpenGL helper functions.
|
|
|
|
*
|
|
|
|
* @author Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002-2005 Jan Wassenberg
|
|
|
|
*
|
|
|
|
* Redistribution and/or modification are also permitted under the
|
|
|
|
* terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation (version 2 or later, at your option).
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
#ifndef __OGL_H__
|
|
|
|
#define __OGL_H__
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
#if OS_WIN
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "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
|
|
|
|
|
|
|
|
|
2006-03-26 23:58:48 +02:00
|
|
|
// Enums from EXT_framebuffer_object
|
|
|
|
#ifndef GL_FRAMEBUFFER_EXT
|
|
|
|
#define GL_FRAMEBUFFER_EXT 0x8D40
|
|
|
|
#define GL_RENDERBUFFER_EXT 0x8D41
|
|
|
|
#define GL_STENCIL_INDEX1_EXT 0x8D46
|
|
|
|
#define GL_STENCIL_INDEX4_EXT 0x8D47
|
|
|
|
#define GL_STENCIL_INDEX8_EXT 0x8D48
|
|
|
|
#define GL_STENCIL_INDEX16_EXT 0x8D49
|
|
|
|
#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
|
|
|
|
#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
|
|
|
|
#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
|
|
|
|
#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
|
|
|
|
#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
|
|
|
|
#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
|
|
|
|
#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
|
|
|
|
#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
|
|
|
|
#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
|
|
|
|
#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
|
|
|
|
#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
|
|
|
|
#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
|
|
|
|
#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
|
|
|
|
#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
|
|
|
|
#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
|
|
|
|
#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
|
|
|
|
#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
|
|
|
|
#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
|
|
|
|
#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
|
|
|
|
#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
|
|
|
|
#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
|
|
|
|
#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
|
|
|
|
#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
|
|
|
|
#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
|
|
|
|
#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
|
|
|
|
#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
|
|
|
|
#define GL_STENCIL_ATTACHMENT_EXT 0x8D20
|
|
|
|
#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
|
|
|
|
#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
|
|
|
|
#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
|
|
|
|
#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
|
|
|
|
#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
|
|
|
|
#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
|
|
|
|
#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
|
|
|
|
#endif
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
//
|
2005-06-17 00:21:12 +02:00
|
|
|
// extensions
|
2003-11-03 17:22:45 +01:00
|
|
|
//
|
|
|
|
|
2005-06-17 00:21:12 +02:00
|
|
|
// check if the extension <ext> is supported by the OpenGL implementation.
|
|
|
|
// takes subsequently added core support for some extensions into account.
|
|
|
|
extern bool oglHaveExtension(const char* ext);
|
|
|
|
|
|
|
|
// check if the OpenGL implementation is at least at <version>.
|
|
|
|
// (format: "%d.%d" major minor)
|
|
|
|
extern bool oglHaveVersion(const char* version);
|
|
|
|
|
|
|
|
// check if all given extension strings (passed as const char* parameters,
|
|
|
|
// terminated by a 0 pointer) are supported by the OpenGL implementation,
|
|
|
|
// as determined by oglHaveExtension.
|
|
|
|
// returns 0 if all are present; otherwise, the first extension in the
|
|
|
|
// list that's not supported (useful for reporting errors).
|
|
|
|
//
|
|
|
|
// note: dummy parameter is necessary to access parameter va_list.
|
|
|
|
//
|
|
|
|
// rationale: see source.
|
|
|
|
extern const char* oglHaveExtensions(int dummy, ...);
|
|
|
|
|
|
|
|
// return a C string of unspecified length containing a space-separated
|
|
|
|
// list of all extensions the OpenGL implementation advertises.
|
|
|
|
// (useful for crash logs).
|
|
|
|
extern const char* oglExtList(void);
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2005-10-30 02:51:16 +01:00
|
|
|
#define FUNC(ret, name, params) extern ret (CALL_CONV *p##name) params;
|
|
|
|
#define FUNC2(ret, nameARB, nameCore, version, params) extern 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
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2005-10-12 06:22:44 +02:00
|
|
|
// implementation limits / feature detect
|
2003-11-03 17:22:45 +01:00
|
|
|
//
|
|
|
|
|
2005-06-17 00:21:12 +02:00
|
|
|
extern int ogl_max_tex_size; // [pixels]
|
|
|
|
extern int ogl_max_tex_units; // limit on GL_TEXTUREn
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2006-04-10 22:12:25 +02:00
|
|
|
// set sysdep/gfx.h gfx_card and gfx_drv_ver. called by gfx_detect.
|
2006-03-26 23:58:48 +02:00
|
|
|
//
|
2005-06-17 00:21:12 +02:00
|
|
|
// fails if OpenGL not ready for use.
|
|
|
|
// gfx_card and gfx_drv_ver are unchanged on failure.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError ogl_get_gfx_info(void);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
|
2005-06-17 00:21:12 +02:00
|
|
|
//
|
|
|
|
// misc
|
|
|
|
//
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-06-17 00:21:12 +02:00
|
|
|
// in non-release builds, enable oglCheck, which breaks into the debugger
|
|
|
|
// if an OpenGL error was raised since the last call.
|
|
|
|
// add these calls everywhere to close in on the error cause.
|
2005-08-09 18:32:23 +02:00
|
|
|
//
|
|
|
|
// reports a bogus invalid_operation error if called before OpenGL is
|
|
|
|
// initialized, so don't!
|
2005-06-17 00:21:12 +02:00
|
|
|
#ifndef NDEBUG
|
2005-01-23 18:54:20 +01:00
|
|
|
extern void oglCheck(void);
|
2004-08-06 16:58:58 +02:00
|
|
|
#else
|
|
|
|
# define oglCheck()
|
|
|
|
#endif
|
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
// ignore and reset the specified error (as returned by glGetError).
|
|
|
|
// any other errors that have occurred are reported as oglCheck would.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
extern void oglSquelchError(GLenum err_to_ignore);
|
|
|
|
|
|
|
|
|
|
|
|
// call before using any of the above, and after each video mode change.
|
2004-05-26 01:16:21 +02:00
|
|
|
//
|
|
|
|
// fails if OpenGL not ready for use.
|
2005-01-23 18:54:20 +01:00
|
|
|
extern void oglInit(void);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // #ifndef __OGL_H__
|