Results 1 to 6 of 6

Thread: Passing unifrom glm::vec3 array to shader

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    5

    Passing unifrom glm::vec3 array to shader

    Hello guys,

    Im trying to pass an array with vec3 to a fragmentshader.
    My code looks like this, but I think it`s wrong:

    Code :
    bool Shader::SetShaderVec3ArrayParameter(const char* pName, vec3 pValue[])
    {
    	int loc = glGetUniformLocation(m_shaderProgram, pName);
    	if (loc >= 0)
    	{
    		glUniform3fv(loc, sizeof(pValue),(float*)pValue);
     
    		return true;
    	}
     
    	return false;
    }

    can anyone tell me how to pass an array of vec3 to a shader as an uniform variable?!
    Thanks in advance

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    22
    What version of OpenGL are you using?

    In OpenGL 4 I would maybe create a uniform buffer with glBufferStorage (if available to you) otherwiese glBufferData. I would then use glBindBufferBase with an explicit binding point, as to avoid any shader reflection.

    ex:

    Code :
    layout(binding = 0, std140) uniform SomeBlock
    {
        vec3 data[MAX_DATA_ARRAY_SIZE];
    };

  3. #3
    Senior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    281
    Code :
    bool Shader::SetShaderVec3ArrayParameter(const char* pName, vec3 pValue[])
    {
        ....
            glUniform3fv(loc, sizeof(pValue),(float*)pValue);
        ....
    }

    pValue is a pointer to a vec3. sizeof(pValue) is the size of a pointer as a multiple as the size of a char. Probably 8 or 4 or something.
    What is your vec3 anyway? Does it really store exactely 3 float value with no padding whatsoever?

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    5
    Quote Originally Posted by Agent D View Post
    [CODE]

    What is your vec3 anyway? Does it really store exactely 3 float value with no padding whatsoever?
    vec3 is a glm::vec3 from an OpenGl Mathematics library

    glm.g-truc.net/0.9.5/index.html


    I thought that it stores 3 float values as a vec3. When I pass just one vec3, everything works fine. Only the array isn`t working.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    5
    Quote Originally Posted by Chris_F View Post
    What version of OpenGL are you using?
    [/code]
    I`m using OpenGL 4. I don`t think that I get your code right . Can you describe it more in detail?

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    22

Similar Threads

  1. Passing an array of glm::mat4 to vertex shader
    By Patsch in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-23-2017, 03:46 AM
  2. Passing large mat4 array to fragment shader
    By Iaolia456 in forum OpenGL: GLSL
    Replies: 5
    Last Post: 04-25-2016, 08:09 AM
  3. Passing array of vec3 to fragment shader
    By icius74 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 02-16-2016, 11:44 AM
  4. How to initialize Vec3 Array
    By Daling in forum OpenGL: GLSL
    Replies: 1
    Last Post: 06-01-2010, 06:02 AM
  5. Constant vec3 array - no go
    By Dark Photon in forum OpenGL: GLSL
    Replies: 10
    Last Post: 03-03-2010, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean