Added extra shader validation, controlled by DEBUG_SHADER_VALIDATION flag. Removed DEBUG_ENTITIES and merged DEBUG_OCTREE and DEBUG_OCTREE_TEXT into DEBUG_OCTREE_LOGGING.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3148 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-04-11 16:03:43 +00:00
parent e5d8d5c4ad
commit c9cdbc7631
10 changed files with 121 additions and 74 deletions

View File

@ -20,16 +20,15 @@ debugFlags : Number (integer, read/write)
An integer bit mask specifying various debug options. The flags vary
between builds, but at the time of writing they are:
console.DEBUG_LINKED_LISTS
console.DEBUG_ENTITIES
console.DEBUG_COLLISIONS
console.DEBUG_DOCKING
console.DEBUG_OCTREE
console.DEBUG_OCTREE_TEXT
console.DEBUG_OCTREE_LOGGING
console.DEBUG_BOUNDING_BOXES
console.DEBUG_OCTREE_DRAW
console.DEBUG_DRAW_NORMALS
console.DEBUG_NO_DUST
console.DEBUG_NO_SHADER_FALLBACK
console.DEBUG_SHADER_VALIDATION
The current flags can be seen in OODebugFlags.h in the Oolite source code,
for instance at:

View File

@ -3645,8 +3645,6 @@
GCC_REUSE_STRINGS = YES;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_VERSION = 4.2;
"GCC_VERSION[sdk=macosx10.4][arch=*]" = 4.0;
HEADER_SEARCH_PATHS = (
"$(HEADER_SEARCH_PATHS_QUOTED_1)",
"$(HEADER_SEARCH_PATHS_QUOTED_2)",

View File

@ -47,10 +47,17 @@
attribute vec3 tangent;
#ifndef OO_LIGHT_0_FIX
#define OO_LIGHT_0_FIX 0
#endif
// No vNormal, because normal is always 0,0,1 in tangent space.
varying vec3 vEyeVector;
varying vec2 vTexCoord;
#if OO_LIGHT_0_FIX
varying vec3 vLight0Vector;
#endif
varying vec3 vLight1Vector;
#ifndef OOSTD_DIFFUSE_MAP_IS_CUBE_MAP
@ -74,8 +81,10 @@ void main(void)
vec3 eyeVector = -vec3(gl_ModelViewMatrix * gl_Vertex);
vEyeVector = eyeVector * TBN;
#if OO_LIGHT_0_FIX
vec3 light0Vector = gl_LightSource[0].position.xyz + eyeVector;
vLight0Vector = light0Vector * TBN;
#endif
vec3 light1Vector = gl_LightSource[1].position.xyz + eyeVector;
vLight1Vector = light1Vector * TBN;

View File

@ -5,16 +5,17 @@
enum OODebugFlags
{
DEBUG_LINKED_LISTS = 0x00000001,
DEBUG_ENTITIES = 0x00000002,
// UNUSED = 0x00000002,
DEBUG_COLLISIONS = 0x00000004,
DEBUG_DOCKING = 0x00000008,
DEBUG_OCTREE = 0x00000010,
DEBUG_OCTREE_TEXT = 0x00000020,
DEBUG_OCTREE_LOGGING = 0x00000010,
// UNUSED = 0x00000020,
DEBUG_BOUNDING_BOXES = 0x00000040,
DEBUG_OCTREE_DRAW = 0x00000080,
DEBUG_DRAW_NORMALS = 0x00000100,
DEBUG_NO_DUST = 0x00000200,
DEBUG_NO_SHADER_FALLBACK = 0x00000400,
DEBUG_SHADER_VALIDATION = 0x00000800,
// Flag for temporary use, always last in list.
DEBUG_MISC = 0x10000000

View File

@ -108,16 +108,15 @@ enum
// Symbolic constants for debug flags:
kConsole_DEBUG_LINKED_LISTS,
kConsole_DEBUG_ENTITIES,
kConsole_DEBUG_COLLISIONS,
kConsole_DEBUG_DOCKING,
kConsole_DEBUG_OCTREE,
kConsole_DEBUG_OCTREE_TEXT,
kConsole_DEBUG_OCTREE_LOGGING,
kConsole_DEBUG_BOUNDING_BOXES,
kConsole_DEBUG_OCTREE_DRAW,
kConsole_DEBUG_DRAW_NORMALS,
kConsole_DEBUG_NO_DUST,
kConsole_DEBUG_NO_SHADER_FALLBACK,
kConsole_DEBUG_SHADER_VALIDATION,
kConsole_DEBUG_MISC
};
@ -135,16 +134,15 @@ static JSPropertySpec sConsoleProperties[] =
#define DEBUG_FLAG_DECL(x) { #x, kConsole_##x, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY }
DEBUG_FLAG_DECL(DEBUG_LINKED_LISTS),
DEBUG_FLAG_DECL(DEBUG_ENTITIES),
DEBUG_FLAG_DECL(DEBUG_COLLISIONS),
DEBUG_FLAG_DECL(DEBUG_DOCKING),
DEBUG_FLAG_DECL(DEBUG_OCTREE),
DEBUG_FLAG_DECL(DEBUG_OCTREE_TEXT),
DEBUG_FLAG_DECL(DEBUG_OCTREE_LOGGING),
DEBUG_FLAG_DECL(DEBUG_BOUNDING_BOXES),
DEBUG_FLAG_DECL(DEBUG_OCTREE_DRAW),
DEBUG_FLAG_DECL(DEBUG_DRAW_NORMALS),
DEBUG_FLAG_DECL(DEBUG_NO_DUST),
DEBUG_FLAG_DECL(DEBUG_NO_SHADER_FALLBACK),
DEBUG_FLAG_DECL(DEBUG_SHADER_VALIDATION),
DEBUG_FLAG_DECL(DEBUG_MISC),
#undef DEBUG_FLAG_DECL
@ -276,16 +274,15 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name,
#define DEBUG_FLAG_CASE(x) case kConsole_##x: *outValue = INT_TO_JSVAL(x); break;
DEBUG_FLAG_CASE(DEBUG_LINKED_LISTS);
DEBUG_FLAG_CASE(DEBUG_ENTITIES);
DEBUG_FLAG_CASE(DEBUG_COLLISIONS);
DEBUG_FLAG_CASE(DEBUG_DOCKING);
DEBUG_FLAG_CASE(DEBUG_OCTREE);
DEBUG_FLAG_CASE(DEBUG_OCTREE_TEXT);
DEBUG_FLAG_CASE(DEBUG_OCTREE_LOGGING);
DEBUG_FLAG_CASE(DEBUG_BOUNDING_BOXES);
DEBUG_FLAG_CASE(DEBUG_OCTREE_DRAW);
DEBUG_FLAG_CASE(DEBUG_DRAW_NORMALS);
DEBUG_FLAG_CASE(DEBUG_NO_DUST);
DEBUG_FLAG_CASE(DEBUG_NO_SHADER_FALLBACK);
DEBUG_FLAG_CASE(DEBUG_SHADER_VALIDATION);
DEBUG_FLAG_CASE(DEBUG_MISC);
#undef DEBUG_FLAG_CASE
@ -356,16 +353,15 @@ static BOOL DoWeDefineAllDebugFlags(enum OODebugFlags flags)
switch (flags)
{
case DEBUG_LINKED_LISTS:
case DEBUG_ENTITIES:
case DEBUG_COLLISIONS:
case DEBUG_DOCKING:
case DEBUG_OCTREE:
case DEBUG_OCTREE_TEXT:
case DEBUG_OCTREE_LOGGING:
case DEBUG_BOUNDING_BOXES:
case DEBUG_OCTREE_DRAW:
case DEBUG_DRAW_NORMALS:
case DEBUG_NO_DUST:
case DEBUG_NO_SHADER_FALLBACK:
case DEBUG_SHADER_VALIDATION:
case DEBUG_MISC:
return YES;

View File

@ -1323,12 +1323,6 @@ static NSTimeInterval time_last_frame;
[UNIVERSE addMessage:@"Bounding box debug ON" forCount:3];
}
if ([gameView isDown:'c'])// look for the 'c' key
{
gDebugFlags |= DEBUG_OCTREE;
[UNIVERSE addMessage:@"Octree debug ON" forCount:3];
}
#endif
if ([gameView isDown:'s'])// look for the 's' key

View File

@ -871,7 +871,7 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl
hh *= 0.5;
#ifndef NDEBUG
if ((ship->isPlayer)&&(gDebugFlags & DEBUG_DOCKING))
if ([ship isPlayer] && (gDebugFlags & DEBUG_DOCKING))
{
BOOL inLane;
float range;

View File

@ -54,6 +54,7 @@ SOFTWARE.
#import "OOOpenGLExtensionManager.h"
#import "OOMacroOpenGL.h"
#import "OOCollectionExtractors.h"
#import "OODebugFlags.h"
static NSMutableDictionary *sShaderCache = nil;
@ -182,6 +183,77 @@ static NSString *GetGLSLInfoLog(GLhandleARB shaderObject);
@end
static BOOL ValidateShaderObject(GLhandleARB object, NSString *name)
{
GLint type, subtype = 0, status;
GLenum statusType;
NSString *subtypeString = nil;
NSString *actionString = nil;
OO_ENTER_OPENGL();
OOGL(glGetObjectParameterivARB(object, GL_OBJECT_TYPE_ARB, &type));
BOOL linking = type == GL_PROGRAM_OBJECT_ARB;
if (linking)
{
subtypeString = @"shader program";
actionString = @"linking";
statusType = GL_OBJECT_LINK_STATUS_ARB;
}
else
{
// FIXME
OOGL(glGetObjectParameterivARB(object, GL_OBJECT_SUBTYPE_ARB, &subtype));
switch (subtype)
{
case GL_VERTEX_SHADER_ARB:
subtypeString = @"vertex shader";
break;
case GL_FRAGMENT_SHADER_ARB:
subtypeString = @"fragment shader";
break;
#if GL_EXT_geometry_shader4
case GL_GEOMETRY_SHADER_EXT:
subtypeString = @"geometry shader";
break;
#endif
default:
subtypeString = [NSString stringWithFormat:@"<unknown shader type 0x%.4X>", subtype];
}
actionString = @"compilation";
statusType = GL_OBJECT_COMPILE_STATUS_ARB;
}
OOGL(glGetObjectParameterivARB(object, statusType, &status));
if (status == GL_FALSE)
{
NSString *msgClass = [NSString stringWithFormat:@"shader.%.failure", linking ? @"link" : @"compile"];
OOLogERR(msgClass, @"GLSL %@ %@ failed for %@:\n>>>>> GLSL log:\n%@\n", subtypeString, actionString, name, GetGLSLInfoLog(object));
return NO;
}
#ifndef NDEBUG
if (gDebugFlags & DEBUG_SHADER_VALIDATION)
{
OOGL(glValidateProgramARB(object));
OOGL(glGetObjectParameterivARB(object, GL_OBJECT_VALIDATE_STATUS_ARB, &status));
if (status == GL_FALSE)
{
NSString *msgClass = [NSString stringWithFormat:@"shader.%.validationFailure", linking ? @"link" : @"compile"];
OOLogWARN(msgClass, @"GLSL %@ %@ failed for %@:\n>>>>> GLSL log:\n%@\n", subtypeString, @"validation", name, GetGLSLInfoLog(object));
return NO;
}
}
#endif
return YES;
}
@implementation OOShaderProgram (OOPrivate)
- (id)initWithVertexShaderSource:(NSString *)vertexSource
@ -194,7 +266,6 @@ static NSString *GetGLSLInfoLog(GLhandleARB shaderObject);
{
BOOL OK = YES;
const GLcharARB *sourceStrings[2] = { "", NULL };
GLint compileStatus;
GLhandleARB vertexShader = NULL_SHADER;
GLhandleARB fragmentShader = NULL_SHADER;
@ -220,12 +291,7 @@ static NSString *GetGLSLInfoLog(GLhandleARB shaderObject);
OOGL(glShaderSourceARB(vertexShader, 2, sourceStrings, NULL));
OOGL(glCompileShaderARB(vertexShader));
OOGL(glGetObjectParameterivARB(vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &compileStatus));
if (compileStatus != GL_TRUE)
{
OOLog(@"shader.compile.vertex.failure", @"***** GLSL %s shader compilation failed for %@:\n>>>>> GLSL log:\n%@\n", "vertex", vertexName, GetGLSLInfoLog(vertexShader));
OK = NO;
}
OK = ValidateShaderObject(vertexShader, vertexName);
}
else OK = NO;
}
@ -240,12 +306,7 @@ static NSString *GetGLSLInfoLog(GLhandleARB shaderObject);
OOGL(glShaderSourceARB(fragmentShader, 2, sourceStrings, NULL));
OOGL(glCompileShaderARB(fragmentShader));
OOGL(glGetObjectParameterivARB(fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, &compileStatus));
if (compileStatus != GL_TRUE)
{
OOLog(@"shader.compile.fragment.failure", @"***** GLSL %s shader compilation failed for %@:\n>>>>> GLSL log:\n%@\n", "fragment", fragmentName, GetGLSLInfoLog(fragmentShader));
OK = NO;
}
OK = ValidateShaderObject(fragmentShader, fragmentName);
}
else OK = NO;
}
@ -261,12 +322,7 @@ static NSString *GetGLSLInfoLog(GLhandleARB shaderObject);
[self bindAttributes:attributeBindings];
OOGL(glLinkProgramARB(program));
OOGL(glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &compileStatus));
if (compileStatus != GL_TRUE)
{
OOLog(@"shader.link.failure", @"***** GLSL shader linking failed:\n>>>>> GLSL log:\n%@\n", GetGLSLInfoLog(program));
OK = NO;
}
OK = ValidateShaderObject(vertexShader, [NSString stringWithFormat:@"%@/%@", vertexName, fragmentName]);
}
else OK = NO;
}

