Oolite
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.

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

◆ dealloc

- (void) dealloc
implementation

Definition at line 83 of file OOSkyDrawable.m.

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

◆ description

- (NSString *) description
implementation

Definition at line 83 of file OOSkyDrawable.m.

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

◆ initWithQuadsWithTexture:inArray:count:

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

Definition at line 83 of file OOSkyDrawable.m.

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

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

◆ texture

- (OOTexture *) texture

Definition at line 83 of file OOSkyDrawable.m.

707{
708 return _texture;
709}

◆ totalSize

- (size_t) totalSize

Definition at line 83 of file OOSkyDrawable.m.

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

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: