softwareRenderer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef SRENDERER_H
  2. #define SRENDERER_H
  3. #include "rasterizer.h"
  4. #include "buffer.h"
  5. #include "model.h"
  6. #include "camera.h"
  7. #include "light.h"
  8. class SoftwareRenderer {
  9. public:
  10. //Dummy Constructor / Destructor
  11. SoftwareRenderer();
  12. ~SoftwareRenderer();
  13. //Creates all buffers and preps everything for for rendering
  14. bool startUp(int w, int h);
  15. void shutDown();
  16. //Overview:
  17. //01.-Gets pointers to render data form mesh
  18. //02.-Builds MVP
  19. //03.-Iterates through all triangle faces
  20. //04.-Runs backface culling algo
  21. //05.-Applies vertex shader per vertex
  22. //06.-Performs clipping of triangles outside frustrum
  23. //07.-Applies perspective divide
  24. //08.-Sends to triangle rasterizer
  25. //09.-NDC -> viewport transform
  26. //10.-Iterates through triangle bounding box
  27. //11.-Calculates barycentric coordinates
  28. //12.-Culls pixels outside of triangle or screen
  29. //13.-Runs fragment shader
  30. //14.-zBuffer update
  31. //15.-Writes to frame buffer
  32. //16.-Swap buffer
  33. void drawTriangularMesh(Model * currentModel);
  34. void clearBuffers();
  35. //Returns pixel buffer
  36. Buffer<Uint32>* getRenderTarget();
  37. void setCameraToRenderFrom(Camera * camera);
  38. void setSceneLights(BaseLight * lights, int numLights);
  39. private:
  40. //Buffer methods
  41. bool createBuffers(int w, int h);
  42. //Primitive level methods
  43. void buildTri(Vector3i &f, Vector3f *trianglePrim, std::vector<Vector3f> &vals);
  44. void perspectiveDivide(Vector3f *clippedVertices);
  45. //Culling and clipping methods
  46. bool backFaceCulling(Vector3f &facetNormal, Vector3f &vertex, Matrix4 &worldToObject);
  47. bool clipTriangles(Vector3f *clipSpaceVertices);
  48. //Pointer to the scene's target camera
  49. Camera * mCamera;
  50. bool startUpComplete = false;
  51. //Pointer to structs containing all the light info
  52. int mNumLights;
  53. BaseLight *mLights;
  54. Buffer<float> * zBuffer;
  55. Buffer<Uint32> * pixelBuffer;
  56. };
  57. #endif