Link

Rendering Manager Architecture

The Rendering Manager in the Untold Engine is represented as U4DRenderManager. It provides pointers to several objects such as Metal Device, Pipeline States, Pipeline Descriptors, Metal Libraries (i.e. Vertex and Fragment programs), attribute buffers, etc.

    class U4DRenderManager {
        
    private:
        
    protected:
        
	//Pointer representing a Metal Device
	id <MTLDevice> mtlDevice;

	//Pointer representing the state of the render pipeline
	id<MTLRenderPipelineState> mtlRenderPipelineState;

	//Pointer for the rendering pipeline descriptor
	MTLRenderPipelineDescriptor *mtlRenderPipelineDescriptor;

	 // Pointer that holds the library of shaders
	id<MTLLibrary> mtlLibrary;
        
    public:
        
	//Sends attributes information to the GPU
	void loadRenderingInformation();

	//Renders the current entity
	virtual void render(id <MTLRenderCommandEncoder> uRenderEncoder){};

	//Renders the shadow for a 3D entity
	virtual void renderShadow(id <MTLRenderCommandEncoder> uRenderShadowEncoder, id<MTLTexture> uShadowTexture){};

	//It initializes the vertex and fragment shaders for the entity
	virtual void initMTLRenderLibrary(){};
        
 	//It prepares the rendering descriptor with the appropriate color attachment, depth attachment, shaders and attributes    
	virtual void initMTLRenderPipeline(){};

	//...More Methods here...
        
    };

The U4DRenderManager class leaves the implementation of most methods to its concrete subclasses. For example, the loadRenderingInformation() method provides a sequence of which method to call, but these methods are all declared as virtual. It is up to the the concrete subclasses to define these methods.

void U4DRenderManager::loadRenderingInformation(){
        
	initMTLRenderLibrary();

	initMTLRenderPipeline();

	if(loadMTLBuffer()){
	    
	    loadMTLTexture();
	    
	    //loads additional information such as normal map, bones, etc if it exists.
	    loadMTLAdditionalInformation();
	    
	    //clear all model attribute data
	    clearModelAttributeData();
	    
	}
        
}

3D Model Rendering

The subclass responsible for rendering 3D models is given to U4DRender3DModel. It is in charge of properly initializing the attribute data required by the GPU, setting up the GPU shaders, Pipelines and rendering the 3D model. The U4DRender3DModel inherits its behaviors from the U4DRenderManager and as shown in the declaration, it contains a pointer to the 3D model entity it will manage.

[image here]

class U4DRender3DModel:public U4DRenderManager {
        
    private:
        
	//The 3D model pointer the class will manage
	U4DModel *u4dObject;
        
    public:
        
	//Constructor for class. It initializes the buffers and textures used for rendering
	U4DRender3DModel(U4DModel *uU4DModel);

	//class destructor. It releases the bone buffer, shadow buffer and sampler descriptor.
	~U4DRender3DModel();

	//It initializes the vertex and fragment shaders for the entity
	void initMTLRenderLibrary();

	//It prepares the rendering descriptor with the appropriate color attachment, depth attachment, shaders and attributes
	void initMTLRenderPipeline();

	//Renders the current entity
	void render(id <MTLRenderCommandEncoder> uRenderEncoder);

	//...More Methods here...
}