Attempt at fixing Windows build. Also started on GL_EXT_rectangle_texture support (mostly for HUDs and maybe mission screeen images).
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@939 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
d5f8ae15de
commit
dcee0200b2
@ -57,7 +57,7 @@ MA 02110-1301, USA.
|
||||
}
|
||||
else
|
||||
{
|
||||
texture = [OOTexture textureWithName:name options:kOOTextureDefaultOptions anisotropy:kOOTextureDefaultAnisotropy];
|
||||
texture = [OOTexture textureWithName:name options:kOOTextureDefaultOptions anisotropy:kOOTextureDefaultAnisotropy lodBias:kOOTextureDefaultLODBias];
|
||||
}
|
||||
[texture retain];
|
||||
}
|
||||
|
@ -43,14 +43,25 @@ enum
|
||||
|
||||
kOOTextureNoShrink = 0x0100UL,
|
||||
kOOTextureRepeatS = 0x0200UL,
|
||||
kOOTextureRepeatT = 0x0200UL,
|
||||
kOOTextureRepeatT = 0x0400UL,
|
||||
kOOTextureAllowRectTexture = 0x0800UL, // Indicates that GL_TEXTURE_RECTANGLE_EXT may be used instead of GL_TEXTURE_2D. See -texCoordsScale for a discussion of rectangle textures.
|
||||
|
||||
kOOTextureMinFilterMask = 0x000FUL,
|
||||
kOOTextureMagFilterMask = 0x00F0UL,
|
||||
kOOTextureFlagsMask = ~(kOOTextureMinFilterMask | kOOTextureMagFilterMask),
|
||||
|
||||
kOOTextureDefaultOptions = kOOTextureMinFilterDefault | kOOTextureMagFilterLinear,
|
||||
kOOTextureDefinedFlags = 0x0733UL
|
||||
|
||||
kOOTextureDefinedFlags = kOOTextureMinFilterMask | kOOTextureMagFilterMask
|
||||
| kOOTextureNoShrink
|
||||
#if GL_EXT_texture_rectangle
|
||||
| kOOTextureAllowRectTexture
|
||||
#endif
|
||||
| kOOTextureRepeatS
|
||||
| kOOTextureRepeatT,
|
||||
|
||||
kOOTextureFlagsAllowedForRectangleTexture =
|
||||
kOOTextureDefinedFlags & ~(kOOTextureRepeatS | kOOTextureRepeatT)
|
||||
};
|
||||
|
||||
|
||||
@ -78,6 +89,9 @@ enum
|
||||
GLuint textureName;
|
||||
uint32_t width,
|
||||
height;
|
||||
#if GL_EXT_texture_rectangle
|
||||
BOOL isRectTexture;
|
||||
#endif
|
||||
} loaded;
|
||||
} data;
|
||||
#if GL_EXT_texture_lod_bias
|
||||
@ -122,6 +136,7 @@ enum
|
||||
+ (id)textureWithConfiguration:(id)configuration;
|
||||
|
||||
/* Bind the texture to the current texture unit.
|
||||
This will block until loading is completed.
|
||||
*/
|
||||
- (void)apply;
|
||||
|
||||
@ -130,4 +145,36 @@ enum
|
||||
*/
|
||||
- (void)ensureFinishedLoading;
|
||||
|
||||
/* Dimensions in pixels.
|
||||
This will block until loading is completed.
|
||||
*/
|
||||
- (NSSize)dimensions;
|
||||
|
||||
|
||||
/* Dimensions in texture coordinates.
|
||||
|
||||
If kOOTextureAllowRectTexture is set, and GL_EXT_texture_rectangle is
|
||||
available, textures whose dimensions are not powers of two will be loaded
|
||||
as rectangle textures. Rectangle textures use unnormalized co-ordinates;
|
||||
that is, co-oridinates range from 0 to the actual size of the texture
|
||||
rather than 0 to 1. Thus, for rectangle textures, -texCoordsScale returns
|
||||
-dimensions (with the required wait for loading) for a rectangle texture.
|
||||
For non-rectangle textures, (1, 1) is returned without delay. If the
|
||||
texture has power-of-two dimensions, it will be loaded as a normal
|
||||
texture.
|
||||
|
||||
Rectangle textures have additional limitations: kOOTextureMinFilterMipMap
|
||||
is not supported (kOOTextureMinFilterLinear will be used instead), and
|
||||
kOOTextureRepeatS/kOOTextureRepeatT will be ignored.
|
||||
|
||||
Note that 'rectangle texture' is a misnomer; non-rectangle textures may
|
||||
be rectangular, as long as their sides are powers of two. Non-power-of-two
|
||||
textures would be more descriptive, but this phrase is used for the
|
||||
extension that allows 'normal' textures to have non-power-of-two sides
|
||||
without additional restrictions. It is intended that OOTexture should
|
||||
support this in future, but this shouldn’t affect the interface, only
|
||||
avoid the scaling-to-power-of-two stage.
|
||||
*/
|
||||
- (NSSize)texCoordsScale;
|
||||
|
||||
@end
|
||||
|
@ -29,6 +29,7 @@ MA 02110-1301, USA.
|
||||
#import "ResourceManager.h"
|
||||
#import "OOOpenGLExtensionManager.h"
|
||||
#import "OOMacroOpenGL.h"
|
||||
#import "OOCPUInfo.h"
|
||||
#import "OOCache.h"
|
||||
|
||||
|
||||
@ -60,10 +61,12 @@ static OOCache *sRecentTextures = nil;
|
||||
static BOOL sCheckedExtensions = NO;
|
||||
|
||||
|
||||
#if __BIG_ENDIAN__
|
||||
#if OOLITE_BIG_ENDIAN
|
||||
#define RGBA_IMAGE_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
|
||||
#else
|
||||
#elif OOLITE_LITTLE_ENDIAN
|
||||
#define RGBA_IMAGE_TYPE GL_UNSIGNED_INT_8_8_8_8
|
||||
#else
|
||||
#error Neither OOLITE_BIG_ENDIAN nor OOLITE_LITTLE_ENDIAN is defined as nonzero!
|
||||
#endif
|
||||
|
||||
|
||||
@ -72,7 +75,7 @@ static BOOL sCheckedExtensions = NO;
|
||||
static BOOL sAnisotropyAvailable;
|
||||
static float sAnisotropyScale; // Scale of anisotropy values
|
||||
#else
|
||||
#warning GL_EXT_texture_filter_anisotropic unavialble -- are you using an up-to-date glext.h?
|
||||
#warning GL_EXT_texture_filter_anisotropic unavailble -- are you using an up-to-date glext.h?
|
||||
#endif
|
||||
|
||||
|
||||
@ -116,6 +119,11 @@ static BOOL sTextureLODBiasAvailable;
|
||||
#endif
|
||||
|
||||
|
||||
#if GL_EXT_texture_rectangle
|
||||
static BOOL sRectangleTextureAvailable;
|
||||
#endif
|
||||
|
||||
|
||||
@interface OOTexture (OOPrivate)
|
||||
|
||||
- (id)initWithPath:(NSString *)path key:(NSString *)key options:(uint32_t)options anisotropy:(float)anisotropy lodBias:(GLfloat)lodBias;
|
||||
@ -139,8 +147,8 @@ static BOOL sTextureLODBiasAvailable;
|
||||
NSString *path = nil;
|
||||
|
||||
if (EXPECT_NOT(name == nil)) return nil;
|
||||
if (EXPECT_NOT(!sCheckedExtensions)) [self checkExtensions];
|
||||
|
||||
options &= kOOTextureDefinedFlags;
|
||||
// Set default flags if needed
|
||||
if ((options & kOOTextureMinFilterMask) == kOOTextureMinFilterDefault)
|
||||
{
|
||||
@ -158,6 +166,25 @@ static BOOL sTextureLODBiasAvailable;
|
||||
options = (options & ~kOOTextureMagFilterMask) | kOOTextureMagFilterLinear;
|
||||
}
|
||||
|
||||
if (options & kOOTextureAllowRectTexture)
|
||||
{
|
||||
// Apply rectangle texture restrictions (regardless of whether rectangle textures are available, for consistency)
|
||||
options &= kOOTextureFlagsAllowedForRectangleTexture;
|
||||
if ((options & kOOTextureMinFilterMask) == kOOTextureMinFilterMipMap)
|
||||
{
|
||||
options = (kOOTextureMinFilterMask & ~kOOTextureMinFilterMask) | kOOTextureMinFilterLinear;
|
||||
}
|
||||
|
||||
#if GL_EXT_texture_rectangle
|
||||
if (!sRectangleTextureAvailable)
|
||||
{
|
||||
options &= ~kOOTextureAllowRectTexture;
|
||||
}
|
||||
#endif // Else, options &= kOOTextureDefinedFlags below will clear the flag
|
||||
}
|
||||
|
||||
options &= kOOTextureDefinedFlags;
|
||||
|
||||
// Look for existing texture
|
||||
key = [NSString stringWithFormat:@"%@:0x%.4X", name, options];
|
||||
result = [[sInUseTextures objectForKey:key] pointerValue];
|
||||
@ -169,9 +196,7 @@ static BOOL sTextureLODBiasAvailable;
|
||||
OOLog(kOOLogFileNotFound, @"Could not find texture file \"%@\".", name);
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (!sCheckedExtensions) [self checkExtensions];
|
||||
|
||||
|
||||
// No existing texture, load texture...
|
||||
result = [[[OOTexture alloc] initWithPath:path key:key options:options anisotropy:anisotropy lodBias:lodBias] autorelease];
|
||||
|
||||
@ -314,6 +339,48 @@ static BOOL sTextureLODBiasAvailable;
|
||||
if (EXPECT_NOT(!loaded)) [self setUpTexture];
|
||||
}
|
||||
|
||||
|
||||
- (NSSize)dimensions
|
||||
{
|
||||
[self ensureFinishedLoading];
|
||||
|
||||
return NSMakeSize(data.loaded.width, data.loaded.height);
|
||||
}
|
||||
|
||||
|
||||
- (NSSize)texCoordsScale
|
||||
{
|
||||
#if GL_EXT_texture_rectangle
|
||||
if (loaded)
|
||||
{
|
||||
if (!data.loaded.isRectTexture)
|
||||
{
|
||||
return NSMakeSize(1.0f, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSMakeSize(data.loaded.width, data.loaded.height);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not loaded
|
||||
if (!data.loading.options & kOOTextureAllowRectTexture)
|
||||
{
|
||||
return NSMakeSize(1.0f, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Finishing may clear the rectangle texture flag (if the texture turns out to be POT)
|
||||
[self ensureFinishedLoading];
|
||||
return [self texCoordsScale];
|
||||
}
|
||||
}
|
||||
#else
|
||||
return NSMakeSize(1.0f, 1.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -374,9 +441,9 @@ static BOOL sTextureLODBiasAvailable;
|
||||
loaded = YES;
|
||||
// data.loaded considered invalid beyond this point.
|
||||
|
||||
// This will block until loading is completed, if necessary.
|
||||
if ([loader getResult:&data.loaded.bytes format:&format width:&data.loaded.width height:&data.loaded.height])
|
||||
{
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // FIXME: this is probably not needed. Remove it once stuff works and see if anything changes. (Should probably be 4 if we need to keep it.)
|
||||
glGenTextures(1, &data.loaded.textureName);
|
||||
glBindTexture(GL_TEXTURE_2D, data.loaded.textureName);
|
||||
|
||||
@ -488,7 +555,7 @@ static BOOL sTextureLODBiasAvailable;
|
||||
#endif
|
||||
|
||||
#ifdef GL_CLAMP_TO_EDGE
|
||||
// GL_CLAMP_TO_EDGE requires OpenGL 1.2 or later
|
||||
// GL_CLAMP_TO_EDGE requires OpenGL 1.2 or later. Oolite probably does too...
|
||||
sClampToEdgeAvailable = (2 < [extMgr minorVersionNumber]) || [extMgr haveExtension:@"GL_SGIS_texture_edge_clamp"];
|
||||
#endif
|
||||
|
||||
@ -499,6 +566,10 @@ static BOOL sTextureLODBiasAvailable;
|
||||
#if GL_EXT_texture_lod_bias
|
||||
sTextureLODBiasAvailable = [extMgr haveExtension:@"GL_EXT_texture_lod_bias"];
|
||||
#endif
|
||||
|
||||
#if GL_EXT_texture_rectangle
|
||||
sRectangleTextureAvailable = [extMgr haveExtension:@"GL_EXT_texture_rectangle"];
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -45,4 +45,7 @@ MA 02110-1301, USA.
|
||||
#define OO_ENTER_OPENGL() CGLContextObj CGL_MACRO_CONTEXT = CGLGetCurrentContext(); \
|
||||
|
||||
#endif
|
||||
#else
|
||||
// Not OS X
|
||||
#define OO_ENTER_OPENGL() do {} while (0)
|
||||
#endif
|
||||
|
@ -30,6 +30,7 @@ MA 02110-1301, USA.
|
||||
|
||||
#import "OOCocoa.h"
|
||||
#import "OOOpenGL.h"
|
||||
#import "OOFunctionAttributes.h"
|
||||
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
@ -96,33 +97,41 @@ MA 02110-1301, USA.
|
||||
@end
|
||||
|
||||
|
||||
#if OOLITE_WINDOWS && !defined(NO_SHADERS)
|
||||
#if OOLITE_WINDOWS
|
||||
/* Define the function pointers for the OpenGL extensions used in the game
|
||||
(required for Windows only).
|
||||
*/
|
||||
void OOBadOpenGLExtensionUsed(void) GCC_ATTR((noreturn));
|
||||
|
||||
#if GL_ARB_vertex_buffer_object
|
||||
// Vertex Buffer Object functions
|
||||
PFNGLBINDBUFFERARBPRO glBindBufferARB;
|
||||
PFNGLGENBUFFERSARBPROC glGenBuffersARB;
|
||||
PFNGLBUFFERDATAARBPROC glBufferDataARB;
|
||||
PFNGLBINDBUFFERARBPROC glBindBufferARB = (PFNGLBINDBUFFERARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLGENBUFFERSARBPROC glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLBUFFERDATAARBPROC glBufferDataARB = (PFNGLBUFFERDATAARBPROC)OOBadOpenGLExtensionUsed;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHADERS
|
||||
// Shader functions
|
||||
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
|
||||
PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
|
||||
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
|
||||
PFNGLUNIFORM1IARBPROC glUniform1iARB;
|
||||
PFNGLUNIFORM1FARBPROC glUniform1fARB;
|
||||
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
|
||||
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
|
||||
PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
|
||||
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
|
||||
PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
|
||||
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
|
||||
PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
|
||||
PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
|
||||
PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
|
||||
PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLACTIVETEXTUREARBPROC glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLUNIFORM1IARBPROC glUniform1iARB = (PFNGLUNIFORM1IARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLUNIFORM1FARBPROC glUniform1fARB = (PFNGLUNIFORM1FARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLGETINFOLOGARBPROC glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLATTACHOBJECTARBPROC glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLLINKPROGRAMARBPROC glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLCOMPILESHADERARBPROC glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)OOBadOpenGLExtensionUsed;
|
||||
PFNGLSHADERSOURCEARBPROC glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)OOBadOpenGLExtensionUsed;
|
||||
#endif // !defined(NO_SHADERS)
|
||||
|
||||
#if GL_APPLE_vertex_array_object
|
||||
PFNGLBINDVERTEXARRAYAPPLE glBindVertexArrayAPPLE = (PFNGLBINDVERTEXARRAYAPPLE)OOBadOpenGLExtensionUsed;
|
||||
PFNGLDELETEVERTEXARRAYAPPLE glDeleteVertexArraysAPPLE = (PFNGLDELETEVERTEXARRAYAPPLE)OOBadOpenGLExtensionUsed;
|
||||
PFNGLGENVERTEXARRAYAPPLE glGenVertexArraysAPPLE = (PFNGLGENVERTEXARRAYAPPLE)OOBadOpenGLExtensionUsed;
|
||||
PFNGLISVERTEXARRAYAPPLE glIsVertexArrayAPPLE = (PFNGLISVERTEXARRAYAPPLE)OOBadOpenGLExtensionUsed;
|
||||
#endif
|
||||
#endif // OOLITE_WINDOWS
|
||||
|
@ -25,6 +25,7 @@ MA 02110-1301, USA.
|
||||
#import "OOOpenGLExtensionManager.h"
|
||||
#import "OOLogging.h"
|
||||
#import "OOFunctionAttributes.h"
|
||||
#import <stdlib.h>
|
||||
|
||||
|
||||
static NSString * const kOOLogOpenGLShaderSupport = @"rendering.opengl.shader.support";
|
||||
@ -106,9 +107,21 @@ static unsigned IntegerFromString(const GLubyte **ioString);
|
||||
|
||||
#if OOLITE_WINDOWS
|
||||
#if GL_ARB_vertex_buffer_object
|
||||
if ([self haveExtension:@"GL_ARB_vertex_buffer_object"])
|
||||
{
|
||||
glBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
|
||||
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
|
||||
glBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if GL_APPLE_vertex_array_object
|
||||
if ([self haveExtension:@"GL_APPLE_vertex_array_object"])
|
||||
{
|
||||
glBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
|
||||
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
|
||||
glBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -316,3 +329,14 @@ static unsigned IntegerFromString(const GLubyte **ioString)
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#if OOLITE_WINDOWS && !defined(NO_SHADERS)
|
||||
|
||||
void OOBadOpenGLExtensionUsed(void)
|
||||
{
|
||||
OOLog(@"rendering.opengl.badExtension", @"***** An uninitialized OpenGL extension function has been called, terminating. This is a serious error, please report it. *****");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user