View File

@ -32,10 +32,9 @@ MA 02110-1301, USA.
#ifndef NDEBUG
#define OctreeDebugLogVerbose(format, ...) do { if (EXPECT_NOT(gDebugFlags & DEBUG_OCTREE_TEXT)) OOLog(@"octree.debug", format, ## __VA_ARGS__); } while (0)
#define OctreeDebugLog(format, ...) do { if (EXPECT_NOT(gDebugFlags & DEBUG_OCTREE)) OOLog(@"octree.debug", format, ## __VA_ARGS__); } while (0)
#define OctreeDebugLog(format, ...) do { if (EXPECT_NOT(gDebugFlags & DEBUG_OCTREE_LOGGING)) OOLog(@"octree.debug", format, ## __VA_ARGS__); } while (0)
#else
#define OctreeDebugLogVerbose(...) do {} while (0)
#define OctreeDebugLog(...) do {} while (0)
#define OctreeDebugLog(...) do {} while (0)
#endif
@ -400,18 +399,18 @@ static BOOL isHitByLine(int* octbuffer, unsigned char* collbuffer, int level, GL
Vector u0 = make_vector( v0.x + off.x, v0.y + off.y, v0.z + off.z);
Vector u1 = make_vector( v1.x + off.x, v1.y + off.y, v1.z + off.z);
OctreeDebugLogVerbose(@"DEBUG octant: [%d] radius: %.2f vs. line: ( %.2f, %.2f, %.2f) - ( %.2f, %.2f, %.2f)",
OctreeDebugLog(@"DEBUG octant: [%d] radius: %.2f vs. line: ( %.2f, %.2f, %.2f) - ( %.2f, %.2f, %.2f)",
level, rad, u0.x, u0.y, u0.z, u1.x, u1.y, u1.z);
if (octbuffer[level] == 0)
{
OctreeDebugLogVerbose(@"DEBUG Hit an empty octant: [%d]", level);
OctreeDebugLog(@"DEBUG Hit an empty octant: [%d]", level);
return NO;
}
if (octbuffer[level] == -1)
{
OctreeDebugLogVerbose(@"DEBUG Hit a solid octant: [%d]", level);
OctreeDebugLog(@"DEBUG Hit a solid octant: [%d]", level);
collbuffer[level] = 2; // green
hit_dist = sqrt( u0.x * u0.x + u0.y * u0.y + u0.z * u0.z);
return YES;
@ -423,7 +422,7 @@ static BOOL isHitByLine(int* octbuffer, unsigned char* collbuffer, int level, GL
if (faces == 0)
{
OctreeDebugLogVerbose(@"----> Line misses octant: [%d].", level);
OctreeDebugLog(@"----> Line misses octant: [%d].", level);
return NO;
}
@ -448,19 +447,19 @@ static BOOL isHitByLine(int* octbuffer, unsigned char* collbuffer, int level, GL
if (CUBE_FACE_BOTTOM & faces)
octantIntersected = ((vi.x < 0.0)? 0: 4) + ((vi.z < 0.0)? 0: 1);
OctreeDebugLogVerbose(@"----> found intersection with face 0x%2x of cube of radius %.2f at ( %.2f, %.2f, %.2f) octant:%d",
OctreeDebugLog(@"----> found intersection with face 0x%2x of cube of radius %.2f at ( %.2f, %.2f, %.2f) octant:%d",
faces, rad, vi.x, vi.y, vi.z, octantIntersected);
}
else
{
OctreeDebugLogVerbose(@"----> inside cube of radius %.2f octant:%d", rad, octantIntersected);
OctreeDebugLog(@"----> inside cube of radius %.2f octant:%d", rad, octantIntersected);
}
hasCollided = YES;
collbuffer[level] = 1; // red
OctreeDebugLogVerbose(@"----> testing octants...");
OctreeDebugLog(@"----> testing octants...");
int nextLevel = level + octbuffer[level];
@ -473,12 +472,12 @@ static BOOL isHitByLine(int* octbuffer, unsigned char* collbuffer, int level, GL
oct2 = oct0 ^ 0x02; // adjacent y
oct3 = oct0 ^ 0x04; // adjacent z
OctreeDebugLogVerbose(@"----> testing first octant hit [+%d]", oct0);
OctreeDebugLog(@"----> testing first octant hit [+%d]", oct0);
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct0)) return YES; // first octant
// test the three adjacent octants
OctreeDebugLogVerbose(@"----> testing next three octants [+%d] [+%d] [+%d]", oct1, oct2, oct3);
OctreeDebugLog(@"----> testing next three octants [+%d] [+%d] [+%d]", oct1, oct2, oct3);
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct1)) return YES; // second octant
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct2)) return YES; // third octant
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct3)) return YES; // fourth octant
@ -487,13 +486,13 @@ static BOOL isHitByLine(int* octbuffer, unsigned char* collbuffer, int level, GL
oct0 ^= 0x07; oct1 ^= 0x07; oct2 ^= 0x07; oct3 ^= 0x07;
OctreeDebugLogVerbose(@"----> testing back three octants [+%d] [+%d] [+%d]", oct1, oct2, oct3);
OctreeDebugLog(@"----> testing back three octants [+%d] [+%d] [+%d]", oct1, oct2, oct3);
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct1)) return YES; // fifth octant
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct2)) return YES; // sixth octant
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct3)) return YES; // seventh octant
// and check the last octant
OctreeDebugLogVerbose(@"----> testing final octant [+%d]", oct0);
OctreeDebugLog(@"----> testing final octant [+%d]", oct0);
if (isHitByLineSub(octbuffer, collbuffer, nextLevel, rad, rd2, u0, u1, oct0)) return YES; // last octant
return NO;
@ -507,13 +506,13 @@ static BOOL isHitByLine(int* octbuffer, unsigned char* collbuffer, int level, GL
if (isHitByLine(octree, octree_collision, 0, radius, v0, v1, kZeroVector, 0))
{
OctreeDebugLogVerbose(@"DEBUG Hit at distance %.2f", hit_dist);
OctreeDebugLog(@"DEBUG Hit at distance %.2f", hit_dist);
hasCollision = hasCollided;
return hit_dist;
}
else
{
OctreeDebugLogVerbose(@"DEBUG Missed!", hit_dist);
OctreeDebugLog(@"DEBUG Missed!", hit_dist);
hasCollision = hasCollided;
return 0.0;
}
@ -529,19 +528,19 @@ BOOL isHitByOctree( Octree_details axialDetails,
if (axialBuffer[0] == 0)
{
OctreeDebugLogVerbose(@"DEBUG Axial octree is empty.");
OctreeDebugLog(@"DEBUG Axial octree is empty.");
return NO;
}
if (!otherBuffer)
{
OctreeDebugLogVerbose(@"DEBUG Other octree is undefined.");
OctreeDebugLog(@"DEBUG Other octree is undefined.");
return NO;
}
if (otherBuffer[0] == 0)
{
OctreeDebugLogVerbose(@"DEBUG Other octree is empty.");
OctreeDebugLog(@"DEBUG Other octree is empty.");
return NO;
}
@ -555,7 +554,7 @@ BOOL isHitByOctree( Octree_details axialDetails,
(otherPosition.y + otherRadius < -axialRadius)||(otherPosition.y - otherRadius > axialRadius)||
(otherPosition.z + otherRadius < -axialRadius)||(otherPosition.z - otherRadius > axialRadius))
{
OctreeDebugLogVerbose(@"----> Other sphere does not intersect axial cube");
OctreeDebugLog(@"----> Other sphere does not intersect axial cube");
return NO;
}
}
@ -567,7 +566,7 @@ BOOL isHitByOctree( Octree_details axialDetails,
(axialPosition.y + axialRadius < -otherRadius)||(axialPosition.y - axialRadius > otherRadius)||
(axialPosition.z + axialRadius < -otherRadius)||(axialPosition.z - axialRadius > otherRadius))
{
OctreeDebugLogVerbose(@"----> Axial sphere does not intersect other cube");
OctreeDebugLog(@"----> Axial sphere does not intersect other cube");
return NO;
}
}
@ -593,7 +592,7 @@ BOOL isHitByOctree( Octree_details axialDetails,
// if any of them collides with this octant
// then we have a solid collision
OctreeDebugLogVerbose(@"----> testing other octants...");
OctreeDebugLog(@"----> testing other octants...");
// work out the nearest octant to the axial octree
int nearest_oct = ((otherPosition.x > 0.0)? 0:4)|((otherPosition.y > 0.0)? 0:2)|((otherPosition.z > 0.0)? 0:1);
@ -629,7 +628,7 @@ BOOL isHitByOctree( Octree_details axialDetails,
// the other octree, if any of them collide
// we have a solid collision
OctreeDebugLogVerbose(@"----> testing axial octants...");
OctreeDebugLog(@"----> testing axial octants...");
// work out the nearest octant to the other octree
int nearest_oct = ((otherPosition.x > 0.0)? 4:0)|((otherPosition.y > 0.0)? 2:0)|((otherPosition.z > 0.0)? 1:0);

View File

@ -4166,11 +4166,6 @@ static BOOL MaintainLinkedLists(Universe* uni)
{
ShipEntity* se = nil;
#ifndef NDEBUG
if (gDebugFlags & DEBUG_ENTITIES)
OOLog(@"universe.addEntity", @"Adding entity: %@", entity);
#endif
if (![entity validForAddToUniverse]) return NO;
// don't add things twice!