NablaZeroLabs / mxd

Space Mission Design Support Tools
MIT License
4 stars 4 forks source link

Add ID containers for shader and program; add shader and program tests #20

Closed fayalalebrun closed 5 years ago

fayalalebrun commented 5 years ago

I was having trouble getting programs to link, and the issue lies in Shader copies prematurely deleting the OpenGL Shader object when their destructor was called. To avoid this problem in the future, it is necessary to disable copying of these classes.

I also fixed a minor issue where the wrong OpenGL function was called to get the Program compilation errors.

fayalalebrun commented 5 years ago

I changed the Program class to receive its shader vector by reference, to avoid copying of shaders.

Now, I am trying to find a way to use the shaders in vectors, with the copy operation disabled. I am attempting to implement a move constructor for the shader class in order to fix this. However, since the id of the shader is defined as const, this is proving to be difficult. Perhaps if there was a way to disable the constructor of the other object, but I cannot find one as of now.

fayalalebrun commented 5 years ago

I've implemented the move functions for the Shader class. However, to do this I had to remove the const attribute of some of its variables, as I must set the OpenGL pointer to 0 whenever a Shader object is moved.

It should be functional as of now, however.

fayalalebrun commented 5 years ago

I restored the copy operators for both the program and shader, and instead decided to implement a container which holds the id of the OpenGL objects. These classes hold a smart pointer to the id container, and when the smart pointer reference count decreases to 0, the container destructor is called and the OpenGL object is deleted.

fayalalebrun commented 5 years ago

I've added tests for the shader copy operator and constructor. In them, I check if the values of a shader have been correctly copied. I would also like to check if the OpenGL objects are correctly deleted, but I am unsure of how to achieve this, although I have tested this manually.

fayalalebrun commented 5 years ago

I've added tests for the program class, which are functionally very similar to the ones used for the Shader class.

fayalalebrun commented 5 years ago

I've added what is necessary in order to find shader uniforms, attempting to save the time it takes OpenGL to find a uniform by using a map of strings and ints, which stores known uniform locations, thus eliminating the need to use glGetUniformLocation more than once per uniform.