Oolite 1.91.0.7745-260117-205bce7
Loading...
Searching...
No Matches
OOSkyQuadSet Class Reference
Inheritance diagram for OOSkyQuadSet:
Collaboration diagram for OOSkyQuadSet:

Instance Methods

(id) - initWithQuadsWithTexture:inArray:count:
(void) - render
(size_t) - totalSize
(OOTexture *) - texture
(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 76 of file OOSkyDrawable.m.

Method Documentation

◆ addQuads:count:toArray:

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

Definition at line 514 of file OOSkyDrawable.m.

514 :(OOSkyQuadDesc *)quads count:(unsigned)count toArray:(NSMutableArray *)ioArray
515{
516 NSMutableSet *seenTextures = nil;
517 OOTexture *texture = nil;
518 OOSkyQuadSet *quadSet = nil;
519 unsigned i;
520
521 // Iterate over all quads.
522 seenTextures = [NSMutableSet set];
523 for (i = 0; i != count; ++i)
524 {
525 texture = quads[i].texture;
526
527 // If we haven't seen this quad's texture before...
528 if (![seenTextures containsObject:texture])
529 {
530 [seenTextures addObject:texture];
531
532 // ...create a quad set for this texture.
533 quadSet = [[self alloc] initWithQuadsWithTexture:texture
534 inArray:quads
535 count:count];
536 if (quadSet != nil)
537 {
538 [ioArray addObject:quadSet];
539 [quadSet release];
540 }
541 }
542 }
543}
unsigned count
return nil
struct OOSkyQuadDesc OOSkyQuadDesc
OOTexture * texture()
OOTexture * texture

References count, nil, texture, and OOSkyQuadDesc::texture.

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

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

◆ dealloc

- (void) dealloc
implementation

Definition at line 669 of file OOSkyDrawable.m.

670{
671 [_texture release];
672
673 if (_positions != NULL) free(_positions);
674 if (_texCoords != NULL) free(_texCoords);
675 if (_colors != NULL) free(_colors);
676
677 [super dealloc];
678}
GLfloat * _positions
GLfloat * _colors
GLfloat * _texCoords

References _colors, _positions, _texCoords, dealloc, and OOTexture::release.

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 681 of file OOSkyDrawable.m.

682{
683 return [NSString stringWithFormat:@"<%@ %p>{%u quads, texture: %@}", [self class], self, _count, _texture];
684}

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 546 of file OOSkyDrawable.m.

546 :(OOTexture *)texture inArray:(OOSkyQuadDesc *)array count:(unsigned)totalCount
547{
548 BOOL OK = YES;
549 unsigned i, j, vertexCount;
550 GLfloat *pos;
551 GLfloat *tc;
552 GLfloat *col;
553 GLfloat r, g, b, x;
554 size_t posSize, tcSize, colSize;
555 unsigned count = 0;
556 int skyColorCorrection = [[NSUserDefaults standardUserDefaults] oo_integerForKey:@"sky-color-correction" defaultValue:0];
557
558// Hejl / Burgess-Dawson filmic tone mapping
559// this algorithm has gamma correction already embedded
560#define SKYCOLOR_TONEMAP_COMPONENT(skyColorComponent) \
561do { \
562 x = MAX(0.0, skyColorComponent - 0.004); \
563 *col++ = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); \
564} while (0)
565
566 self = [super init];
567 if (self == nil) OK = NO;
568
569 if (OK)
570 {
571 // Count the quads in the array using this texture.
572 for (i = 0; i != totalCount; ++i)
573 {
574 if (array[i].texture == texture) ++_count;
575 }
576 if (_count == 0) OK = NO;
577 }
578
579 if (OK)
580 {
581 // Allocate arrays.
582 vertexCount = _count * 4;
583 posSize = sizeof *_positions * vertexCount * kSkyQuadSetPositionEntriesPerVertex;
584 tcSize = sizeof *_texCoords * vertexCount * kSkyQuadSetTexCoordEntriesPerVertex;
585 colSize = sizeof *_colors * vertexCount * kSkyQuadSetColorEntriesPerVertex;
586
587 _positions = malloc(posSize);
588 _texCoords = malloc(tcSize);
589 _colors = malloc(colSize);
590
591 if (_positions == NULL || _texCoords == NULL || _colors == NULL) OK = NO;
592
593 pos = _positions;
594 tc = _texCoords;
595 col = _colors;
596 }
597
598 if (OK)
599 {
600 // Find the matching quads again, and convert them to renderable representation.
601 for (i = 0; i != totalCount; ++i)
602 {
603 if (array[i].texture == texture)
604 {
605 r = [array[i].color redComponent];
606 g = [array[i].color greenComponent];
607 b = [array[i].color blueComponent];
608
609 // Loop over vertices
610 for (j = 0; j != 4; ++j)
611 {
612 *pos++ = array[i].corners[j].x;
613 *pos++ = array[i].corners[j].y;
614 *pos++ = array[i].corners[j].z;
615
616 // Colour is the same for each vertex
617 if (skyColorCorrection == 0) // no color correction
618 {
619 *col++ = r;
620 *col++ = g;
621 *col++ = b;
622 }
623 else if (skyColorCorrection == 1) // gamma correction only
624 {
625 *col++ = pow(r, 1.0/2.2);
626 *col++ = pow(g, 1.0/2.2);
627 *col++ = pow(b, 1.0/2.2);
628 }
629 else // gamma correctioin + filmic tone mapping
630 {
634 }
635 *col++ = 1.0f; // Alpha is unused but needs to be there
636 }
637
638 // Texture co-ordinates are the same for each quad.
639 *tc++ = sMinTexCoord;
640 *tc++ = sMinTexCoord;
641
642 *tc++ = sMaxTexCoord;
643 *tc++ = sMinTexCoord;
644
645 *tc++ = sMaxTexCoord;
646 *tc++ = sMaxTexCoord;
647
648 *tc++ = sMinTexCoord;
649 *tc++ = sMaxTexCoord;
650
651 count++;
652 }
653 }
654
655 _texture = [texture retain];
656 OOLog(@"sky.setup", @"Generated quadset with %u quads for texture %@", count, _texture);
657 }
658
659 if (!OK)
660 {
661 [self release];
662 self = nil;
663 }
664
665 return self;
666}
#define OOLog(class, format,...)
Definition OOLogging.h:88
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, OOTexture::retain, SKYCOLOR_TONEMAP_COMPONENT, sMaxTexCoord, sMinTexCoord, texture, and x.

