delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/23/19:27:34

From: JeLlyFish DOT software AT gmx DOT net (Vinzent Hoefler)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: fast depth buffer
Date: Tue, 23 Nov 1999 22:59:23 GMT
Organization: JeLlyFish software
Lines: 111
Message-ID: <81f698$hsp$1@news01.btx.dtag.de>
References: <81eth3$95r$2 AT gxsn DOT com>
Mime-Version: 1.0
X-Trace: news01.btx.dtag.de 943397992 18329 777000109768-0001 991123 22:59:52
X-Complaints-To: abuse AT t-online DOT de
X-Sender: 777000109768-0001 AT t-dialin DOT net
X-Newsreader: Forte Free Agent 1.11/16.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Anthony Graham" <Anthony AT fonzyco DOT co DOT uk> wrote:

>I need to code a Z-Buffer Manually (Can't use a library as it makes it too
>easy and so i'd not get the grade i need in my A-Level).... This is how it
>works, not the actual code, in DJGPP and ALLEGRO:
>
>int THEZBUFFER[640][480];

Uhuh. Is this a typo? The code uses [y][x] order...

>BITMAP *SCREEN_BUFFER;
>
>void ClearZBuffer()
>{
> int xrun;
> int yrun;
> for (yrun=0;yrun<480;yrun++)
> {
> for (xrun=0;xrun<640;xrun++)
> {
>  THEZBUFFER[yrun][xrun]=1000000;
> }
> }
>}

You should give memset() a try. If it still sets byte by byte you can
use some little assembly to speed this up.

But I don't think it would be a very big difference (unless the
compiler still uses the slow byte by byte approach). Clearing ~1MB of
memory per frame is relatively time-consuming with either method.

Oh, yes!
The VDH(*) method to force the compiler to generate faster code:

void ClearZBuffer()
{
  int srun;
  for (srun=0;srun<640*480;srun++)
  {
      THEZBUFFER[0][srun]=1000000;
  }
}

But from the generated code (GCC 2.95, -O3) I see that it is actually
filled backwards with more code than necessary, so you can give this a
try instead:

void ClearZBuffer()
{
  int srun;
  for (srun=640*480-1;srun>=0;srun--)
  {
      THEZBUFFER[0][srun]=1000000;
  }
}

At least with my DJGPP version this _looks_ faster.

(*) VDH= Very Dirty Hack

>void drawpixel(int x, int y, int z)
>{
>if (z<THEZBUFFER[y][x])
>{
>THEZBUFFER[y][x]=z;
>{draw the pixel}
>}
>
>my first thoughts were to make an int BLANK_ZBUFFER[640][480] and clear that
>and use the normal zbuffer and instead of clearing it:
>THEZBUFFER=BLANK_ZBUFFER but i get an error about incompatable types!! even
>though they're the exact same!!

Mmh. Is it possible to assign complete arrays in C? I didn't try that
myself.

But it wouldn't help anyway, because _moving_ ~1MB of memory is
definitely more time consuming than _filling_ it.

>some libs use a bitmap??!!

Yes. It's a good way to handle moving objects on a static background
with depth information (just like in adventure games).

>but they can only have 256 levels of depth as
>they store chars not ints,

Using 32-bit color bitmaps can help. :-)

>unfortunatly i can't follow the code in these libs, nor can i use them, If
>anyone could explain how to use bitmaps as zbuffers i'd be very grateful.

They use it the same way as you do I think. But instead using memset()
to clear the z-buffer they're using memcpy() to reload it, I think.

>Please use C not C++ as i don't understand C++

Hey, what difference. ;-)

>Please e mail me suggestions to the address below

Ok, CCed.


Vinzent.

-- 
A person who is more than casually interested in computers should be well
schooled in machine language, since it is a fundamental part of a computer.
                -- Donald Knuth

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019