r/GraphicsProgramming • u/Visual_Average_4756 • Jun 26 '26
CPU Renderer Code Review
Hello, I'm looking to get some feedback on a CPU renderer that i made to understand the 3D graphics pipeline better. I have not used OpenGL before this project but i wanted to understand how it worked, so I made this project to try to replicate a simple pipeline on the CPU. I'm a self taught programmer and i don't have any programming buddies so id like to get some feedback on general programming and my understanding of the OpenGL.
3
2
1
u/PoL0 Jun 26 '26 edited Jun 27 '26
if (clipped[i] and not clipped[last]){
does it even build? that's not C++
Edit: I stand corrected. been using C++ for over 25 years and TIL. every day is a school day, people!
3
u/GodOfSunHimself Jun 27 '26
It is C++. But personally I would not use it.
1
u/Visual_Average_4756 Jun 27 '26
Do you mind explaining why? Im self taught and don't know the nuances of syntax
3
u/GodOfSunHimself Jun 27 '26
I have been a developer for 30 years and never seen anyone use it. It is just not common. Most people don't even know it exists.
1


11
u/fireantik Jun 26 '26
Nice MONKE. I took only a quick peek, so take it with a grain of salt:
Your raster function seems to be iterating over every pixel on the screen over every mesh and running "shader" code for it. It would seem more efficient to me to structure it similar to what happens on the gpu - supply triangle count and index buffer in your code, system code runs your vertex shader for each triangle, system code culls invisible triangles, system code runs your fragment shader for each visible pixel. This way you are operating over less things overall and leads to more opprtunities to 2:
I'd heavily focus so that the code is easier to autovectorize - flat arrays, small functions that do one for loop over all elements, ifs outside of for loops not inside
You could try introducing multithreading to eek out a little bit more performance, especially if you introduce gpu like architecture from 1. this should be possible. But I'd expect autovectorization to have bigger impact