Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6815505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:48:56+00:00 2026-05-26T20:48:56+00:00

I’m pretty new to C++ and am writing a cross-platform (desktop/mobile) 2D game engine…

  • 0

I’m pretty new to C++ and am writing a cross-platform (desktop/mobile) 2D game engine… my question is, am I using singletons in an appropriate manner and if not, is there an alternative?

Basically I have a few components to my engine which are built around a singleton object. Examples:

VBOManager (Singleton)
This “manager” is basically responsible for allocating and of course, “managing” vbo’s that are used to store texture mapping and vertex coordinates. I control “read/write” through this object so I can cache data written to the vbo by other objects and return pointers (avoiding storing duplicate data like 500 sprites with the same mapping and vertex coordinates).

TextureManager (Singleton, self explanatory)

GLUtils (Singleton)
I pretty much use this for unifying common GL calls which are different based on the current platform, like GL or GLES. Example, GLU functions (libglu isn’t on android so I have a custom implementation)

Graphics (Singleton)
Used to handle things like window initialization and resizing, global framerate management, viewport initialization etc.

InputManager (Singleton, self explanatory)

Anyway so here I am reviewing all of this and I’m starting to feel really, really dirty. I do feel that given the requirements and functionality of the given objects, it’s justified. But on the other hand I’m a newbie and something just doesn’t feel right about having this “pattern” so rampant throughout my code. If the latter is indeed the case, what might be an alternative?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:48:57+00:00Added an answer on May 26, 2026 at 8:48 pm

    Before I begin, I want to make to clear what we’re talking about so that we’re all on the same page. A Singleton is:

    1. “an object,” This means that it has certain internal state, which is encapsulated from direct external access. It has a lifetime: it is created at some point in the program’s execution, and it is destroyed at some later point.
    2. “of which no more than one instance can be created,” This means that there is some explicit machinery in place that forcibly prevents creating multiple instances. The constructor and destructor will be called no more than once in the program’s execution.
    3. “which is globally accessible.” The instance, once created, is accessed either via a global function call or a public static member of a class.

    A global object is not a singleton; it is simply a global object. If it is possible to make more than one, it is not a singleton.

    Now that the definitions are out of the way:

    VBOManager (Singleton)

    I cannot imagine how this object works in any way that makes sense. Buffer objects are, in terms of OpenGL, free-standing constructs. They have no relation to one another. So I don’t understand why you would need a manager that handles all of them.

    I can understand having a specialized wrapper buffer object class for dealing with streaming buffer objects. There are several ways to do streaming, and some are more performing than others. So it makes sense to wrap that in an object.

    But to have a global buffer object manager does not make sense. Buffer objects should be independent of one another. Or if anything, they should be dependent on other objects like Meshes (multiple mesh objects can reference the same buffer(s)). But you shouldn’t need to have a global buffer object manager.

    I can understand having a repository of named objects from which you can add and retrieve. But I don’t understand the need to have it for specific object types like this. And the need for it to be a global singleton is… dubious.

    I find that singletons are best for concepts that are fundamentally unique. There is one filesystem, and therefore it makes sense to have a global filesystem. OpenGL itself is global (owing to its C-based nature), though even then, it is possible to switch rendering contexts. If it ever makes sense to have two of something, then a singleton probably isn’t the best way to go.

    Even if you are only using a single buffer object, and have a manager for it, there is no need to make this class a singleton. You can make it a global if you like, but there is no need to forcibly prevent users from creating more than one instance of this class. If later, you want to have multiple buffer object managers (and possibly pay the performance price), so be it.

    GLUtils (Singleton)

    Why is this an object? The Singleton pattern refers to an object that there can only ever be a single instance of at any one time. Utility functions are simply global functions.

    C++ is not Java. You don’t have to put everything in a class. Global functions are not bad design. Indeed, they are good design, where appropriate. If a function doesn’t need to access any state (outside of its parameters and any other functions it might call), then there is no need for it to be part of an object.

    Graphics (Singleton)

    This is something for which one can argue that a Singleton makes sense. It is a living object with state. And you explicitly do not want more than one in your application.

    However, consider this. Is it so wrong to have more than one? How often would you be passing around this Graphics object? How much code needs to work at the level of the Graphics object? I’m guessing not a lot. Some basic initialization code, and that’s it.

    So while it is defensible, it isn’t necessary. It’s not a concept that requires being a Singleton. Plus, by being able to have more than one, you can delete it at any time and create a new one. This allows your application to be able to reconstruct the window more easily.

    The one flaw with this is the possibility of having two Graphics objects at once. And that involves dealing with OpenGL contexts. Since an OpenGL context is global state, having multiple Graphics objects could cause problems, since both would have their own contexts. You would need some way to set a particular Graphics object as the current one, which would bind itself as the current OpenGL context (and retrieve any function pointers it needs to).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.