Hi all, its been awhile since I last posted.
(this is with Lime 5.0.3, hxcpp 3.4.64, openfl 5.1.2)
Note - this may be purely to do with Lime and not much to do with OpenFL. Forgive me if this is the wrong place to post this low level stuff
Anyway, I have been chugging along learning OpenGL and translating book content to Haxe working sample versions. First every example (and the website extras) from WebGL Programming Guide by Matsuda Lea, and now working on OpenGL 4 Shading Language Cookbook (which I know 4 is kind of high for cross-platform but I am making do and know enough by now about #version differences to make it work so far)
Anyways I have hit a bit of an impasse.
I am working on getting a FrameBuffer with Multiple Render Targets sample up and running, and am having trouble getting the FrameBuffer to render to more than just one COLOR_ATTACHMENT# (in this case, 0 works).
I was able to get a single texture-bound framebuffer example to work, and even went so far as to extend it as a sort of ping-pong rendering using two FBOs with single texture each.
Where I am at now, is only the first texture bound to the FBO will be rendered to, when I am attempting to bind 3 (one each for storing Position data, Normal data, and diffuse/color data) however I can only get the first to actually render to texture, and this ends up incorrect which I’ll describe below. (in short, fragment shader seems to only respect layout (location = 0) out vec4 FragColor, and the texture bound to FBO with COLOR_ATTACHMENT0 is the only texture drawn-to)
The way I am testing the end-result is by simply, using a if statement branch in my ubershader (bad practice I know, this is just for prototype reasons), I draw from a selected texture to a simple quad.
Frag shader setup:
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 PositionData;
layout (location = 2) out vec4 NormalData;
layout (location = 3) out vec4 ColorData;
// actual texture
uniform sampler2D u_sampler; // ends up bound to TEXTURE0 when drawing-from
// g-buffer textures
uniform sampler2D u_positionTex; // ends up bound to TEXTURE0+1 when drawing-from
uniform sampler2D u_normalTex; // ends up bound to TEXTURE0+12 when drawing-from
uniform sampler2D u_colorTex; // ends up bound to TEXTURE0+13 when drawing-from
void main() {
//if render mode is store in g-buffers...
PositionData = vec4(Position, 1.0);
NormalData = vec4(Normal, 1.0);
ColorData = texture2D(u_Sampler, v_TexCoord);
FragColor = texture2D(u_Sampler, v_TexCoord);
//if render mode is draw to quad... (( and FBO is unbound ))
textureColor = texture2D(selectedTexture, v_TexCoord)
// /\ where selected texture ends up either u_sampler, u_positionTex, u_normalTex, or u_colorTex
FragColor = textureColor;
...
}
When binding the textures to the FBO I use the following call:
gl.framebufferTexture2D(gl.FRAMEBUFFER, tempTextureInfoContainer.gl_ColorAttachment,
gl.TEXTURE_2D, tempTextureInfoContainer.texture, 0);
where tempTextureInfoContainer.gl_ColorAttachment, in order of the textures passed in, is COLOR_ATTACHMENT0, 1, and 2 respectively.
As mentioned above, only one texture ends up being drawn to, and that is the first texture I bind to the FBO.
However, what ends up being drawn to that first texture, is FragColor in layout = 0. Changing what is drawn to it to hard color (green) or one of the other values (such as storing the normal) does propagate to the texture at TEXTURE1 (bound to FBO using COLOR_ATTACHMENT0 ie layout = 0) and eventually to the test-draw to the quad.
After wrestling with this off and on for about a week I am at an impasse. I believe I have narrowed it down to the following call, which appears to do nothing:
var drawBuffersArray:Array<Int> = gl.NONE, [gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2];
gl.drawBuffers(drawBuffersArray); //does nothing
The purpose of drawBuffers is to connect the textures (bound to the FBO) to the fragment shaders output variables (a la 0, 1, and 2) so that they get drawn to. The default is a single entry COLOR_ATTACHMENT0, which is why I think single-texture FBO’s do work
in fact I can pass any number of, and as high an Int value into that array that I want (ie values that surpass MAX_DRAW_BUFFERS, even negative values) and there are no errors thrown. Passing a variety of values to this does not change anything.
This leads me to believe this function gl.drawBuffers(buffers:Array) is (as of yet) unsupported on Native. (the function is a stub in NativeGLRenderContext.hx) Is this correct? If so, are there plans to implement support in the future? (I’ve peeked into the latest in Lime 5.3.0 but it still looks like a stub)
If it is in fact supported, are there any ideas as to what I am doing wrong then? I am at a loss and Deferred Rendering is pretty important for my engine I am building. (going to be using a ton of lights)
Anyways, thank you for your time!