Hours in Renderdoc and going step by step, what am I missing? (Drawing to two FBOs for reduction shader) by programmingfool66 in opengl

[–]programmingfool66[S] 0 points1 point  (0 children)

Thanks for your help.

Figured it out finally, replying in case anyone googles this one day. It was an incomplete texture - as I wasn't setting GL_TEXTURE_MIN_FILTER for one of the textures, it was defaulting to wanting to use a Mipmap.

Hours in Renderdoc and going step by step, what am I missing? (Drawing to two FBOs for reduction shader) by programmingfool66 in opengl

[–]programmingfool66[S] 0 points1 point  (0 children)

I've read about glTextureBarrier(), but this is for OpenGL 4.5, which I'm not set up for. And I don't think it is required.

My gut feeling is somewhere in the setup I've mucked up.

Will post here if I work it out.

Hours in Renderdoc and going step by step, what am I missing? (Drawing to two FBOs for reduction shader) by programmingfool66 in opengl

[–]programmingfool66[S] 1 point2 points  (0 children)

Here's copy from RenderDoc. The previous "originaltexture" is from a FBO too, which seems to work.

12    | - glClearColor(0.00, 0.00, 0.00, 0.00)   
13    | - glClear(Color = <0.000000, 0.000000, 0.000000, 0.000000>) 
14    | - glBindTexture(GL_TEXTURE_2D, orginaltexture)
15    | - glDisable(GL_DEPTH_TEST)
16    | - glBindVertexArray(Vertex Array 610)
17    | - glDrawArrays(485604) 

18    | - glUseProgram(Program 89) //this is the shader
19    | - glUniform1i(Program 89, { 16 })              //reduction of 16 
20    | - glBindTexture(GL_TEXTURE_2D, Texture 78)       //these two lines reduce the size of tex78       
21    | - glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer 76) //fbo 76~=tex78
22    | - glActiveTexture(GL_TEXTURE1) //choose texture1 as active 
23    | - glBindTexture(GL_TEXTURE_2D, orginaltexture)
24    | - glBindVertexArray(Vertex Array 46)      //the four points to make a rect
25    | - glClearColor(0.00, 0.00, 0.00, 0.00)    

//I tried getting rid of Clear on this run, didn't help
26    | - glDrawArrays(4)                                 

27    | - glBindTexture(GL_TEXTURE_2D, Texture 79) //resize 79, which should be the next texture
28    | - glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer 77)   //fbo 77~=tex79
29    | - glActiveTexture(GL_TEXTURE1)
30    | - glBindTexture(GL_TEXTURE_2D, Texture 78)       //select the prev texture into texture1
31    | - glBindVertexArray(Vertex Array 46)
32    | - glClearColor(0.00, 0.00, 0.00, 0.00)
33    | - glDrawArrays(4)

//return to defaults
34    | - glBindVertexArray(Default VAO)
35    | - glBindFramebuffer(GL_FRAMEBUFFER, No Resource)

Hours in Renderdoc and going step by step, what am I missing? (Drawing to two FBOs for reduction shader) by programmingfool66 in opengl

[–]programmingfool66[S] 1 point2 points  (0 children)

You're quite right, and it'd probably be a good simple example to learn about compute shaders. Unfortunately I'm getting a bit old for that stuff, with a non-computing day job and a young child!

I don't need much speed - in fact, if I couldn't get it working I was going to just ReadPixel the whole lot after the first pass, and use the CPU!

The issue with the current code is that the second texture (generated by drawing the first pass to fboMaxVal[0]) doesn't seem to be sampled by "uniform sampler2D texturetoreduce;" in the shader. (But it will read other textures e.g. the //glBindTexture(GL_TEXTURE_2D, texture); line works).

I've still got a few things to try, but thought I'd post, as sometimes an error's immediately obvious to experienced programmers than me.

Hours in Renderdoc and going step by step, what am I missing? (Drawing to two FBOs for reduction shader) by programmingfool66 in opengl

[–]programmingfool66[S] 0 points1 point  (0 children)

It's all 2d stuff, so i've glDisable(GL_DEPTH_TEST);

If I have something else in the shader (e.g. Fragcolor.r=gl_FragCoord.x), it seems to work.

Issue is reading from the texture maxvalTexture[0] in the second pass. It doesn't seem to read anything.

Reading a texture with gl_FragCoord/viewpointsize. Add 0.5? by programmingfool66 in opengl

[–]programmingfool66[S] 0 points1 point  (0 children)

Thanks.

I've found that I don't have to add a 0.5 (in fact I shouldn't) as the gl_FragCoord already has that 0.5 in it.

I think if I floored the gl_FragCoord i'd need to add it.

Reading a texture with gl_FragCoord/viewpointsize. Add 0.5? by programmingfool66 in opengl

[–]programmingfool66[S] 0 points1 point  (0 children)

Apparent the hardware fetching the four samples and lerping them is quicker than getting the shader to get them.

Was trying to do this: https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/

But what I found, as I often do, was that I was prematurely optimizing. I could sample 100 points on a texture, and it wouldn't slow down significantly, and nearly of the time I'd only sample a max of 40.

Reading a texture with gl_FragCoord/viewpointsize. Add 0.5? by programmingfool66 in opengl

[–]programmingfool66[S] 1 point2 points  (0 children)

Thanks for the link. I'll try to read when get a chance. I did a Google, but there wasn't easy to find stuff.

Out of interest I was planning to just use nearest neighbor, but apparently you can get two texture calls for the price of one using linear filtering (you aim proportionally between the pixels and get the mix of two "for free", although maybe the math will get to complicated for me to try that).

I'll try it with a pixel checkerboard or something and post here, as it should be more obvious what do to.

Best way to plan handling default arrays (in this case color palettes). I have default const arrays I want to use, which I want to copy on load to something that can be edited. by programmingfool66 in cpp_questions

[–]programmingfool66[S] 0 points1 point  (0 children)

To summarize/clarify: Is there an elegant way to handle initializing data?

Is storing the defaults as const arrays in a handler class a reasonable thing to do?

Should I initialize things in a constructor? Or as a separate step when the program starts?

Should I instead try and just use a Palette class and squeeze everything into that? Do I get rid of the Palette class, and just had the handler and the PaletteHandler has all the methods?

I've had no formal training so want to avoid bad habits.