New batch renderer#2
Conversation
textures and shader can now be created context independently.
used for screenshots and resizing currently
the name will soon be used for wrapping shader variables
| void GlShaderProgram::use() const { | ||
| glUseProgram(*this->handle); | ||
|
|
||
| for (auto const &pair : this->textures_per_texunits) { |
There was a problem hiding this comment.
I made a new system for managing textures which can be found in texturemanager.cpp. So this was not compatible with it. But this can be added back and a workaround can be found. I thought the system for managing various textures and texture units was a little too closed for optimisation.
There was a problem hiding this comment.
Ok, i'll look at that - if it's indeed better, there's no need to revert back to the old code.
| std::unique_ptr<UniformInput> GlShaderProgram::new_unif_in() { | ||
| auto in = std::make_unique<GlUniformInput>(); | ||
|
|
||
| void GlShaderProgram::send_uniform(const GlUniformInput *unif_in) { |
There was a problem hiding this comment.
This is already done in execute_with.
There was a problem hiding this comment.
Yes this is effectively the same program but without the sampler2d stuff as that is being handled by texturemanager.cpp
| namespace renderer { | ||
| namespace opengl { | ||
|
|
||
| GlIndexBuffer::GlIndexBuffer(size_t size, GLenum usage) |
There was a problem hiding this comment.
This looks like effectively the same code as for GlBuffer, so we could add an enum for the buffer type there and remove this class.
There was a problem hiding this comment.
That would be a better idea
|
|
||
| bool has_uniform(const char*) override; | ||
|
|
||
| int texture_array(); |
There was a problem hiding this comment.
What do these functions do? There is no explanation (add comments please).
There was a problem hiding this comment.
The texture_array() function basically sets the uniforms of the textures in the shader. Its a little implementation specific right now, but we can abstract it. the main reason here is that I do not have to pass in texture objects to the shader to bind them. They are bound by their own bind() method.
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
|
|
||
| glBindTexture(GL_TEXTURE_2D, 0); |
There was a problem hiding this comment.
This is unnecessary - we don't care which texture is bound as long as we always remember to bind ones we want to use when we need them. Having them bound while they're not being used does not hurt.
There was a problem hiding this comment.
I just thought it was a good practice and does not affect performance.
There was a problem hiding this comment.
While I can't find a source for this right now, redundant state changes like this can be bad. A single one in the constructor is not important, but as a general rule it's better to avoid them.
There was a problem hiding this comment.
Sure. This does not affect the program in anyway
| class GlTextureArray final : public GlSimpleObject { | ||
| public: | ||
| /// Constructs a texture and fills it with the given data. | ||
| GlTextureArray(const resources::TextureData&); |
There was a problem hiding this comment.
Should the parameter not be a vector<TextureData> instead? Since there's multiple of them.
There was a problem hiding this comment.
I have since written a better version of this. which includes a different constructor and a better way to send in TextureData with the submit_texture() method. Will commit that soon.
| float v; | ||
| }; | ||
|
|
||
| class VertexRenderer{ |
There was a problem hiding this comment.
What does this class do? Again no explanation 😢
There was a problem hiding this comment.
this is just a test class. Was trying out different types of rendering such as static draw and such.
There was a problem hiding this comment.
Ok, if it's a test class then presumably we won't need to include it in the final code, so there's no need to spend time commenting it.
Vtec234
left a comment
There was a problem hiding this comment.
Hey, first of all thank you for spending time working on this! It's a lot of changes, so will take me some time. In general, I like the texture array and batching additions, but maybe we can figure out a way to integrate them better with the backend-independent renderer abstraction, and make the default Renderer batching by default, removing the need for a separate BatchRenderer.
Like we discussed, removing RVO2 would make this a bit easier to review in the web interface 😅 Additionally, could you please run this through some code formatter conformant with the SFTTech code standards?
| glBufferData(GL_ARRAY_BUFFER, size, 0, usage); | ||
| } | ||
|
|
||
| GlBuffer::GlBuffer(const float *data, size_t size, GLenum usage) |
There was a problem hiding this comment.
This constructor seems unnecessary, since we can just cast float* to uint8_t*. The meaning of uint8_t is not necessarily that it has to be usable as unsigned ints, but rather just that it's some number of bytes.
There was a problem hiding this comment.
Sure. That constructor again is not being used anyway. Lots of testing code left off. I'll remove that as wwel
| glBindBuffer(target, *this->handle); | ||
| } | ||
|
|
||
| void GlBuffer::unbind(GLenum target) const { |
There was a problem hiding this comment.
Like for the texture, unbinding is not necessary.
There was a problem hiding this comment.
A method for doing it wouldn't hurt☺
There was a problem hiding this comment.
For maintainability, it's better to have less than more code, so if something is unused, better to remove it.
| in float a_id; | ||
| uniform vec2 mouse_pos = vec2(0.0,0.0); | ||
|
|
||
| uniform sampler2D texture_0; |
There was a problem hiding this comment.
To avoid this horrible duplication, a sampler2DArray would serve well.
cec2431 to
f0f6993
Compare
This includes a lot of modifications to the original code which is entirely unnecessary at this point. We have to revert them to their original state. Most of them are converting from the original unique pointers to shared pointers.
Support for texture arrays, index buffers, batch rendering has been added.