Need a design advice on a Mesh Class

Started by
11 comments, last by L. Spiro 10 years, 3 months ago

You are getting closer, but one of the things I wanted to say that I didn’t have time to say before is in regards to passing an OpenGL context around all the time.

Are you going to call ::wglMakeCurrent() (or similar) on every single OpenGL call? That is the only reason the vertex buffer would need you to pass a context into it; it is the only relevant function that can be called related to the context. If that is how you want to emulate object-oriented programming, you would be calling ::wglMakeCurrent() for every single call, including ::glEnable() etc.

Why do you need more than one context anyway? Even if you have multiple “renderer” instances a single context is enough. You don’t need more than one context to do object-oriented OpenGL programming, and even if you did the object you would be passing around would be some kind of more-generalized class such as “Renderer” or something above and beyond “ContextGL”.


L. Spiro

All my Wrappers for OpenGL Objects (Shaders, Textures, VB, IB) lives in the Context, and these objects manage the lifetime by themselves but the ContextGL that delete them. When the context creates a VBO, it puts the vbo in a std::vector<VertexBuffer*> for delete them when gets destroyed.

One thing that I didn't said is that the ContextGL was doing the Rendering stuff (but it's just temporary since the "Single Responsability Principle" it's a must).

Okay... What I've undestand from your perspective is that (since my context was doing the rendering job) the context is a Renderer and inside the Renderer is where the Wrapped Objects lives.

Advertisement

Here is my code with the correction:


class RendererGL {
public:
	RendererGL();
	~RendererGL();

	void SetViewport(int x, int y, int w, int h);

	void CreateTexture(Texture2D** texture);
	void CreateVertexBuffer(const ArrayInfo& ainfo, const std::vector<VertexInfo>& vinfo, VertexBuffer** buffer);
	void CreateIndexBuffer(const std::vector<unsigned int>& index, IndexBuffer** buffer);
	void CreateShader(Shader** shader);
	void CreateProgram(const std::vector<Shader>& shader, ShaderProgram** program);

	void RenderBuffers(VertexBuffer* vbuffer, IndexBuffer* ibuffer);
//private: //tmp
	ShaderProgram* program;
  
	std::map<std::string, Texture2D> texture;	
	std::map<std::string, Shader> shader;
        //more objects
};
If there is a need for textures to be managed, they should be managed by a class designed to manage textures.
Same goes for shaders. I don’t know what you are doing here but your maps look like primitive managers.

Even if managers are associated with the renderer instance, they should still be separate classes that are members of the renderer. Keep their implementations separate and modular.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement