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 6883569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:23:57+00:00 2026-05-27T05:23:57+00:00

VC++ 2010, SDL, OpenGL, GLSL I am working on this class as a way

  • 0

VC++ 2010, SDL, OpenGL, GLSL

I am working on this class as a way to switch between shaders quick and easily. It seems to be working properly(functionality-wise), however the framerate drops severely after implementing it(from 60 to 40). Hopefully you guys can point me in the right direction.

Here is what I have so far:

namespace SL {

struct Shader_Manager {

    struct shader_vect {

        GLuint      shader_type;
        GLuint      shader_handle;
        char *      filename;
    };

    struct search_vect
    {
        std::string target;
        bool operator()(const shader_vect& vect) const
        {
            return vect.filename == target;
        }
    };

    GLuint          prog;
    std::vector     <shader_vect> shader_list;

    GLuint          vertex_shader;
    GLuint          fragment_shader;

    Shader_Manager() {

        prog = glCreateProgram();
    };

    ~Shader_Manager() {};

    void load(char * filename, int type) {

        shader_vect shader;

        shader.filename             = filename;
        shader.shader_type          = type;

        shader.shader_handle        = glCreateShader(type);
        char * fs                   = textFileRead(filename);

        const char * vv = fs;
        glShaderSource(shader.shader_handle, 1, &vv, NULL);

        free(fs);
        glCompileShader(shader.shader_handle);

        shader_list.push_back(shader);
    }

    void use(char * filename) {

        search_vect search;
        search.target = filename;

        std::vector<shader_vect>::iterator it = 
                std::find_if(shader_list.begin(), shader_list.end(), search);

        glAttachShader(prog, it->shader_handle);

        glLinkProgram(prog);
        glUseProgram(prog);
    }

    void end() {

        glLinkProgram(0);
        glUseProgram(0);
    }
};
} // namespace SL

inside my main function I use it like such:

SL::Shader_Manager SLManager;
SLManager.load("shader.frag", GL_FRAGMENT_SHADER);

and withing the game loop I am doing:

SLManager.use("shader.frag");
  makeSphere();
SLManager.end();

Am I not properly free’ing up some resources? Any help would be appreciated, thanks!

  • 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-27T05:23:58+00:00Added an answer on May 27, 2026 at 5:23 am

    Linking a program every time you switch is a mistake. You should create as many programs as you need, all shader objects and then link everything that you will need. Then just call glUseProgram on a switch (possibly have a debug mode that calls glGet(GL_CURRENT_PROGRAM) and alerts for unnecessary switches, because those are, essentially, bugs.

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

Sidebar

Related Questions

VC++ 2010, OpenGL, GLSL, SDL I am moving over to shaders, and have run
VC++ 2010, OpenGL, GLSL, SDL So I am having two major problems. I am
VS 2010 is reporting this warning Value cannot be null. However, the project seems
I'm working on some cross-platform code using OpenGL and SDL, but have immediately run
2010-06-14 02:21:49+0400 or 2010-06-14 02:21:49-0400 is there a way to convert this string to
Visual Studio 2010 allows toggling the Intellisense mode between the completion mode and the
I'm trying to create an SDL game with Visual Studio 2010, but I'm getting
While installing Visual Studio 2010 Service Pack 1, I am getting this error: Installation
For some reason I can't compile this program because I'm supposedly missing SDL. It
VB.NET 2010, .NET 4 This might be a dumb question but I'm wondering what

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.