Browse Source

clear viewport

David Rose 17 năm trước cách đây
mục cha
commit
c72cf3f452

+ 1 - 1
panda/src/tinydisplay/clear.c

@@ -25,6 +25,6 @@ void glopClear(GLContext *c,GLParam *p)
   /* TODO : correct value of Z */
 
   ZB_clear(c->zb,mask & GL_DEPTH_BUFFER_BIT,z,
-	   mask & GL_COLOR_BUFFER_BIT,r,g,b);
+	   mask & GL_COLOR_BUFFER_BIT,r,g,b,0);
 }
 

+ 27 - 17
panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx

@@ -677,20 +677,30 @@ clear(DrawableRegion *clearable) {
   
   set_state_and_transform(RenderState::make_empty(), _internal_transform);
 
-  int mask = 0;
-  
+  bool clear_color = false;
+  int r, g, b, a;
   if (clearable->get_clear_color_active()) {
     Colorf v = clearable->get_clear_color();
-    glClearColor(v[0],v[1],v[2],v[3]);
-    mask |= GL_COLOR_BUFFER_BIT;
+    r = (int)(v[0] * 0xffff);
+    g = (int)(v[1] * 0xffff);
+    b = (int)(v[2] * 0xffff);
+    a = (int)(v[3] * 0xffff);
+    clear_color = true;
   }
   
+  bool clear_z = false;
+  int z;
   if (clearable->get_clear_depth_active()) {
-    glClearDepth(clearable->get_clear_depth());
-    mask |= GL_DEPTH_BUFFER_BIT;
+    // We ignore the specified depth clear value, since we don't
+    // support alternate depth compare functions anyway.
+    z = 0;
+    clear_z = true;
   }
-  
-  glClear(mask);
+
+  ZB_clear_viewport(_c->zb, clear_z, z,
+                    clear_color, r, g, b, a,
+                    _c->viewport.xmin, _c->viewport.ymin,
+                    _c->viewport.xsize, _c->viewport.ysize);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -712,24 +722,24 @@ prepare_display_region(DisplayRegionPipelineReader *dr,
   int xsize = GLsizei(w);
   int ysize = GLsizei(h);
   
-  int xsize_req=xmin+xsize;
-  int ysize_req=ymin+ysize;
+  int xsize_req = xmin + xsize;
+  int ysize_req = ymin + ysize;
   
   if (_c->gl_resize_viewport && 
-      _c->gl_resize_viewport(_c,&xsize_req,&ysize_req) != 0) {
+      _c->gl_resize_viewport(_c, &xsize_req, &ysize_req) != 0) {
     gl_fatal_error("glViewport: error while resizing display");
   }
   
-  xsize=xsize_req-xmin;
-  ysize=ysize_req-ymin;
+  xsize = xsize_req - xmin;
+  ysize = ysize_req - ymin;
   if (xsize <= 0 || ysize <= 0) {
     gl_fatal_error("glViewport: size too small");
   }
   
-  _c->viewport.xmin=xmin;
-  _c->viewport.ymin=ymin;
-  _c->viewport.xsize=xsize;
-  _c->viewport.ysize=ysize;
+  _c->viewport.xmin = xmin;
+  _c->viewport.ymin = ymin;
+  _c->viewport.xsize = xsize;
+  _c->viewport.ysize = ysize;
   
   gl_eval_viewport(_c);
 }

+ 39 - 13
panda/src/tinydisplay/zbuffer.c

@@ -293,21 +293,47 @@ void memset_RGB24(void *adr,int r, int v, int b,long count)
 }
 
 void ZB_clear(ZBuffer * zb, int clear_z, int z,
-	      int clear_color, int r, int g, int b)
+	      int clear_color, int r, int g, int b, int a)
 {
-    int color;
-    int y;
-    PIXEL *pp;
+  int color;
+  int y;
+  PIXEL *pp;
+  
+  if (clear_z) {
+    memset_s(zb->zbuf, z, zb->xsize * zb->ysize);
+  }
+  if (clear_color) {
+    color = RGBA_TO_PIXEL(r, g, b, a);
+    pp = zb->pbuf;
+    for (y = 0; y < zb->ysize; y++) {
+      memset_l(pp, color, zb->xsize);
+      pp = (PIXEL *) ((char *) pp + zb->linesize);
+    }
+  }
+}
 
-    if (clear_z) {
-	memset_s(zb->zbuf, z, zb->xsize * zb->ysize);
+void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z,
+                       int clear_color, int r, int g, int b, int a,
+                       int xmin, int ymin, int xsize, int ysize)
+{
+  int color;
+  int y;
+  PIXEL *pp;
+  unsigned short *zz;
+  
+  if (clear_z) {
+    zz = zb->zbuf + xmin;
+    for (y = ymin; y < ymin + ysize; ++y) {
+      memset_s(zz, z, xsize);
+      zz += zb->xsize;
     }
-    if (clear_color) {
-	pp = zb->pbuf;
-	for (y = 0; y < zb->ysize; y++) {
-            color = RGB_TO_PIXEL(r, g, b);
-	    memset_l(pp, color, zb->xsize);
-	    pp = (PIXEL *) ((char *) pp + zb->linesize);
-	}
+  }
+  if (clear_color) {
+    color = RGBA_TO_PIXEL(r, g, b, a);
+    pp = zb->pbuf + xmin;
+    for (y = ymin; y < ymin + ysize; ++y) {
+      memset_l(pp, color, xsize);
+      pp = (PIXEL *) ((char *) pp + zb->linesize);
     }
+  }
 }

+ 5 - 1
panda/src/tinydisplay/zbuffer.h

@@ -117,7 +117,11 @@ void ZB_close(ZBuffer *zb);
 
 void ZB_resize(ZBuffer *zb,void *frame_buffer,int xsize,int ysize);
 void ZB_clear(ZBuffer *zb,int clear_z,int z,
-	      int clear_color,int r,int g,int b);
+	      int clear_color,int r,int g,int b,int a);
+void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z,
+                       int clear_color, int r, int g, int b, int a,
+                       int xmin, int ymin, int xsize, int ysize);
+
 /* linesize is in BYTES */
 void ZB_copyFrameBuffer(ZBuffer *zb,void *buf,int linesize);