Tuesday, June 17, 2025
HomeGame Developmentc - How do I make my Software program 3D Renderer decelerate...

c – How do I make my Software program 3D Renderer decelerate as quickly as I alter the display screen decision throughout runtime?


I am writing a Software program 3D Renderer in C many months after I first initially wrote it in Python. It’s made utilizing SDL2. My engine at the moment has depth shading, perspective appropriate texturing and a few very nice efficiency (330 FPS at 1920×1080 on my Ryzen 5 5500, or a body time of about 3ms.). Nevertheless, I made a decision so as to add in a settings function to my engine that will permit the person to vary the decision with out having to recompile this system. This is able to find yourself with me having to try to work out a serious bug which ended up in large failure – a bug that solely occured each time I set the display screen decision from an array throughout runtime.

I’ve executed my greatest to repair the issue, and have not had any success in any way. I’ve nonetheless observed that if the variables are recognized throughout compilation, my efficiency doesn’t undergo, even when I name the operate for it at runtime. If the values are unknown and I alter them throughout runtime, my efficiency is minimize down by virtually half.

I’ve requested in a number of locations earlier than and I’ve had no success with the ideas given to me. I don’t need to use a profiler as a result of there’s nothing to profile, I do know the place the issue is however I have no idea tips on how to repair that downside – one thing a profiler won’t straight inform me the reply for. I at the moment suspect that the compiler is upset with the actual fact my variables aren’t constants even when modified as soon as and don’t apply the suitable optimizations. I’ve tried writing a few of my raster capabilities in ASM however that has failed.

My Raster Features. I apologise if a few of it’s sloppy.

static inline void draw_wall(float sx0, float sx1, 
    float sy0, float sy1, float sy2, float sy3, Uint16 * limit pixels, 
    portalCull portalBounds, int * limit ceilingLut, int * limit floorLut, int flat, uint16_t * limit w_pixels, float t0, float t1, float wy0, float wy1, float size, float top) 
        case 1:
            for (int x=X0; x> 11) & 0x1F) >> shade);
                    register uint8_t g = (((baseColour >> 5)  & 0x3F) >> shade);
                    register uint8_t b = ((baseColour & 0x1F) >> shade);
                    
                    pixels[row] = (r << 11) ;

static inline void draw_flat(Uint16 *limit pixels, int *limit lut, int flat, portalCull portalBounds, float elevation, float fov, float yaw, float f, float cx, float cy, uint16_t *limit t_pixels) {
    int X0 = clamp(clamp((int)0, portalBounds.x0, portalBounds.x1), 1, SW1);
    int X1 = clamp(clamp((int)SW1, portalBounds.x0, portalBounds.x1), 1, SW1);

    float radFOV = (float)fov*PI/180.0;
    float halfRFOV = radFOV/2.0;
    float radYaw = (float)((int)yaw)*PI/180.0;
    float elevationFactor = elevation * f;
    change (flat)  b;
                    row += SW;
                
            }
            break;
        case 2:
        for (int x=X0; x> 11) & 0x1F) >> shade);
                register uint8_t g = (((baseColour >> 5)  & 0x3F) >> shade);
                register uint8_t b = ((baseColour & 0x1F) >> shade);
                
                pixels[row] = (r << 11) | (g << 5) | b;
                row += SW;
            }
        }
        break;
    }
};

Github Repository: https://github.com/GooseyMcGoosington/Scotch-Engine-C

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments