I have an idea of fragment shader that ckecks if current fragment is inside a polygon. Vertex values of that polygon are supposed to be transfered to that shader by an array of floats. Problem is that uniform array of floats gets dropped (location = -1) since it is not directly used by shader.
I don't know how to pass an array to a shader by other method as by uniform values. Can someone direct me to a better solution?
TIA.
EDIT: (better explanation)
I have an array of float values which represent vertices of some polygon. I compute min max from that array and pass those two (min/max) vectors to geometry shader which produces a quad under that polygon. Now, my fragment shader is supposed to take that array of polygon vertices and analyze each fragment if it is inside that polygon. If inside, draw some color, if outside draw some other color.
vertex:
in vec3 inPosition;
void main(void)
{
gl_Position = vec4(inPosition, 1.0);
}
geometry:
layout(lines) in;
layout(triangle_strip) out;
layout(max_vertices = 4) out;
uniform mat4 u_proj;
void main()
{
vec4 pos0 = u_proj * gl_in[0].gl_Position;
vec4 pos1 = u_proj * gl_in[1].gl_Position;
//left up
gl_Position.x = pos0.x;
gl_Position.y = pos1.y;
gl_Position.w = pos0.w;
EmitVertex();
//left down
gl_Position = pos0;
EmitVertex();
//right up
gl_Position = pos1;
EmitVertex();
//right down
gl_Position.x = pos1.x;
gl_Position.y = pos0.y;
gl_Position.w = pos1.w;
EmitVertex();
EndPrimitive();
}
fragment:
uniform float points[570];
out vec4 outColor;
void main()
{
int nvert = 570;
float testx = gl_FragCoord.x;
float testy = gl_FragCoord.y;
int i;
int j;
bool c = false;
for (i = 0, j = nvert - 3; i < nvert; i = i + 3, j = i)
{
if (((points[i + 1]>testy) != (points[j + 1] > testy)) && (testx < (points[j] - points[i]) * (testy - points[i + 1]) / (points[j + 1] - points[i + 1]) + points[i]))
{
c = !c;
}
}
if (c == true)
{
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
else
{
outColor = vec4(0.0, 0.0, 0.0, 1.0);
}
}
these:
m_FILL_uniProjId = glGetUniformLocation(m_FillProgram, "u_proj");
m_FILL_uniCount = glGetUniformLocation(m_FillProgram, "count");
m_FILL_uniPoints = glGetUniformLocation(m_FillProgram, "points");
each returns -1.
this is how i fill my uniform array:
for (int i = 0; i < 570; ++i)
{
glUniform1fv(m_FILL_uniPoints + i, 1, &m_Points->at(i));
}
'570' is just a temporary value used in my test scene as i know the size of polygon i use.