Closed ptheywood closed 6 years ago
4.3 seems to be the best current option. It's the highest crap intel stuff like my laptop supports, and alot of new stuff was introduced at 4.3.
Only thing missing I'm aware of is named buffers which were introduced with 4.5. These may be more efficient that the older method of binding a buffer, then unbinding it around any methods that act on buffers, but replacing those at a later date should be rather painless.
I've created a branch 4.3compat
for removing deprecated stuff: https://github.com/Robadob/sdl_exp/commit/ffce97e3017760800290055c6a27ebcd852ca2c6
So far I've enabled EXIT_ON_ERROR, enabled 4.3 forward compatibility (so we get deprecation errors on windows too), wrapped all gl calls with GL_CALL()
(regex find-all did the trick, alot of stuff in comments or var names which also matched, so I may have missed 1 or two) and removed a handful of deprecated stuff (replaced some with printfs, to warn of their missing).
Current issues is glVertexAttribPointer()
giving GL_INVALID_OPERATION. Found GL forum thread saying this is caused by core 3.1+ profile required a VAO bound when vertexattrib ptr is used.
The general usecase of VAO's appears to be;
When you create VBOs,
//Create enable VAO
GLint m_VAO;
glGenVertexArrays(1, &m_VAO);
glBindVertexArray(m_VAO);
//Create & Setup VBOs (we do this once at creation, rather than everytime we use program)
glGenBuffers(1, vbo));
glBindBuffer(target, *vbo));
glBufferData(target, size, data, GL_STATIC_DRAW));
glEnableVertexAttribArray(this->positions.location);//ShaderCore::findAttribute();
glVertexAttribPointer(this->positions.location, this->positions.components, this->positions.componentType, GL_FALSE, this->positions.stride, static_cast<char *>(nullptr) + this->positions.offset
//Repeat glVertexAttribPointer() for normals/colors/texcoords
GL_CALL(glBindBuffer(target, 0));
//Repeat for our faces vbo
//Set face array
GL_CALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, faces.vbo));
glBindVertexArray(0);
//This tells us the attribLocation required for binding array
std::pair<int, GLenum> ShaderCore::findAttribute(const char *attributeName, const int shaderProgram)
{
int attribLocation = shaderProgram<0 ? -1 : GL_CALL(glGetAttribLocation(shaderProgram, attributeName));
//attribLocation != attribIndex (Index required to get info, Location required to set val)
GLuint attribIndex = shaderProgram<0 ? -1 : GL_CALL(glGetProgramResourceIndex(shaderProgram, GL_PROGRAM_INPUT, attributeName));
if (attribLocation>-1 && attribIndex != GL_INVALID_INDEX)
{
GLenum type;
GLint size;//Collect size, because its not documented that you can pass 0
GL_CALL(glGetActiveAttrib(shaderProgram, attribIndex, 0, nullptr, &size, &type, nullptr));
return std::pair<int, GLenum>(attribLocation, type);
}
return std::pair<int, GLenum>(-1, 0);
}
Then at render, we simply rebind the vao
glUseProgram(m_program);
glBindVertexArray(m_VAO);
//any dynamic bindings (uniforms/textures[tex shouldn't be dynamic, but current implementation doesn't keep them stable, so other shaders can overwrite a tex]
//doRender
GL_CALL(glDrawElements(GL_TRIANGLES, faces.count * faces.components, GL_UNSIGNED_INT, 0));
glBindVertexArray(0);
glUseProgram(0);
This will be a great change, means we can bind a model to a shader by passing a single VAO, rather than the complicated VertexAttrib
structs we currently pass.
Will be worth changing shaders to make use of glBindAttribLocation()
to lock our common attribs to specific locations. Limit on 1080gtx is 16 vertex attribs, that should leave us room to reserve vertex, color, normal, texcoord with 12 to spare for generics
There's a full tutorial that covers VAO usage here.
Feel free to do work in this branch, I've got alot of other branches unfinished, so this isn't a high priority.
I've managed to get the branch 4.3compat working, it's not the cleanest of code (a few basic features [axis] simply removed).
I'm working on gradually moving master over to proper 4.3 compatibility, remaining tasks:
Looking at a class like that below for creating raw models under VAOs, due to the complexity of construction.
Still stuck on the best way to handle generic attrib;
/**
* This class facilitates the construction of Model objects from raw vertex data
* Call the relevant setTYPEAttribData() and addGenericAttribData() methods, providing all desired attributes
* Once attributes have all been set call make_shared() or make_unique() to recieve a pointer to a RawModel
* @note This class will store a copy of passed attrib arrays for it's duration
* @note they will be deleted at destruction leaving only the copy in graphics memory
*/
class RawModelBuilder
{
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void setVertexAttribData(const glm::vec3 *vertices, unsigned int count, bool normalized=false);
void setVertexAttribData(const glm::vec4 *vertices, unsigned int count, bool normalized=false);
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void setNormalAttribData(const glm::vec3 *normals, unsigned int count, bool normalized=false);
void setNormalAttribData(const glm::vec4 *normals, unsigned int count, bool normalized=false);
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void setColorAttribData(const glm::vec3 *colors, unsigned int count, bool normalized=false);
void setColorAttribData(const glm::vec4 *colors, unsigned int count, bool normalized=false);
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void setTexCoordAttribData(const glm::vec2 *texCoords, unsigned int count, bool normalized=false);
void setTexCoordAttribData(const glm::vec3 *texCoords, unsigned int count, bool normalized=false);
void setTexCoordAttribData(const glm::vec4 *texCoords, unsigned int count, bool normalized=false);
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void addGenericAttribData(const char* attribName, float *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, glm::vec2 *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, glm::vec3 *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, glm::vec4 *attribData, unsigned int count, bool normalized=false);
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void addGenericAttribData(const char* attribName, double *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, glm::dvec2 *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, glm::dvec3 *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, glm::dvec4 *attribData, unsigned int count, bool normalized=false);
void addGenericAttribData(const char* attribName, int *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, glm::ivec2 *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, glm::ivec3 *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, glm::ivec4 *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, unsigned int *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, glm::uvec2 *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, glm::uvec3 *attribData, unsigned int count);
void addGenericAttribData(const char* attribName, glm::uvec4 *attribData, unsigned int count);
/**
* @param @normalized Specifies whether the data should be normalised when accessed by the shader
*/
void addGenericAttribData(const char* attribName, void *attribData, unsigned int count, GLint components, GLenum type, bool normalized=false);
};
The version of assimp_clean_merge
on my machine now execute under GL 4.3 forward compatibility without error. There are some messy changes in Entity holding me back from fully committing this right now, but it should be in soon.
d3a31e3
If this isn't right the next large commit to the branch should solve it for the stock scenes.
Remove the fixed function pipeline commands and do not using deprecated / removed opengl commands , targetting a specific GL version (4.something)