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

  • SEARCH
  • Home
  • 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 7578411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:34+00:00 2026-05-30T17:25:34+00:00

I tend to wrap OpenGL objects in their own classes. In OpenGL there is

  • 0

I tend to wrap OpenGL objects in their own classes. In OpenGL there is the concept of binding, where you bind your object, do something with it and then unbind it. For example, a texture:

 glBindTexture(GL_TEXTURE_2D, TextureColorbufferName);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000);
 glBindTexture(GL_TEXTURE_2D, 0);

Wrapping this would be something like:

texture->bind();
    texture->setParameter(...);
    texture->setParameter(...);
texture->unBind();

The problem here, is that I want to avoid the bind() and unBind() functions, and instead just be able to call the set methods and the GLObject will be bound automaticly.

I could just do it in every method implementation:

public void Texture::setParameter(...)
{
    this.bind();
    // do something
    this.unBind();
}

Though then I have to do that for every added method! Is there a better way, so it is automatically done before and after every method added?

  • 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-30T17:25:35+00:00Added an answer on May 30, 2026 at 5:25 pm

    Maybe a context object may help here. Consider this small object:

    class TextureContext {
    public:
        TextureContext(char* texname) {
            glBindTexture(GL_TEXTURE_2D, texname);
        }
        ~TextureContext() {
            glBindTexture(GL_TEXTURE_2D, 0);
        }
    };
    

    This object is now used within a scope:

    {
        TextureContext mycont(textname);
        mytexture->setParameter(...);
        mytexture->setParameter(...);
        mytexture->setParameter(...);
    }
    

    the object mycont only lives in the scope and calls its destructor (ant the unbind method respectively) automatically once the scope is left.

    EDIT:

    Maybe you can adjust the TextureContext class to take your Texture instance instead in the constructor and retrieves the texture name itself before binding the texture.

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

Sidebar

Related Questions

I tend to use (or even overuse) double braces object intialization in GWT. For
Out of habit I tend to put classes/structs/enumerations in separate files when not nested.
In a SOA - environment there tend to be a lot of projects in
I'm asking because classes tend to be passed by reference, but I'm not sure
There exist static analysis tools for Python , but compile time checks tend to
I tend to write a class declaration in a source file and then decide
I tend to use If Not IsDBNull(dr(data)) Then myData = dr(data) End If to
I tend to do a lot of projects on short deadlines and with lots
I tend to get the feeling that most folks here think SVN is gold-plated
I tend to take the academic approach all too often and adhere to strict

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.