首页 \ 问答 \ 将uint传递给着色器会更改其值(Passing a uint to shader changes its value)

将uint传递给着色器会更改其值(Passing a uint to shader changes its value)

我试图将一个uint传递给我的着色器,但我必须做错了,因为在着色器中值为3212836864而不是4294967295。

我有一个Vertex数组,我存储每个顶点,然后使用glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex) * 4 * vertexBufferArrayInserts, vertexBufferArray);将它们发送到着色器glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex) * 4 * vertexBufferArrayInserts, vertexBufferArray);

这些是我的glVertexAttribPointer调用:

    shaderPosAttrib = glGetAttribLocation(shaderProgram, "position");
    glVertexAttribPointer(shaderPosAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
    glEnableVertexAttribArray(shaderPosAttrib);

    shaderTexCoordAttrib = glGetAttribLocation(shaderProgram, "texCoord");
    glVertexAttribPointer(shaderTexCoordAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texCoords));
    glEnableVertexAttribArray(shaderTexCoordAttrib);

    shaderColorAttrib = glGetAttribLocation(shaderProgram, "color");
    glVertexAttribPointer(shaderColorAttrib, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, color));
    glEnableVertexAttribArray(shaderColorAttrib);

这是Vertex结构

struct Vertex
{
    Vector2<GLfloat> position;
    Vector2<GLfloat> texCoords;
    GLuint color;

    Vertex() {

    }

    Vertex(Vector2<GLfloat> position, Vector2<GLfloat> texCoords, GLuint color) {
        this->position = position;
        this->texCoords = texCoords;
        this->color = color;
    }
};

顶点着色器:

#version 150

in vec2 position;
in vec2 texCoord;
in uint color;

out vec2 TexCoord;
out uint Color;

uniform mat4 projMat;

void main()
{
    TexCoord = texCoord;
    Color = color;
    gl_Position =  projMat * vec4(position, 0.0, 1.0);
}

片段着色器:

#version 150

in vec2 TexCoord;
in uint Color;

out vec4 outColor;

uniform sampler2D tex;

void main()
{
    float colorr = 0;

    if(Color == 3212836864)
        colorr = 1;

    outColor = texture(tex, TexCoord) * vec4(colorr, colorr, colorr, 1.0);
}

显然我在某处做错了但我却看不到它...非常感谢帮助!


I'm trying to pass a uint to my shader but I must be doing something wrong because in the shader the value is 3212836864 and not 4294967295.

I have a Vertex array that I store each vertex in before sending them to the shader using glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex) * 4 * vertexBufferArrayInserts, vertexBufferArray);

These are my glVertexAttribPointer calls:

    shaderPosAttrib = glGetAttribLocation(shaderProgram, "position");
    glVertexAttribPointer(shaderPosAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
    glEnableVertexAttribArray(shaderPosAttrib);

    shaderTexCoordAttrib = glGetAttribLocation(shaderProgram, "texCoord");
    glVertexAttribPointer(shaderTexCoordAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texCoords));
    glEnableVertexAttribArray(shaderTexCoordAttrib);

    shaderColorAttrib = glGetAttribLocation(shaderProgram, "color");
    glVertexAttribPointer(shaderColorAttrib, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, color));
    glEnableVertexAttribArray(shaderColorAttrib);

And this is the Vertex struct

struct Vertex
{
    Vector2<GLfloat> position;
    Vector2<GLfloat> texCoords;
    GLuint color;

    Vertex() {

    }

    Vertex(Vector2<GLfloat> position, Vector2<GLfloat> texCoords, GLuint color) {
        this->position = position;
        this->texCoords = texCoords;
        this->color = color;
    }
};

Vertex shader:

#version 150

in vec2 position;
in vec2 texCoord;
in uint color;

out vec2 TexCoord;
out uint Color;

uniform mat4 projMat;

void main()
{
    TexCoord = texCoord;
    Color = color;
    gl_Position =  projMat * vec4(position, 0.0, 1.0);
}

Fragment shader:

#version 150

in vec2 TexCoord;
in uint Color;

out vec4 outColor;

uniform sampler2D tex;

void main()
{
    float colorr = 0;

    if(Color == 3212836864)
        colorr = 1;

    outColor = texture(tex, TexCoord) * vec4(colorr, colorr, colorr, 1.0);
}

Obviously I'm doing something wrong somewhere but I just can't see it... Help is very much appreciated!


原文:https://stackoverflow.com/questions/17260493
更新时间:2022-05-20 18:05

最满意答案

您可能希望重新考虑日期时间字段上的分组,如果您希望它与第二个字段区分开来; 多个记录共享完全相同的日期时间字段的可能性通常非常低,否定了分组的有用性。

出于这个原因,CR可能已经冒昧地假设您只想按日期而不是完整的日期时间值进行分组。 您可以通过执行以下步骤进行检查:从CR工具栏中选择“报告”→“组专家”→在右侧选择您的组并点击“选项”→在“公共”选项卡底部会有一个标有下拉列表的下拉列表“该部分将被打印”。 验证它是否显示“For each second”而不是“For each day”或其他值。

从这里开始,您可以控制希望CR为您的日期时间值分组的网络的大小。


You may want to rethink grouping on a datetime field if you want it distinct down to the second; the chance that multiple records share the exact same datetime field are usually extremely low, negating the usefulness of grouping.

For this reason, CR may have taken the liberty of assuming you only wanted to group by the date instead of the full datetime value. You can check by performing the following steps: Select "Report" from the CR toolbar → "Group Expert" → Select your group on the right and hit "Options" → At the bottom of the "Common" tab there will be a dropdown labeled "The section will be printed". Verify that it says "For each second" instead of "For each day" or some other value.

It's from here that you can control how small or large of a net you want CR to group for your datetime values.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)