Oolite 1.91.0.7644-241112-7f5034b
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 83 of file OOSkyDrawable.m.

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

◆ dealloc

- (void) dealloc
implementation

Definition at line 83 of file OOSkyDrawable.m.

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

◆ description

- (NSString *) description
implementation

Definition at line 83 of file OOSkyDrawable.m.

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

◆ initWithQuadsWithTexture:inArray:count:

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

Definition at line 83 of file OOSkyDrawable.m.

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

◆ render

- (void) render

Definition at line 83 of file OOSkyDrawable.m.

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

◆ texture

- (OOTexture *) texture

Definition at line 83 of file OOSkyDrawable.m.

710{
711 return _texture;
712}

◆ totalSize

- (size_t) totalSize

Definition at line 83 of file OOSkyDrawable.m.

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

Member Data Documentation

◆ _colors

- (GLfloat*) _colors
private

Definition at line 83 of file OOSkyDrawable.m.

◆ _count

- (unsigned) _count
private

Definition at line 80 of file OOSkyDrawable.m.

◆ _positions

- (GLfloat*) _positions
private

Definition at line 81 of file OOSkyDrawable.m.

◆ _texCoords

- (GLfloat*) _texCoords
private

Definition at line 82 of file OOSkyDrawable.m.

◆ _texture

- (OOTexture*) _texture
private

Definition at line 79 of file OOSkyDrawable.m.


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