A downloadable project

DOWNLOAD FILES 

This week we are building an interface for non-engine designer programmers to utilize our graphics engine. To do this, I built a data structure and class with engine functions that gives a user a nice interface to load data into render frame. To pass that data in, we use two separate threads that have the jobs of reading and writing. These are represented by s_dataBeingSubmittedByApplicationThread and s_databeingRenderedByRenderThread, while data is being “submitted” by my game, the other is asynchronous “rendering”. 

We also implemented Reference Counting to keep track of objects without the possibility of the game engineer deleting data while it was being used. To do this, we pass a pointer of our cEffect and cMesh graphics classes into a static factory or load function to keep track of and increment the reference of that object. If the reference of an object reaches 0, this signifies that an object is safe to destroy, and will be done automatically. 

Controls:

  • Hold “Enter”: draw one mesh
  • Hold “Spacebar”: draw mesh with different effect 

Interfaces:

These are the interfaces to submit data into the graphics engine. 

SubmitCearColor takes a pointer to a custom struct holding the 4 float values RGBA. 

SubitDrawData is a bit more interesting, I made a custom class that holds a custom array of effect and mesh pair data. The reason for using a class was that I could give some helper methods to add, get size, and index new data from the user. 

This is an example of a user Adding a new pair of effect and mesh data to the “List” 

sizeof()

Direct3D

Breakdown of data:

  • cMesh x2 = 80 bytes (2 objects in the world)
  • cEffect x2 = 240 bytes. I’m not sure how one cEffect could possibly have 240 bytes with 2 pointers, render state, and 2 strings. I could definitely remove the strings at a later date, but for now they help me keep my current effect state for key input switching.
  • sRGBAColor: 4 floats = 16 bytes
  • DrawData: stored in myGame, but pointers are used to pull the data into graphics to build effects and meshes
    • 2 strings: length * sizeof(char) also contains pointers
    • 1 vertex array (pointer): 3 floats * length (4) * 2
    • 2 uint16_t: 2 bytes
    • 1 uint16_t array: 2 bytes * length (6) * 2

OpenGL

Breakdown of data:

  • cMesh x2 = 40 bytes 
  • cEffect x2 = 136 bytes
  • sRGBAColor: 4 floats = 16 bytes
  • DrawData: The decrease is due to pointer sizes going from 8 bytes to 4 bytes.

 

Size differences in Open GL and Direct3D are due to their configurations, x64 and x86. When building our platform specific classes, we separated our member variables in their respective platforms. An example of the size change would be in cMesh, where we go from 3 pointers (d3d) 8 bytes each to 3 GLuints (OpenGL) 4 bytes each. There is also another pointer for reference counting in that class, making the 40 byte to 20 byte change. I ended up budgeting 512 bytes (nice power of 2) of memory since my calculations were floating around 300-400 bytes being used in graphics. 

My program gives assert errors and logs in debug mode, while in release mode it just outputs a log and continues running normally. 

A change I tried to explore was loading meshes and effects before sending over the data, but I ran into circular dependency issues. Specifically when I tried to reference any bit of the mesh and effect header files. This was due to them needing to include context.h that was also being included in graphics.h that we were pulling the submitting data functions from. If I can figure out this change, this would reduce the amount of pointers I need to keep track of my data. 

Download

Download
Chai_Assignment4.zip 428 kB

Leave a comment

Log in with itch.io to leave a comment.