Is there a way to initialize or reset an OpenGL texture with a solid color? I can use functions up to OpenGL 4.0 since I'd like to support notebook's Intel HD Graphics 4000.
-
1@fedab I create a really flexible rendering pipeline. Render passes can be toggled or modified on the fly. Therefore, each render pass can specify fallbacks that are performed when the pass is disabled, so that the whole pipeline still works. Those fallbacks include filling a texture with a solid color and copying another texture over without modification. – danijar Jan 19 '14 at 11:13
4 Answers
If you unbind a texture from its unit/sampler object, it texture accesses will come out all white. So I suggest you simply add a uniform for color modulation. If you need a solid color, unbind the texture and set that color uniform to whatever you want.
But quite frankly, it sounds to me, like you want to reimplement the OpenGL fixed function pipeline, where you had a large bunch of switches to get your desired effects. We finally got rid of that, and now you want to reincarnate this bane?

- 159,371
- 13
- 185
- 298
-
I think my rendering pipeline is designed quite well. However, I'd love to hear your thoughts on it. Render passes are defined in a scripting file and can be toggled at runtime with according fallbacks taking place. This is my [current pipeline script](https://github.com/ComputerGame/GraphicsApplication/blob/master/module/renderer/pipeline.js). Also uniforms can be set from scripts. Do you see design mistakes in my pipeline I could improve? – danijar Jan 19 '14 at 13:47
-
The problem with the fixed function pipeline was that many use cases don't fit it. But what if the asker's program's needs exactly match the capabilities of a fixed function pipeline? – user253751 Jan 08 '17 at 08:37
Although you say you can use up to GL 4.0 (and you got some answers for that), I'd still like to point out that beginning with GL 4.4, there is also glClearTexImage()
.
The relevant OpenGL extension for this is ARB_clear_texture
. Intel HD 4000 is said to support GL4.0, but with newer drivers, lots of extensions implementing extensions for 4.1, 4.2 and 4.3 level feautres have been adeed. However, I have not yet found any source claiming that Intel had started implementing 4.4 level features. The latest source I found is this OpenGL feature matrix from february 2014
showing that Intel des not yet support that feature. But I find it quite likely that this extension might be supported in future driver versions.

- 43,833
- 2
- 57
- 78
-
You don't know if this is supported by Intel's HD graphics drivers as an extension, do you? – danijar Mar 29 '14 at 11:08
-
Maybe you can use a framebuffer. You can link it with a texture and draw what you want on the framebuffer. If the fallback is in action, you clear the framebuffer to a color you want.
And then you draw the framebuffer as texture.

- 978
- 11
- 38
-
In the last hours, I implemented clearing and copying in the same way using simple shaders. It works now. Do you think clearing is considerably faster than using a simple fragment shader? – danijar Jan 19 '14 at 13:34
-
@danijar Not sure. You have to create and run the shader. I would use the clearing described on the [OpenGL Wiki](https://www.opengl.org/wiki/Framebuffer#Buffer_clearing). – fedab Jan 19 '14 at 14:29
You can do that by copying your color data into the already created texture using glTexSubImage2D, and giving it the full textures dimensions. The different is that this doesn't create a new buffer but only updates it.

- 2,248
- 12
- 21
-
So I would create a long array of the same color for each pixel and send that to the video card, right? – danijar Jan 19 '14 at 11:44
-
@danijar yes, just like an ordinary image. What makes this a requirement, is the problem is that in order to clear a buffer (frame buffer for example) you need to lock the buffer and loop through it and reset each pixel. This operation is slow that's is why it is implemented in Hardware. In your case you don't have that privialge. Unless you can modify the texture object on the fly using shaders. Check texture buffer objects but am not sure about this . – concept3d Jan 19 '14 at 11:47
-
@danijar You can do that using FBOs this way you can reduce data transfer to the GPU. But this will need more work. – concept3d Jan 19 '14 at 12:26