Experiment a little with OpenGL ES
This was SVN commit r10915.
This commit is contained in:
parent
c8bf34948c
commit
e64a3d3946
@ -1,6 +1,7 @@
|
||||
newoption { trigger = "atlas", description = "Include Atlas scenario editor projects" }
|
||||
newoption { trigger = "collada", description = "Include COLLADA projects (requires FCollada library)" }
|
||||
newoption { trigger = "coverage", description = "Enable code coverage data collection (GCC only)" }
|
||||
newoption { trigger = "gles", description = "Use non-working OpenGL ES 2.0 mode" }
|
||||
newoption { trigger = "icc", description = "Use Intel C++ Compiler (Linux only; should use either \"--cc icc\" or --without-pch too, and then set CXX=icpc before calling make)" }
|
||||
newoption { trigger = "outpath", description = "Location for generated project files" }
|
||||
newoption { trigger = "without-tests", description = "Disable generation of test projects" }
|
||||
@ -141,6 +142,10 @@ function project_set_build_flags()
|
||||
|
||||
configuration { }
|
||||
|
||||
if _OPTIONS["gles"] then
|
||||
defines { "CONFIG2_GLES=1" }
|
||||
end
|
||||
|
||||
-- required for the lowlevel library. must be set from all projects that use it, otherwise it assumes it is
|
||||
-- being used as a DLL (which is currently not the case in 0ad)
|
||||
defines { "LIB_STATIC_LINK" }
|
||||
|
@ -103,7 +103,7 @@ void CTerritoryTexture::ConstructTexture(int unit)
|
||||
// overwrite with glTexSubImage2D later
|
||||
u8* texData = new u8[m_TextureSize * m_TextureSize * 4];
|
||||
memset(texData, 0x00, m_TextureSize * m_TextureSize * 4);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_TextureSize, m_TextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, texData);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, texData);
|
||||
delete[] texData;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
@ -93,4 +93,11 @@
|
||||
# define CONFIG2_MAHAF_ATTEMPT_DRIVER_START 0
|
||||
#endif
|
||||
|
||||
// build in OpenGL ES 2.0 mode, instead of the default mode designed for
|
||||
// GL 1.1 + extensions.
|
||||
// this disables various features that are not supported by GLES.
|
||||
#ifndef CONFIG2_GLES
|
||||
# define CONFIG2_GLES 0
|
||||
#endif
|
||||
|
||||
#endif // #ifndef INCLUDED_CONFIG2
|
||||
|
@ -24,11 +24,16 @@
|
||||
* OpenGL extension function declarations (X macros).
|
||||
*/
|
||||
|
||||
#if OS_MACOSX
|
||||
#include <OpenGL/glext.h>
|
||||
#include "lib/config2.h" // CONFIG2_GLES
|
||||
|
||||
#if CONFIG2_GLES
|
||||
# include <GLES2/gl2ext.h>
|
||||
#elif OS_MACOSX
|
||||
# include <OpenGL/glext.h>
|
||||
#else
|
||||
#include <GL/glext.h>
|
||||
# include <GL/glext.h>
|
||||
#endif
|
||||
|
||||
#if OS_WIN
|
||||
# include <GL/wglext.h>
|
||||
#endif
|
||||
@ -58,6 +63,17 @@ actually supported).
|
||||
|
||||
*/
|
||||
|
||||
#if CONFIG2_GLES
|
||||
|
||||
// no GLES extensions used yet
|
||||
|
||||
// some functions that are extensions in GL are core functions in GLES,
|
||||
// so we should use them without the function pointer indirection
|
||||
#define pglCompressedTexImage2DARB glCompressedTexImage2D
|
||||
#define pglActiveTextureARB glActiveTexture
|
||||
|
||||
#else
|
||||
|
||||
// were these defined as real functions in gl.h already?
|
||||
|
||||
// GL_EXT_draw_range_elements / GL1.2:
|
||||
@ -272,6 +288,8 @@ FUNC(void, glEndPerfQueryINTEL, (GLuint id))
|
||||
FUNC(void, glDeletePerfQueryINTEL, (GLuint id))
|
||||
FUNC(void, glGetPerfQueryDataINTEL, (GLuint id, GLenum requestType, GLuint maxLength, char *buffer, GLuint *length))
|
||||
|
||||
#endif // #if CONFIG_GLES2
|
||||
|
||||
|
||||
#if OS_WIN
|
||||
// WGL_EXT_swap_control
|
||||
|
@ -27,6 +27,8 @@
|
||||
#ifndef INCLUDED_OPENGL
|
||||
#define INCLUDED_OPENGL
|
||||
|
||||
#include "lib/config2.h" // CONFIG2_GLES
|
||||
|
||||
#if OS_WIN
|
||||
// wgl.h is a private header and should only be included from here.
|
||||
// if this isn't defined, it'll complain.
|
||||
@ -34,7 +36,9 @@
|
||||
#include "lib/sysdep/os/win/wgl.h"
|
||||
#endif
|
||||
|
||||
#if OS_MACOSX || OS_MAC
|
||||
#if CONFIG2_GLES
|
||||
# include <GLES2/gl2.h>
|
||||
#elif OS_MACOSX || OS_MAC
|
||||
# include <OpenGL/gl.h>
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
@ -53,7 +57,9 @@
|
||||
// including GL/glext.h.
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
#if OS_MACOSX || OS_MAC
|
||||
#if CONFIG2_GLES
|
||||
# include <GLES2/gl2ext.h>
|
||||
#elif OS_MACOSX || OS_MAC
|
||||
# include <OpenGL/glext.h>
|
||||
#else
|
||||
# include <GL/glext.h>
|
||||
|
@ -286,6 +286,14 @@ const char* ogl_HaveExtensions(int dummy, ...)
|
||||
// some extension functions which our graphics code assumes exist.
|
||||
// it will render incorrectly but at least it shouldn't crash.
|
||||
|
||||
#if CONFIG2_GLES
|
||||
|
||||
static void enableDummyFunctions()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void GL_CALL_CONV dummy_glDrawRangeElementsEXT(GLenum mode, GLuint, GLuint, GLsizei count, GLenum type, GLvoid* indices)
|
||||
{
|
||||
glDrawElements(mode, count, type, indices);
|
||||
@ -309,6 +317,26 @@ static void GL_CALL_CONV dummy_glMultiTexCoord3fARB(int, float s, float t, float
|
||||
glTexCoord3f(s, t, r);
|
||||
}
|
||||
|
||||
static void enableDummyFunctions()
|
||||
{
|
||||
// fall back to the dummy functions when extensions (or equivalent core support) are missing
|
||||
|
||||
if(!ogl_HaveExtension("GL_EXT_draw_range_elements"))
|
||||
{
|
||||
pglDrawRangeElementsEXT = &dummy_glDrawRangeElementsEXT;
|
||||
}
|
||||
|
||||
if(!ogl_HaveExtension("GL_ARB_multitexture"))
|
||||
{
|
||||
pglActiveTextureARB = &dummy_glActiveTextureARB;
|
||||
pglClientActiveTextureARB = &dummy_glClientActiveTextureARB;
|
||||
pglMultiTexCoord2fARB = &dummy_glMultiTexCoord2fARB;
|
||||
pglMultiTexCoord3fARB = &dummy_glMultiTexCoord3fARB;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if CONFIG2_GLES
|
||||
|
||||
static void importExtensionFunctions()
|
||||
{
|
||||
// It should be safe to load the ARB function pointers even if the
|
||||
@ -331,20 +359,7 @@ static void importExtensionFunctions()
|
||||
#undef FUNC23
|
||||
#undef FUNC
|
||||
|
||||
// fall back to the dummy functions when extensions (or equivalent core support) are missing
|
||||
|
||||
if(!ogl_HaveExtension("GL_EXT_draw_range_elements"))
|
||||
{
|
||||
pglDrawRangeElementsEXT = &dummy_glDrawRangeElementsEXT;
|
||||
}
|
||||
|
||||
if(!ogl_HaveExtension("GL_ARB_multitexture"))
|
||||
{
|
||||
pglActiveTextureARB = &dummy_glActiveTextureARB;
|
||||
pglClientActiveTextureARB = &dummy_glClientActiveTextureARB;
|
||||
pglMultiTexCoord2fARB = &dummy_glMultiTexCoord2fARB;
|
||||
pglMultiTexCoord3fARB = &dummy_glMultiTexCoord3fARB;
|
||||
}
|
||||
enableDummyFunctions();
|
||||
}
|
||||
|
||||
|
||||
@ -359,10 +374,12 @@ static void dump_gl_error(GLenum err)
|
||||
E(GL_INVALID_ENUM)
|
||||
E(GL_INVALID_VALUE)
|
||||
E(GL_INVALID_OPERATION)
|
||||
#if !CONFIG2_GLES
|
||||
E(GL_STACK_OVERFLOW)
|
||||
E(GL_STACK_UNDERFLOW)
|
||||
#endif
|
||||
E(GL_OUT_OF_MEMORY)
|
||||
E(GL_INVALID_FRAMEBUFFER_OPERATION_EXT)
|
||||
E(GL_INVALID_FRAMEBUFFER_OPERATION)
|
||||
default: debug_printf(L"Unknown GL error: %04x\n", err); break;
|
||||
}
|
||||
#undef E
|
||||
@ -463,5 +480,7 @@ void ogl_Init()
|
||||
importExtensionFunctions();
|
||||
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &ogl_max_tex_size);
|
||||
#if !CONFIG2_GLES
|
||||
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ogl_max_tex_units);
|
||||
#endif
|
||||
}
|
||||
|
@ -112,6 +112,10 @@ public:
|
||||
|
||||
void draw(int x, int y) const
|
||||
{
|
||||
#if CONFIG2_GLES
|
||||
UNUSED2(x); UNUSED2(y);
|
||||
#warning TODO: implement cursors for GLES
|
||||
#else
|
||||
(void)ogl_tex_bind(ht);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@ -125,6 +129,7 @@ public:
|
||||
glTexCoord2i(1, 1); glVertex2i( x-hotspotx+w, y+hotspoty-h );
|
||||
glTexCoord2i(0, 1); glVertex2i( x-hotspotx, y+hotspoty-h );
|
||||
glEnd();
|
||||
#endif
|
||||
}
|
||||
|
||||
Status validate() const
|
||||
@ -239,7 +244,7 @@ static Status Cursor_validate(const Cursor* c)
|
||||
WARN_RETURN(ERR::_2);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
|
@ -65,9 +65,11 @@ static bool wrap_valid(GLint wrap)
|
||||
{
|
||||
switch(wrap)
|
||||
{
|
||||
#if !CONFIG2_GLES
|
||||
case GL_CLAMP:
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
case GL_CLAMP_TO_BORDER:
|
||||
#endif
|
||||
case GL_CLAMP_TO_EDGE:
|
||||
case GL_REPEAT:
|
||||
case GL_MIRRORED_REPEAT:
|
||||
return true;
|
||||
@ -103,8 +105,10 @@ static bool fmt_is_s3tc(GLenum fmt)
|
||||
{
|
||||
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
||||
#if !CONFIG2_GLES
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
||||
#endif
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@ -129,10 +133,12 @@ static GLint choose_fmt(size_t bpp, size_t flags)
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
case 1:
|
||||
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
#if !CONFIG2_GLES
|
||||
case 3:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
case 5:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
#endif
|
||||
default:
|
||||
DEBUG_WARN_ERR(ERR::LOGIC); // invalid DXT value
|
||||
return 0;
|
||||
@ -149,10 +155,18 @@ static GLint choose_fmt(size_t bpp, size_t flags)
|
||||
return GL_LUMINANCE_ALPHA;
|
||||
case 24:
|
||||
ENSURE(!alpha);
|
||||
#if CONFIG2_GLES
|
||||
// GLES never supports BGR
|
||||
ENSURE(!bgr);
|
||||
return GL_RGB;
|
||||
#else
|
||||
return bgr? GL_BGR : GL_RGB;
|
||||
#endif
|
||||
case 32:
|
||||
ENSURE(alpha);
|
||||
return bgr? GL_BGRA : GL_RGBA;
|
||||
// GLES can support BGRA via GL_EXT_texture_format_BGRA8888
|
||||
// (TODO: can we rely on support for that extension?)
|
||||
return bgr? GL_BGRA_EXT : GL_RGBA;
|
||||
default:
|
||||
DEBUG_WARN_ERR(ERR::LOGIC); // invalid bpp
|
||||
return 0;
|
||||
@ -218,6 +232,15 @@ static GLint choose_int_fmt(GLenum fmt, int q_flags)
|
||||
if(fmt_is_s3tc(fmt))
|
||||
return fmt;
|
||||
|
||||
#if CONFIG2_GLES
|
||||
|
||||
UNUSED2(half_bpp);
|
||||
|
||||
// GLES only supports internal format == external format
|
||||
return fmt;
|
||||
|
||||
#else
|
||||
|
||||
switch(fmt)
|
||||
{
|
||||
// 8bpp
|
||||
@ -254,6 +277,8 @@ static GLint choose_int_fmt(GLenum fmt, int q_flags)
|
||||
}
|
||||
|
||||
UNREACHABLE;
|
||||
|
||||
#endif // #if CONFIG2_GLES
|
||||
}
|
||||
|
||||
|
||||
@ -316,8 +341,10 @@ static void state_latch(OglTexState* ots)
|
||||
// .. only CLAMP and REPEAT are guaranteed to be available.
|
||||
// if we're using one of the others, we squelch the error that
|
||||
// may have resulted if this GL implementation is old.
|
||||
#if !CONFIG2_GLES
|
||||
if((wrap_s != GL_CLAMP && wrap_s != GL_REPEAT) || (wrap_t != GL_CLAMP && wrap_t != GL_REPEAT))
|
||||
ogl_SquelchError(GL_INVALID_ENUM);
|
||||
#endif
|
||||
|
||||
// anisotropy
|
||||
const GLfloat anisotropy = ots->anisotropy;
|
||||
@ -777,6 +804,7 @@ static Status get_mipmaps(Tex* t, GLint filter, int q_flags, int* plevels_to_ski
|
||||
*plevels_to_skip = 0; // t contains mipmaps
|
||||
// OpenGL supports automatic generation; we need only
|
||||
// activate that and upload the base image.
|
||||
#if !CONFIG2_GLES
|
||||
else if(have_auto_mipmap_gen)
|
||||
{
|
||||
// note: we assume GL_GENERATE_MIPMAP and GL_GENERATE_MIPMAP_SGIS
|
||||
@ -784,6 +812,7 @@ static Status get_mipmaps(Tex* t, GLint filter, int q_flags, int* plevels_to_ski
|
||||
// governing 'promoted' ARB extensions and just plain makes sense.
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||
}
|
||||
#endif
|
||||
// image is S3TC-compressed and the previous 2 alternatives weren't
|
||||
// available; we're going to cheat and just disable mipmapping.
|
||||
// rationale: having tex_transform add mipmaps would be slow (since
|
||||
|
@ -320,6 +320,9 @@ void glvwprintf(const wchar_t* fmt, va_list args)
|
||||
|
||||
ogl_WarnIfError();
|
||||
|
||||
#if CONFIG2_GLES
|
||||
#warning TODO: implement unifont for GLES
|
||||
#else
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
@ -335,6 +338,7 @@ void glvwprintf(const wchar_t* fmt, va_list args)
|
||||
|
||||
// Move into position for subsequent prints
|
||||
glTranslatef((float)x, 0, 0);
|
||||
#endif
|
||||
|
||||
delete[] vertexes;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user