hi everyone:
i applied a Texture2d with the code below:
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,4096, 4096, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
and then i used it as TBO:
glBindTexture(GL_TEXTURE_2D, 0);
glBindImageTexture(0, textureID, 0, GL_FALSE,0, GL_READ_WRITE, GL_RGBA8UI);
i want to update my this texture in my fragement, every pixels in my texture is updataed by it’s former color and the new color. i want to save memory, so i apply the texture in GL_RGBA8.
here is my Fragement shader:
#version 420
in vec4 color_from_vshader;
in vec2 text_coord;
out vec4 out_color;
uniform sampler2D SpriteTex;
uniform float bDraw;
uniform vec3 oldcolor;
layout (binding=0, rgba8) uniform uimage2D out_texture;
void main() {
if(bDraw > 0.0)
{
//out_color = color_from_vshader;
ivec4 orgColor = imageLoad(out_texture, ivec2(gl_FragCoord.xy));
if(color_from_vshader.w>0)
{
imageStore(out_texture, ivec2(gl_FragCoord.xy), ivec4(255*oldcolor,color_from_vshader.w));
}
else if(orgColor.w < 0.1)
{
imageStore(out_texture, ivec2(gl_FragCoord.xy), ivec4(0, 0, 0,0));
}
else
{
orgColor = orgColor - 0.1 * vec4(oldcolor, orgColor.w);
imageStore(out_texture, ivec2(gl_FragCoord.xy), orgColor);
}
}
else
{
out_color = texture(SpriteTex, text_coord);
}
}
in the shader, when i want to update the texture, i will set the “bDraw” to 10.0, and call “glDrawArrays(GL_POINTS, 0, numPoints);”.
but when i compile the shader,i got the below error log:
0(10) : error C1318: can’t apply layout(rgba8) to image type “uimage2D”
0(10) : error C1315: can’t apply layout(rgba8) to non-image
0(10) : error C7596: OpenGL requires image variables declared without using the ‘writeonly’ qualifier to have a format layout qualifier
0(16) : error C1115: unable to find compatible overloaded function “imageLoad(struct uimage2D_bindless, ivec2)”
0(27) : error C7011: implicit cast from “vec4” to “ivec4”
i know this "0(27) : error C7011: implicit cast from “vec4” to “ivec4"”,but i can’t understand others. i found some sample code in 《OpenGL Programming Guide》,but the texture is GL_RGBA32F. i can’t access a texture in GL_RGBA8.is there anyone can give me some suggestions?