Skip to content

New batch renderer#2

Open
surajhanchinal wants to merge 96 commits into
Vtec234:new-rendererfrom
surajhanchinal:new-renderer
Open

New batch renderer#2
surajhanchinal wants to merge 96 commits into
Vtec234:new-rendererfrom
surajhanchinal:new-renderer

Conversation

@surajhanchinal

Copy link
Copy Markdown

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.

TheJJ and others added 30 commits November 12, 2017 13:38
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) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done in execute_with.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a better idea


bool has_uniform(const char*) override;

int texture_array();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these functions do? There is no explanation (add comments please).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought it was a good practice and does not affect performance.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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&);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the parameter not be a vector<TextureData> instead? Since there's multiple of them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this class do? Again no explanation 😢

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a test class. Was trying out different types of rendering such as static draw and such.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Vtec234 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like for the texture, unbinding is not necessary.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A method for doing it wouldn't hurt☺

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid this horrible duplication, a sampler2DArray would serve well.

@Vtec234 Vtec234 force-pushed the new-renderer branch 3 times, most recently from cec2431 to f0f6993 Compare July 22, 2018 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants