Changeset View
Changeset View
Standalone View
Standalone View
source/lib/ogl.h
Show All 21 Lines | |||||
/* | /* | ||||
* OpenGL helper functions. | * OpenGL helper functions. | ||||
*/ | */ | ||||
#ifndef INCLUDED_OGL | #ifndef INCLUDED_OGL | ||||
#define INCLUDED_OGL | #define INCLUDED_OGL | ||||
#include "lib/external_libraries/opengl.h" | #include "third_party/glad/glad.h" | ||||
/** | /** | ||||
* initialization: import extension function pointers and do feature detect. | * initialization: import extension function pointers and do feature detect. | ||||
* call before using any other function, and after each video mode change. | * call before using any other function, and after each video mode change. | ||||
* fails if OpenGL not ready for use. | * fails if OpenGL not ready for use. | ||||
**/ | **/ | ||||
extern void ogl_Init(); | void ogl_Init(); | ||||
vladislavbelov: Why `extern` was removed? The same for few lines below. | |||||
echotangoechoUnsubmitted Done Inline Actionsbecause extern is unneeded here (note that I see that I forgot a few), see also rP18591 echotangoecho: because `extern` is unneeded here (note that I see that I forgot a few), see also rP18591 | |||||
//----------------------------------------------------------------------------- | |||||
// extensions | |||||
/** | /** | ||||
* check if an extension is supported by the OpenGL implementation. | * Check whether the given OpenGL extension is supported. | ||||
* | * NOTE: this does not check whether the extensions is *loaded*. | ||||
* takes subsequently added core support for some extensions into account | * for that, check whether GLAD_<extension name> is not null. | ||||
* (in case drivers forget to advertise extensions). | */ | ||||
* | |||||
* @param ext extension string; exact case. | |||||
* @return bool. | |||||
**/ | |||||
extern bool ogl_HaveExtension(const char* ext); | extern bool ogl_HaveExtension(const char* ext); | ||||
/** | /** | ||||
Done Inline ActionsWhy not wrap extension (wgl, glx, ...) functions to avoid including their headers? vladislavbelov: Why not wrap extension (wgl, glx, ...) functions to avoid including their headers? | |||||
Done Inline ActionsBecause you need the headers for some of the types. Which is why wgl is such a nightmare. Even copying 500 lines you don't have all the defines. Stan: Because you need the headers for some of the types. Which is why wgl is such a nightmare. Even… | |||||
Done Inline ActionsWhich types do you need from wgl? vladislavbelov: Which types do you need from wgl? | |||||
Done Inline ActionsTechnically we only need one function, so not many. Problem would be if we wanna use more. Else I can just botch the header with that method :) Stan: Technically we only need one function, so not many. Problem would be if we wanna use more. Else… | |||||
Done Inline ActionsSo again, why not wrap that function and move the header include to ogl.cpp? vladislavbelov: So again, why not wrap that function and move the header include to `ogl.cpp`? | |||||
* 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". | |||||
**/ | |||||
extern bool ogl_HaveVersion(const char* version); | |||||
/** | |||||
* check if a list of extensions are all supported (as determined by | * check if a list of extensions are all supported (as determined by | ||||
* ogl_HaveExtension). | * ogl_HaveExtension). | ||||
* | * | ||||
* @param dummy value ignored; varargs requires a placeholder. | * @param dummy value ignored; varargs requires a placeholder. | ||||
* follow it by a list of const char* extension string parameters, | * follow it by a list of const char* extension string parameters, | ||||
* terminated by a 0 pointer. | * terminated by a 0 pointer. | ||||
* @return 0 if all are present; otherwise, the first extension in the | * @return 0 if all are present; otherwise, the first extension in the | ||||
* list that's not supported (useful for reporting errors). | * list that's not supported (useful for reporting errors). | ||||
**/ | **/ | ||||
extern const char* ogl_HaveExtensions(int dummy, ...) SENTINEL_ARG; | const char* ogl_HaveExtensions(int dummy, ...); | ||||
leperUnsubmitted Done Inline ActionsAny specific reason to remove the sentinel annotation? leper: Any specific reason to remove the sentinel annotation? | |||||
/** | |||||
* make sure the OpenGL implementation version matches or is newer than | |||||
* the given version. | |||||
**/ | |||||
inline bool ogl_HaveVersion(int major, int minor) | |||||
{ | |||||
return GLVersion.major >= major && GLVersion.minor >= minor; | |||||
leperUnsubmitted Done Inline ActionsThis is broken. Assume checking agains 2.1 while we have 3.0. leper: This is broken.
Assume checking agains 2.1 while we have 3.0. | |||||
} | |||||
/** | /** | ||||
* get a list of all supported extensions. | * get a list of all supported extensions. | ||||
* | * | ||||
* useful for crash logs / system information. | * useful for crash logs / system information. | ||||
* | * | ||||
* @return read-only C string of unspecified length containing all | * @return read-only C string of unspecified length containing all | ||||
* advertised extension names, separated by space. | * advertised extension names, separated by space. | ||||
**/ | **/ | ||||
extern const char* ogl_ExtensionString(); | const char* ogl_ExtensionString(); | ||||
// The game wants to use some extension constants that aren't provided by | |||||
// glext.h on some old systems. | |||||
// Manually define all the necessary ones that are missing from | |||||
// GL_GLEXT_VERSION 39 (Mesa 7.0) since that's probably an old enough baseline: | |||||
#ifndef GL_VERSION_3_0 | |||||
# define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 | |||||
# define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 | |||||
#endif | |||||
#ifndef GL_EXT_transform_feedback | |||||
# define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A | |||||
# define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B | |||||
# define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80 | |||||
#endif | |||||
#ifndef GL_ARB_geometry_shader4 | |||||
# define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29 | |||||
# define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD | |||||
# define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE | |||||
# define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF | |||||
# define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0 | |||||
# define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1 | |||||
#endif | |||||
#ifndef GL_ARB_timer_query | |||||
# define GL_TIME_ELAPSED 0x88BF | |||||
# define GL_TIMESTAMP 0x8E28 | |||||
#endif | |||||
#ifndef GL_ARB_framebuffer_object | |||||
# define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 | |||||
#endif | |||||
// Also need some more for OS X 10.5: | |||||
#ifndef GL_EXT_texture_array | |||||
# define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF | |||||
#endif | |||||
// Also need some types not in old glext.h: | |||||
#ifndef GL_ARB_sync | |||||
typedef int64_t GLint64; | |||||
typedef uint64_t GLuint64; | |||||
#endif | |||||
// declare extension function pointers | |||||
#if OS_WIN | |||||
# define GL_CALL_CONV __stdcall | |||||
#else | |||||
# define GL_CALL_CONV | |||||
#endif | |||||
#define FUNC(ret, name, params) EXTERN_C ret (GL_CALL_CONV *p##name) params; | |||||
#define FUNC2(ret, nameARB, nameCore, version, params) EXTERN_C ret (GL_CALL_CONV *p##nameARB) params; | |||||
#define FUNC3(ret, nameARB, nameCore, version, params) EXTERN_C ret (GL_CALL_CONV *p##nameCore) params; | |||||
#include "lib/external_libraries/glext_funcs.h" | |||||
#undef FUNC3 | |||||
#undef FUNC2 | |||||
#undef FUNC | |||||
// leave GL_CALL_CONV defined for ogl.cpp | |||||
//----------------------------------------------------------------------------- | |||||
// errors | |||||
/** | /** | ||||
* raise a warning (break into the debugger) if an OpenGL error is pending. | * raise a warning (break into the debugger) if an OpenGL error is pending. | ||||
* resets the OpenGL error state afterwards. | * resets the OpenGL error state afterwards. | ||||
* | * | ||||
* when an error is reported, insert calls to this in a binary-search scheme | * when an error is reported, insert calls to this in a binary-search scheme | ||||
* to quickly narrow down the actual error location. | * to quickly narrow down the actual error location. | ||||
* | * | ||||
* reports a bogus invalid_operation error if called before OpenGL is | * reports a bogus invalid_operation error if called before OpenGL is | ||||
* initialized, so don't! | * initialized, so don't! | ||||
* | * | ||||
* disabled in release mode for efficiency and to avoid annoying errors. | * disabled in release mode for efficiency and to avoid annoying errors. | ||||
**/ | **/ | ||||
extern void ogl_WarnIfErrorLoc(const char *file, int line); | void ogl_WarnIfErrorLoc(const char *file, int line); | ||||
#ifdef NDEBUG | #ifdef NDEBUG | ||||
# define ogl_WarnIfError() | # define ogl_WarnIfError() | ||||
#else | #else | ||||
# define ogl_WarnIfError() ogl_WarnIfErrorLoc(__FILE__, __LINE__) | # define ogl_WarnIfError() ogl_WarnIfErrorLoc(__FILE__, __LINE__) | ||||
#endif | #endif | ||||
/** | /** | ||||
* get a name of the error. | * get a name of the error. | ||||
* | * | ||||
* useful for debug. | * useful for debug. | ||||
* | * | ||||
* @return read-only C string of unspecified length containing | * @return read-only C string of unspecified length containing | ||||
* the error's name. | * the error's name. | ||||
**/ | **/ | ||||
extern const char* ogl_GetErrorName(GLenum err); | const char* ogl_GetErrorName(GLenum err); | ||||
/** | /** | ||||
* ignore and reset the specified OpenGL error. | * ignore and reset the specified OpenGL error. | ||||
* | * | ||||
* this is useful for suppressing annoying error messages, e.g. | * this is useful for suppressing annoying error messages, e.g. | ||||
* "invalid enum" for GL_CLAMP_TO_EDGE even though we've already | * "invalid enum" for GL_CLAMP_TO_EDGE even though we've already | ||||
* warned the user that their OpenGL implementation is too old. | * warned the user that their OpenGL implementation is too old. | ||||
* | * | ||||
* call after the fact, i.e. the error has been raised. if another or | * call after the fact, i.e. the error has been raised. if another or | ||||
* different error is pending, those are reported immediately. | * different error is pending, those are reported immediately. | ||||
* | * | ||||
* @param err_to_ignore: one of the glGetError enums. | * @param err_to_ignore: one of the glGetError enums. | ||||
* @return true if the requested error was seen and ignored | * @return true if the requested error was seen and ignored | ||||
**/ | **/ | ||||
extern bool ogl_SquelchError(GLenum err_to_ignore); | bool ogl_SquelchError(GLenum err_to_ignore); | ||||
//----------------------------------------------------------------------------- | |||||
// implementation limits / feature detect | |||||
extern GLint ogl_max_tex_size; /// [pixels] | extern GLint ogl_max_tex_size; /// [pixels] | ||||
extern GLint ogl_max_tex_units; /// limit on GL_TEXTUREn | extern GLint ogl_max_tex_units; /// limit on GL_TEXTUREn | ||||
#endif // #ifndef INCLUDED_OGL | #endif // #ifndef INCLUDED_OGL |
Wildfire Games · Phabricator
Why extern was removed? The same for few lines below.