Oolite
Loading...
Searching...
No Matches
OOSkyQuadSet Class Reference
Inheritance diagram for OOSkyQuadSet:
Collaboration diagram for OOSkyQuadSet:

Instance Methods

(id) - initWithQuadsWithTexture:inArray:count:
(void) - render
(void) - dealloc [implementation]
(NSString *) - description [implementation]

Class Methods

(void) + addQuads:count:toArray:

Private Attributes

OOTexture * _texture
unsigned _count
GLfloat * _positions
GLfloat * _texCoords
GLfloat * _colors

Detailed Description

Definition at line 69 of file OOSkyDrawable.m.

Method Documentation

◆ addQuads:count:toArray:

+ (void) addQuads: (OOSkyQuadDesc*) quads
count: (unsigned) count
toArray: (NSMutableArray*) ioArray 

Definition at line 472 of file OOSkyDrawable.m.

472 :(OOSkyQuadDesc*)quads count:(unsigned)count toArray:(NSMutableArray*)ioArray
473{
474 NSMutableSet* seenTextures = nil;
475 OOTexture* texture = nil;
476 OOSkyQuadSet* quadSet = nil;
477 unsigned i;
478
479 // Iterate over all quads.
480 seenTextures = [NSMutableSet set];
481 for (i = 0; i != count; ++i) {
482 texture = quads[i].texture;
483
484 // If we haven't seen this quad's texture before...
485 if (![seenTextures containsObject:texture]) {
486 [seenTextures addObject:texture];
487
488 // ...create a quad set for this texture.
489 quadSet = [[self alloc] initWithQuadsWithTexture:texture
490 inArray:quads
491 count:count];
492 if (quadSet != nil) {
493 [ioArray addObject:quadSet];
494 [quadSet release];
495 }
496 }
497 }
498}
unsigned count
return nil
struct OOSkyQuadDesc OOSkyQuadDesc
OOTexture * texture

References count, nil, and OOSkyQuadDesc::texture.

Referenced by OOSkyDrawable(OOPrivate)::addQuads:count:.

Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 616 of file OOSkyDrawable.m.

617{
618 [_texture release];
619
620 if (_positions != NULL)
621 free(_positions);
622 if (_texCoords != NULL)
623 free(_texCoords);
624 if (_colors != NULL)
625 free(_colors);
626
627 [super dealloc];
628}
GLfloat * _positions
GLfloat * _colors
GLfloat * _texCoords

References _colors, _positions, _texCoords, and dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ description

- (NSString *) description
implementation

Definition at line 630 of file OOSkyDrawable.m.

631{
632 return [NSString stringWithFormat:@"<%@ %p>{%u quads, texture: %@}", [self class], self, _count, _texture];
633}

References description.

Referenced by description.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithQuadsWithTexture:inArray:count:

- (id) initWithQuadsWithTexture: (OOTexture*) texture
inArray: (OOSkyQuadDesc*) array
count: (unsigned) totalCount 

Definition at line 500 of file OOSkyDrawable.m.

500 :(OOTexture*)texture inArray:(OOSkyQuadDesc*)array count:(unsigned)totalCount
501{
502 BOOL OK = YES;
503 unsigned i, j, vertexCount;
504 GLfloat* pos;
505 GLfloat* tc;
506 GLfloat* col;
507 GLfloat r, g, b, x;
508 size_t posSize, tcSize, colSize;
509 unsigned count = 0;
510 int skyColorCorrection = [[NSUserDefaults standardUserDefaults] oo_integerForKey:@"sky-color-correction" defaultValue:0];
511
512// Hejl / Burgess-Dawson filmic tone mapping
513// this algorithm has gamma correction already embedded
514#define SKYCOLOR_TONEMAP_COMPONENT(skyColorComponent) \
515 do { \
516 x = MAX(0.0, skyColorComponent - 0.004); \
517 *col++ = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); \
518 } while (0)
519
520 self = [super init];
521 if (self == nil)
522 OK = NO;
523
524 if (OK) {
525 // Count the quads in the array using this texture.
526 for (i = 0; i != totalCount; ++i) {
527 if (array[i].texture == texture)
528 ++_count;
529 }
530 if (_count == 0)
531 OK = NO;
532 }
533
534 if (OK) {
535 // Allocate arrays.
536 vertexCount = _count * 4;
537 posSize = sizeof *_positions * vertexCount * kSkyQuadSetPositionEntriesPerVertex;
538 tcSize = sizeof *_texCoords * vertexCount * kSkyQuadSetTexCoordEntriesPerVertex;
539 colSize = sizeof *_colors * vertexCount * kSkyQuadSetColorEntriesPerVertex;
540
541 _positions = malloc(posSize);
542 _texCoords = malloc(tcSize);
543 _colors = malloc(colSize);
544
545 if (_positions == NULL || _texCoords == NULL || _colors == NULL)
546 OK = NO;
547
548 pos = _positions;
549 tc = _texCoords;
550 col = _colors;
551 }
552
553 if (OK) {
554 // Find the matching quads again, and convert them to renderable representation.
555 for (i = 0; i != totalCount; ++i) {
556 if (array[i].texture == texture) {
557 r = [array[i].color redComponent];
558 g = [array[i].color greenComponent];
559 b = [array[i].color blueComponent];
560
561 // Loop over vertices
562 for (j = 0; j != 4; ++j) {
563 *pos++ = array[i].corners[j].x;
564 *pos++ = array[i].corners[j].y;
565 *pos++ = array[i].corners[j].z;
566
567 // Colour is the same for each vertex
568 if (skyColorCorrection == 0) // no color correction
569 {
570 *col++ = r;
571 *col++ = g;
572 *col++ = b;
573 } else if (skyColorCorrection == 1) // gamma correction only
574 {
575 *col++ = pow(r, 1.0 / 2.2);
576 *col++ = pow(g, 1.0 / 2.2);
577 *col++ = pow(b, 1.0 / 2.2);
578 } else // gamma correctioin + filmic tone mapping
579 {
583 }
584 *col++ = 1.0f; // Alpha is unused but needs to be there
585 }
586
587 // Texture co-ordinates are the same for each quad.
588 *tc++ = sMinTexCoord;
589 *tc++ = sMinTexCoord;
590
591 *tc++ = sMaxTexCoord;
592 *tc++ = sMinTexCoord;
593
594 *tc++ = sMaxTexCoord;
595 *tc++ = sMaxTexCoord;
596
597 *tc++ = sMinTexCoord;
598 *tc++ = sMaxTexCoord;
599
600 count++;
601 }
602 }
603
604 _texture = [texture retain];
605 OOLog(@"sky.setup", @"Generated quadset with %u quads for texture %@", count, _texture);
606 }
607
608 if (!OK) {
609 [self release];
610 self = nil;
611 }
612
613 return self;
614}
#define OOLog(class, format,...)
Definition OOLogging.h:84
float y
float x
static float sMaxTexCoord
static float sMinTexCoord
@ kSkyQuadSetTexCoordEntriesPerVertex
@ kSkyQuadSetPositionEntriesPerVertex
@ kSkyQuadSetColorEntriesPerVertex
#define SKYCOLOR_TONEMAP_COMPONENT(skyColorComponent)
unsigned _count
OOTexture * _texture

References _colors, _count, _positions, _texCoords, _texture, OOSkyQuadDesc::corners, count, kSkyQuadSetColorEntriesPerVertex, kSkyQuadSetPositionEntriesPerVertex, kSkyQuadSetTexCoordEntriesPerVertex, nil, OOLog, SKYCOLOR_TONEMAP_COMPONENT, sMaxTexCoord, sMinTexCoord, Vector::x, x, Vector::y, and Vector::z.

◆ render

- (void) render

Definition at line 635 of file OOSkyDrawable.m.

636{
638
639 [_texture apply];
640
641 OOGL(glVertexPointer(kSkyQuadSetPositionEntriesPerVertex, GL_FLOAT, 0, _positions));
642 OOGL(glTexCoordPointer(kSkyQuadSetTexCoordEntriesPerVertex, GL_FLOAT, 0, _texCoords));
643 OOGL(glColorPointer(kSkyQuadSetColorEntriesPerVertex, GL_FLOAT, 0, _colors));
644
645 OOGL(glDrawArrays(GL_QUADS, 0, 4 * _count));
646}
#define OO_ENTER_OPENGL()
#define OOGL(statement)
Definition OOOpenGL.h:262

References _colors, _count, _positions, _texCoords, OOTexture::apply, kSkyQuadSetColorEntriesPerVertex, kSkyQuadSetPositionEntriesPerVertex, kSkyQuadSetTexCoordEntriesPerVertex, OO_ENTER_OPENGL, OOGL, and render.

Referenced by render.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _colors

- (GLfloat*) _colors
private

Definition at line 75 of file OOSkyDrawable.m.

Referenced by dealloc, initWithQuadsWithTexture:inArray:count:, and render.

◆ _count

- (unsigned) _count
private

Definition at line 72 of file OOSkyDrawable.m.

Referenced by initWithQuadsWithTexture:inArray:count:, and render.

◆ _positions

- (GLfloat*) _positions
private

Definition at line 73 of file OOSkyDrawable.m.

Referenced by dealloc, initWithQuadsWithTexture:inArray:count:, and render.

◆ _texCoords

- (GLfloat*) _texCoords
private

Definition at line 74 of file OOSkyDrawable.m.

Referenced by dealloc, initWithQuadsWithTexture:inArray:count:, and render.

◆ _texture

- (OOTexture*) _texture
private

Definition at line 71 of file OOSkyDrawable.m.

Referenced by initWithQuadsWithTexture:inArray:count:.


The documentation for this class was generated from the following file: