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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:35:45+00:00 2026-05-29T17:35:45+00:00

I have an existing WebGL renderer (too much code to be useful to share)

  • 0

I have an existing WebGL renderer (too much code to be useful to share) which used to be very simple: it only had one vertex shader, one fragment shader, and one shader program with both. It was for rendering quads.

I’m trying to extend it to have a second shader program it switches to and from, for rendering point sprites. It has its own vertex attribute array, and a second vertex shader, fragment shader and shader program.

I can’t seem to switch between the two properly: I keep getting display glitches, randomly disappearing objects and such. Here’s the two functions I have to switch between them. Any idea what I’m missing?

GLWrapProto.switchQuadProgram = function ()
{
    var gl = this.gl;

    gl.useProgram(this.shaderProgramPoint);

    gl.disableVertexAttribArray(this.locAPosPoint);

    gl.useProgram(this.shaderProgram);

    gl.enableVertexAttribArray(this.locAPos);
    gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
    gl.vertexAttribPointer(this.locAPos, 2, gl.FLOAT, false, 0, 0);

    gl.enableVertexAttribArray(this.locATex);
    gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
    gl.vertexAttribPointer(this.locATex, 2, gl.FLOAT, false, 0, 0);
};

GLWrapProto.switchPointProgram = function ()
{
    var gl = this.gl;

    gl.useProgram(this.shaderProgram);

    gl.disableVertexAttribArray(this.locAPos);
    gl.disableVertexAttribArray(this.locATex);

    gl.useProgram(this.shaderProgramPoint);

    gl.enableVertexAttribArray(this.locAPosPoint);
    gl.bindBuffer(gl.ARRAY_BUFFER, this.pointBuffer);
    gl.vertexAttribPointer(this.locAPosPoint, 4, gl.FLOAT, false, 0, 0);
};
  • 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-29T17:35:46+00:00Added an answer on May 29, 2026 at 5:35 pm

    It’s going to be difficult to tell what the problem is from that piece of code, but let me throw some suggestions out there to try and help you find the problem.

    First off, you don’t need to worry too much about doing disableVertexAttribArray every time you switch shaders. The enabled/disabled arrays are state that is associated with the shader, and as such changing the bound program invalidates your previously enabled arrays anyway.

    (Actually, does anyone know of a decent citation for that, I was trying to find one and can’t at the moment.)

    With that in mind you could simplify your above code to:

    GLWrapProto.switchQuadProgram = function ()
    {
        var gl = this.gl;
    
        gl.useProgram(this.shaderProgram);
    
        gl.enableVertexAttribArray(this.locAPos);
        gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
        gl.vertexAttribPointer(this.locAPos, 2, gl.FLOAT, false, 0, 0);
    
        gl.enableVertexAttribArray(this.locATex);
        gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
        gl.vertexAttribPointer(this.locATex, 2, gl.FLOAT, false, 0, 0);
    };
    
    GLWrapProto.switchPointProgram = function ()
    {
        var gl = this.gl;
    
        gl.useProgram(this.shaderProgramPoint);
    
        gl.enableVertexAttribArray(this.locAPosPoint);
        gl.bindBuffer(gl.ARRAY_BUFFER, this.pointBuffer);
        gl.vertexAttribPointer(this.locAPosPoint, 4, gl.FLOAT, false, 0, 0);
    };
    

    I’m curious about the issue that you mentioned with “display glitches”, though. I can’t think of any reason why switching shaders would cause objects to randomly stop and start rendering. Try rendering only the geometry using one shader first, then switch and render only geometry that uses the other. If either of them have the issue then you know it’s not the shader switching that is causing your problem. If the problem only appears when rendering both sets of geometry together, there may be some error in the state management between the two.

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

Sidebar

Related Questions

I have existing client code wherein sql data reader is being used to pull
I have existing code that uses CMNewProfileSearch to find then iterate over the color
I have existing Linux shared object file (shared library) which has been stripped. I
I have existing java code and need to create Design Document based on that.
I have existing websites with PHP/MySQL framework. They are very busy and chat, events,
I have an existing app in which I made the mistake of using String.GetHashCode
I am new to MongoDb but have an existing application which would benefit heavily
Have an existing C# .NET code base that is currently coded to directly access
I'm trying to optimize and existing piece of WebGl JavaScript code, and the bottleneck
I have: existing object oriented native code API (non GUI) GUI application that works

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.