Commits

Cliff Biffle  committed 2fdf5c5

At some cost in CPU, the KVMultiDepthMap now tracks colors for occluded surfaces, so texture mapping works again.

  • Participants
  • Parent commits c737ef6

Comments (0)

Files changed (2)

File KVMultiDepthMap.h

 // background can be separated.
 @interface KVMultiDepthMap : NSObject <KVDepthMap> {
  @private
-  colors_t colors;
   depth_t depthCopy;
-  BOOL blinky;
+  colors_t colorCopy;
 }
 
 - init;

File KVMultiDepthMap.m

 @interface KVDepthPlane : NSObject {
   GLfloat linearizationTable[2048];
   depth_t cachedDepth;
+  colors_t cachedColors;
   linear_depth_t zs;
 }
 
 @property(retain, nonatomic) NSColor *color;
 
-- (void) updateAndTransformDepth: (depth_t *) depth finalPlane: (BOOL)finalPlane;
-- (void) drawInCurrentOpenGLContextWithRenderer: (id <KVRenderer>)renderer colors: (const colors_t *)colors;
+- (void) updateAndTransformDepth: (depth_t *) depth colors: (const colors_t *)colors finalPlane: (BOOL)finalPlane;
+- (void) drawInCurrentOpenGLContextWithRenderer: (id <KVRenderer>)renderer;
 - (void) buildLinearizationTable;
 @end
 
   
   NSUInteger planeIndex = 0;
   for (KVDepthPlane *plane in planes) {
-    [plane updateAndTransformDepth: &depthCopy finalPlane: (planeIndex == 1)];
+    [plane updateAndTransformDepth: &depthCopy colors: &colorCopy finalPlane: (planeIndex == 1)];
     planeIndex++;
   }
 }
 
 - (void) updateColor: (const colors_t *)pixels {
-  memcpy(&colors, pixels, sizeof(colors_t));
+  memcpy(&colorCopy, pixels, sizeof(colors_t));
 }
 
 - (void) drawInCurrentOpenGLContextWithRenderer: (id <KVRenderer>) renderer {
   NSUInteger x = 0;
   for (KVDepthPlane *plane in planes) {
-    [plane drawInCurrentOpenGLContextWithRenderer: renderer colors: &colors];
+    [plane drawInCurrentOpenGLContextWithRenderer: renderer];
     x++;
   }
 }
   if ((self = [super init])) {
     self.color = newColor;
     [self buildLinearizationTable];
-    for (int y = 0; y < 480; y++) {
-      for (int x = 0; x < 640; x++) {
-        cachedDepth.samples[y][x] = 0;
-      }
-    }
   }
   return self;
 }
 
-- (void) drawInCurrentOpenGLContextWithRenderer: (id <KVRenderer>)renderer colors: (const colors_t *)colors {
+- (void) drawInCurrentOpenGLContextWithRenderer: (id <KVRenderer>)renderer {
   renderer.color = color;
-  [renderer drawInCurrentOpenGLContext: &zs colors: colors];
+  [renderer drawInCurrentOpenGLContext: &zs colors: &cachedColors];
 }
 
-- (void) updateAndTransformDepth: (depth_t *)depth finalPlane: (BOOL) finalPlane {
+- (void) updateAndTransformDepth: (depth_t *)depth colors: (const colors_t *)newColors finalPlane: (BOOL) finalPlane {
   // Remember: we're working with raw camera depth samples here.  Smaller is
   // closer.
   for (int y = 0; y < 480; y++) {
     for (int x = 0; x < 640; x++) {
       // Ignore all holes in the depth data.
-      if (depth->samples[y][x] == NO_DEPTH) continue;
+      if (depth->samples[y][x] == NO_DEPTH) {
+        cachedColors.pixels[y][x] = newColors->pixels[y][x];
+        continue;
+      }
       
       if (depth->samples[y][x] == ALL_CLEAR) {
         // This ray is not occluded!  I CAN SEE FOREVER
         } else {
           // Update us.
           cachedDepth.samples[y][x] = depth->samples[y][x];
+          cachedColors.pixels[y][x] = newColors->pixels[y][x];
           // Knock a hole for later planes.
           depth->samples[y][x] = ALL_CLEAR;
         }