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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:24:56+00:00 2026-06-12T23:24:56+00:00

Frag shader: out vec4 Color; uniform samplerBuffer sampler; uniform int index; void main() {

  • 0

Frag shader:

out vec4 Color;
uniform samplerBuffer sampler;
uniform int index;
void main() 
{
   Color=normalize(texelFetch(sampler,index));

}

I am using glTexBuffer() for texturing for all the internal formats given at http://www.opengl.org/sdk/docs/man3/xhtml/glTexBuffer.xml. Above shader works only for ubyte, ushort normalised types and float, halffloat unnormalised types. For the rest of the internal formats, it does not apply texture on geometry.

What do I need to change to give me the desired effect?

code

GLbyte arr[]={124,5,126};
glGenBuffers(1,&bufferid);

glBindBuffer(GL_TEXTURE_BUFFER,bufferid);

glBufferData(GL_TEXTURE_BUFFER,sizeof(arr),arr,GL_STATIC_DRAW);


glGenTextures(1, &buffer_texture);   

glBindTexture(GL_TEXTURE_BUFFER, buffer_texture);
glTexBuffer(GL_TEXTURE_BUFFER, GL_R8I, bufferid);

glUniform1i(glGetUniformLocation(shader_data.psId,"sampler"),0);
glUniform1i(glGetUniformLocation(shader_data.psId,"index"),0);

glGenBuffers(1,&bufferid1);

glBindBuffer(GL_ARRAY_BUFFER,bufferid1);
glBufferData(GL_ARRAY_BUFFER,sizeof(vertices4),vertices4,GL_STATIC_DRAW);

attr_vertex = glGetAttribLocation(shader_data.psId, "a_position");

glVertexAttribPointer(attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);

glEnableVertexAttribArray(attr_vertex);

glDrawArrays(GL_TRIANGLE_FAN,0,4);

glUniform1i(glGetUniformLocation(shader_data.psId,"index"),1);

glVertexAttribPointer(attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0,(void *)(32) );

glDrawArrays(GL_TRIANGLE_FAN,0,4);

glUniform1i(glGetUniformLocation(shader_data.psId,"index"),2);

glVertexAttribPointer(attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0,(void *)(64) );

glDrawArrays(GL_TRIANGLE_FAN,0,4);

I have to apply texture using all the internal formats.

  • 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-06-12T23:24:57+00:00Added an answer on June 12, 2026 at 11:24 pm

    If the “desired effect” is to have a single shader which can work with any format of image data, then there’s no way to do it. Or at least, no simple way.

    You could have three different samplers, bound to three different texture image units, corresponding to the three different possible formats (float, signed-int, unsigned-int). You create 3 different buffer textures (using the same buffer), and bind the appropriate texture to appropriate sampler for the kind of data you want the shader to use. Then you pass a uniform that defines which sampler should be used.

    But other than conditional logic like that, no. The sampler’s type is used to determine how to interpret the data given to the shader, and it must match with the texture’s format.

    In general, a shader is designed to expect certain specific data, not any old arbitrary thing that the client code wants to hurl at it. A shader that pulls floats out of a texture doesn’t care if it’s normalized-integers or 16-bit floats, or R11F_G11F_B10F or whatever; the shader just wants floats. It’s not appropriate to shove images at a shader that expects floats.

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

Sidebar

Related Questions

Lets say I have a fairly complex frag shader for figuring out just how
I'm trying to figure out how to do texture mapping using GLSL version 4.10.
I've been trying to figure out how to send a texture to a shader
Does the order and/or size of shader in/out variables make any difference in memory
@Override public void onTabSelected(Tab tab, FragmentTransaction ft) { if(tab.getPosition()==0) { FragmentA frag = new
First of all In Jquery loading html frag with dynamic content using load() is
Using the PVRUniScoEditor to profile our pixel shaders, I'm finding that our frag shaders
My code works fine when using glDrawArrays, but whenever I make an index buffer
I am having two fragments Frag A and Frag B which are rendered using
I have these structs: typedef struct _Frag{ struct _Frag *next; char *seq; int x1;

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.