#150304 - Lord Graga - Fri Feb 01, 2008 7:21 pm
Hey all.
I've been working on a 3d engine for the GBA for a couple of years (on and off), and have decided that it is time to give it a major overhaul so that it can compete with more mature engines.
While I should worry the most about structuring my faces and vertices in the most optimal way, I am still playing around with my buggy linear textured polyfiller (which has to be rewritten fully because it sucks and is linear).
God damn those massive overheads, there are too many variables that needs to be handled gracefully.
But, what I want to ask:
Here is my current inner loop for the polyfiller:
I was thinking about doing this:
Would this create better or worse code? I am afraid that it could add some complexity to how the program would handle the stack.
Cheers.
I've been working on a 3d engine for the GBA for a couple of years (on and off), and have decided that it is time to give it a major overhaul so that it can compete with more mature engines.
While I should worry the most about structuring my faces and vertices in the most optimal way, I am still playing around with my buggy linear textured polyfiller (which has to be rewritten fully because it sucks and is linear).
God damn those massive overheads, there are too many variables that needs to be handled gracefully.
But, what I want to ask:
Here is my current inner loop for the polyfiller:
Code: |
while(toplength--)
{ int startx = xleft>>8; int len = (xright>>8) - startx; if(y >= 0 && y < 160 && xright > 0 && startx < 240) { unsigned uv = v | (u << 16); if(startx < 0) { uv -= startx*duvx; len += startx; startx = 0; } if(startx+len > 240) len = 240 - startx; if(len > 0 ) { if(startx & 1) { //Draw first uneven pixel } if(len > 0 ) { //Fill pixels } } } y++; if(y > 159) return; xleft += dxleft; xright += dxright; u += dug; v += dvg; } |
I was thinking about doing this:
Code: |
while(toplength--) {
int startx = xleft>>8; int len = (xright>>8) - startx; if(len < 1 || y < 0 || y > 159 || xright < 0 || startx > 240) goto nodraw; unsigned uv = v | (u << 16); if(startx < 0) { uv -= startx*duvx; len += startx; startx = 0; } if(startx+len > 240) len = 240 - startx; if(len < 1 ) goto nodraw; if(startx & 1) { //Draw first uneven pixel } if(len > 0 ) { //Fill Scanline } nodraw: y++; if(y > 159) return; xleft += dxleft; xright += dxright; u += dug; v += dvg; } |
Would this create better or worse code? I am afraid that it could add some complexity to how the program would handle the stack.
Cheers.