Here is the call graph for this function:

◆ render

- (void) render

Definition at line 687 of file OOSkyDrawable.m.

688{
690
691 [_texture apply];
692
693 OOGL(glVertexPointer(kSkyQuadSetPositionEntriesPerVertex, GL_FLOAT, 0, _positions));
694 OOGL(glTexCoordPointer(kSkyQuadSetTexCoordEntriesPerVertex, GL_FLOAT, 0, _texCoords));
695 OOGL(glColorPointer(kSkyQuadSetColorEntriesPerVertex, GL_FLOAT, 0, _colors));
696
697 OOGL(glDrawArrays(GL_QUADS, 0, 4 * _count));
698}
#define OO_ENTER_OPENGL()
#define OOGL(statement)
Definition OOOpenGL.h:251

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:

◆ texture

- (OOTexture *) texture

Definition at line 708 of file OOSkyDrawable.m.

709{
710 return _texture;
711}

References _texture, and texture.

Referenced by addQuads:count:toArray:, OOSkyDrawable::allTextures, initWithQuadsWithTexture:inArray:count:, and texture.

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

◆ totalSize

- (size_t) totalSize

Definition at line 702 of file OOSkyDrawable.m.

703{
704 return [self oo_objectSize] + _count * 4 * (sizeof *_positions + sizeof *_texCoords + sizeof *_colors);
705}

References _colors, _count, _positions, _texCoords, and totalSize.

Referenced by OOSkyDrawable::totalSize, and totalSize.

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 83 of file OOSkyDrawable.m.

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

◆ _count

- (unsigned) _count
private

Definition at line 80 of file OOSkyDrawable.m.

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

◆ _positions

- (GLfloat*) _positions
private

Definition at line 81 of file OOSkyDrawable.m.

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

◆ _texCoords

- (GLfloat*) _texCoords
private

Definition at line 82 of file OOSkyDrawable.m.

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

◆ _texture

- (OOTexture*) _texture
private

Definition at line 79 of file OOSkyDrawable.m.

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


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