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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:59:44+00:00 2026-06-10T18:59:44+00:00

So, I’m trying to make sense of some code before I copy and paste

  • 0

So, I’m trying to make sense of some code before I copy and paste it into my application. In openGL I’m seeing some variables typed as in and out. I see no such thing in the following code snippet. From what I understand, the vertex shader “magically” gets the input for the “in” typed variables via the program, which incidentally can have a fragment and vertex shader attached to it(the program). Heres the code:

<script id="shader-vs" type="x-shader/x-vertex">
attribute vec2 aVertexPosition;
attribute vec2 aPlotPosition;

varying vec2 vPosition;

void main(void) {
    gl_Position = vec4(aVertexPosition, 1.0, 1.0);
    vPosition = aPlotPosition;
}
</script>

So, my question is, by attaching an appropriate program here, aVertexPosition and aPlotPosition will both be properly initialized and furthermore, vPosition could be used somewhere else in my app, namely the fragment shader?

  • 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-10T18:59:46+00:00Added an answer on June 10, 2026 at 6:59 pm

    Let me try and explain how the GPU pipeline I/O works:

    Each Vertex has a set of attributes associated with it. Given your example code:

    attribute vec2 aVertexPosition;
    attribute vec2 aPlotPosition;

    You are saying that each vertex has a 2D vertex position and plot position. If you added:

    attribute vec3 vNormal;

    Then every vertex would also have a normal. You could think of these as vertex “properties”.

    You must tell the GPU where to fetch the values for each of these attributes.

    Each vertex attribute is assigned an attribute array index when the shader is compiled. You must enable each attribute array index that your shader requires

    enableVertexAttribArray(int attributeIndex);
    

    Once you’ve enabled it, you want to bind the attribute array to a vertex buffer.

    bindBuffer(ARRAY_BUFFER, buffer);
    

    You now describe how to fetch the attribute with this call:

    vertexAttribPointer(int attributeIndex, int count, int type, bool normalized, int stride, int offset);
    

    Given your example code:

    vertexAttribPointer(0, 2, FLOAT, false, 16, 0); // vertex position
    vertexAttribPointer(1, 2, FLOAT, false, 16, 8); // plot position
    

    16 or the stride is the number of bytes between each vertex. Each vertex consists of 4 floats and each float is 4 bytes wide. The offset is where the attribute starts within a vertex. The vertex position is at the 0th byte of the vertex and plot position is at the 8th.

    You can think of these as describing how to index into an array. The Nth vertex:

    aVertexPosition.x = BUFFER[offset + N * stride + sizeof(FLOAT) * 0];
    aVertexPosition.y = BUFFER[offset + N * stride + sizeof(FLOAT) * 1];
    

    Vertex attributes are fetched automatically for you by the GPU and filled in before your vertex shader function is executed. Yes your vertex shader main is called once for every single vertex you draw.

    The output of the vertex shader stage are the ‘varying’ variables. They are ‘varying’ because they are interpolated across the surface of the primitive (triangle) between vertices. You write the values out for each vertex but when the triangle is rasterized into fragments, each fragment gets the interpolated value of each varying variable. The fragment shader gets run for every fragment (pixel) that is “covered” by the draw call. If you draw a small triangle that covers a 4×4 patch of pixels then the fragment shader is executed 16 times.

    Concisely:

    Vertex Shader Inputs: Vertex Attributes & Uniform values (not covered)
    Vertex Shader Outputs: Varying Values at each vertex
    Fragment Shader Inputs: Varying Values for a given fragment (pixel)
    Fragment Shader Outputs: Color & Depth values which are stored in the color and depth buffer.
    
    Vertex Shader is run for every vertex in the draw call.
    Fragment shader is run for every "covered" or "lit" fragment (pixel) in the draw call.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.