September 08, 2010, 03:19:33 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: New members: I'm testing a different CAPTCHA system that hopefully is less prone to spambot abuse. Email me at jf@jonof.id.au if you have problems.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: drawing fast squares  (Read 469 times)
Hugo Smits
Chatterbox
***
Posts: 171


View Profile WWW
« on: July 23, 2010, 02:45:51 AM »

what is the fastes way to draw voxels that are represented by 2D squares ?

No matter what I do my code always gets slowdown by the drawing routine, this is ofcourse somewhat normal,
but I was hoping to speed it up. What do you guys suggest ?


so I'm searching for something like this :

for(y = 0; y < 4; y++)
{
   for(x = 0; x < 4; x++)
   {
      pixel(x,y,color);
   }
}

or

for(y = 0; y < 4; y++)
{
   pixel(0,y,color);
   pixel(1,y,color);
   pixel(2,y,color);   
   pixel(3,y,color);
}




I was hoping somebody had a damn sweet trick for it.
Logged
ConsistentCallsign
Fixture
*****
Posts: 596


This video is not available in your color.


View Profile
« Reply #1 on: July 23, 2010, 02:51:53 AM »

Why, the fastest way to draw bounded cubes is to use Ken's Voxlap / Slab6 optimized rendering algorithm.
I suggest you skim through Ken's Voxlap / Slab6 source:
http://advsys.net/ken/slab6.zip <--- src included
http://advsys.net/ken/voxlap/voxlap_src.zip <---- src included
Logged

1488 ╬卐†§• • •«««***{ Volumetric Power }***»»»• • •§†卐╬ 1488
¡Viva Voxel! D:
Hugo Smits
Chatterbox
***
Posts: 171


View Profile WWW
« Reply #2 on: July 23, 2010, 02:57:58 AM »

I've read the source before. But it's not too handy for my situation.
Since his drawing code is optimized for PC in ASM, and I'm searching for C/C++ code.

Basically I need a fast routine for C/C++ to plot a square directly to the VRAM.

In case of my examples the pixel function would be :

VRAM[y * width + x] = color;


Logged
CaimX86
Observer
*
Posts: 34


View Profile
« Reply #3 on: July 23, 2010, 03:57:11 AM »

I'm pretty sure the second way is more faster!
Logged
Awesoken
Global Moderator
Fixture
*
Posts: 895



View Profile WWW
« Reply #4 on: July 23, 2010, 09:14:33 AM »

You are losing most of your speed by calling a function for every single pixel. Here's how I would write it:
Code:
typedef struct { long topleft, pitch, xres, yres; } frame_t;
static void drawrect_32bpp (frame_t *dd, long x0, long y0, long x1, long y1, long col)
{
   long *lptr;
   x0 = max(x0,0); x1 = min(x1,dd->xres);
   y0 = max(y0,0); y1 = min(y1,dd->yres);
   lptr = (long *)(y0*dd->pitch + dd->topleft);
   for(y1-=y0;y1>0;y1--,lptr=(long *)(((long)lptr)+dd->pitch))
      for(y0=x0;y0<x1;y0++) lptr[y0] = col;
}
You could use a lookup table for the initial calculation of lptr, but I've found it to not always be faster.
Logged

-Ken S.
Hugo Smits
Chatterbox
***
Posts: 171


View Profile WWW
« Reply #5 on: July 23, 2010, 07:10:29 PM »

thanks Ken, I'm going to try your routine Smiley


Btw; I'm not calling pixel every time, It was just to make the example look more clear.
As I wrote in my second post; I write directly to VRAM.


Logged
Scott_AW
Participant
**
Posts: 79


View Profile WWW
« Reply #6 on: July 23, 2010, 07:27:04 PM »

Sounds interesting, I like to see where this goes.
Logged
Hugo Smits
Chatterbox
***
Posts: 171


View Profile WWW
« Reply #7 on: July 26, 2010, 04:57:21 AM »

And what do you guys use for zbuffer ?


my current routine (inside my voxel render function) looks something like this :


where :
256 is the width of the screen and int posy = y * 256;

if(newz < zbuffer[(posy) + x])  vram[(posy) + x] = color;   
if(newz < zbuffer[(posy) + x + 1])  vram[(posy) + x + 1] = color;

if(newz < zbuffer[(posy + 256) + x])  vram[(posy + 256) + x] = color;   
if(newz < zbuffer[(posy + 256) + x + 1])  vram[(posy + 256) + x + 1] = color;


I basically write everything out, no loops, no multiplies. yet I'm still not happy.

   
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC