OpenGL Erorr: Module out of frame.

So, to begin with a bit of backstory, I’m building a graphics engine for a game engine that I am making via following some youtube video series. Upon getting to use of texture arrays and being able to use multiple textures at once/batch rendering textures this error occured. Originally this error manifested as Nvoglv32.dll requiring Nvoglv32.pdb to debug. However, after checking my uniforms I managed to discover that the issue was due to one of them. But, this left me with the current crashing issue. I’m certain theres something wrong with the array of samplers I am trying to use, but I’m unsure. The program only crashes upon a specific line in the shader, removal of this allows me to render a none textured sprite manually quite happily.

Here are my shaders,

vertex:

#version 330 core

layout (location = 0) in vec4 position;
layout (location = 1) in vec2 uv;
layout (location = 2) in float tid;
layout (location = 3) in vec4 color;

uniform mat4 pr_matrix;
uniform mat4 vw_matrix = mat4(1.0);
uniform mat4 ml_matrix = mat4(1.0);

out DATA
{
	vec4 position;
	vec2 uv;
	float tid;
	vec4 color;

} vs_out;


void main()
{
	gl_Position = pr_matrix * vw_matrix * ml_matrix * position;
	vs_out.position = ml_matrix * position;
	vs_out.uv = uv;
	vs_out.tid = tid;
	vs_out.color = color;
}

and fragment:

#version 330 core

layout (location = 0) out vec4 color;

uniform vec4 col;
uniform vec2 light_pos;

in DATA
{
	vec4 position;
	vec2 uv;
	float tid;
	vec4 color;
} fs_in;

uniform sampler2D textures[32];

void main()
{
	float intensity = 1.0f / length(fs_in.position.xy - light_pos);
	vec4 texColor = fs_in.color;
	if(fs_in.tid > 0.0)
	{
		int tid = int(fs_in.tid + 0.5);
		texColor = texture(textures[tid], fs_in.uv);
	}

	color = texColor * intensity;

	//color = vec4(tid, 0, 0, 1) * intensity;
}

The exact line that the crash occurs is, texColor = texture(textures[tid], fs_in.uv);

As far as I can see the tid (texture ID) being passed in from my renderer is properly assigned to the textures that I’m trying to use. Using the tid value in the bottom color set also incurrs the same crash as trying to use the array of samplers. Any help into if I’m doing anything wrong would be greatly appreciated. Also, if I need to provide more code please say so.

This is invalid. For GLSL 3.3 (§4.1.7):

Samplers aggregated into arrays within a shader (using square brackets ) can only be indexed with integral constant expressions

For later versions, the restriction is relaxed somewhat (§4.1.7.1):

When aggregated into arrays within a shader, samplers can only be indexed with a dynamically uniform integral expression, otherwise results are undefined.

But this still doesn’t allow what you’re trying to do.

If the texture ID can vary between fragments within a single primitive, then you cannot use an array of samplers in this way; you need to use an array texture instead. If the texture ID is constant for each primitive, and you’re willing to limit yourself to more recent versions of GLSL, then you can add the “flat” qualifier to [var]tid[/var], which will make the expression dynamically-uniform.

Hm, I see. Heres a link to the video with the exact same shader as I’m using, that works (a bit later on after he fixes a couple of things). Also, from what I understand the idea of this is that one primitive gets one texture ID across all the fragments for the primitive.

Which is odd to me. So, how do I go about rectifying it… since it worked for him but not me?

In which case, you can add the [var]flat[/var] qualifier to [var]tid[/var] (and may as well declare it as an [var]int[/var]).

You’ll also need to change the GLSL version to:


#version 400

I gave this a go and I still get crashes, however with the help of a friend I have narrowed it down to being within my flush() function that is in my batch renderer, the crash occurs at a call to glDrawElements() which is leaving me back at square one with no clue as to why it’s crashing.

(I attempted to include the flush() function here but kept getting told my post was denied)

You tried with putting your code between [ code] and [ /code] statements (without any spaces in between) ?
I guess you need few posts before you’re able to use all the tools this forums provides.

[QUOTE=Silence;1284397]You tried with putting your code between [ code] and [ /code] statements (without any spaces in between) ?
I guess you need few posts before you’re able to use all the tools this forums provides.[/QUOTE]

I did that in my first post. Not sure why it wouldn’t let me do it again.