3

Below is a mininal reproducer:

  GL_CHECK(glClearColor(0.4f, 0.4f, 0.4f, 1.0f));
  GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
                   GL_STENCIL_BUFFER_BIT));
  GL_CHECK(glUseProgram(this->pp_->shader_program));
  GL_CHECK(glEnable(GL_TEXTURE_2D));
  GL_CHECK(glActiveTexture(GL_TEXTURE0));
  GL_CHECK(glBindTexture(GL_TEXTURE_2D, this->particle_->id));
  GLfloat points[] = { 150.f, 150.f, 10.0f, 150.0f, 175.0f, 10.0f };
  GLfloat colors[] = { 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f };
  shader_pass_set_uniform(this->pp_, HASH("mvp"), glm::value_ptr(this->camera_));
  GL_CHECK(glEnableVertexAttribArray(0));
  GL_CHECK(glEnableVertexAttribArray(3));
  GL_CHECK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, &points[0]));
  GL_CHECK(glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 0, &colors[0]));
  GL_CHECK(glDrawArrays(GL_POINTS, 0, 2));

vertex shader:

#version 300 es

layout(location = 0) in highp vec3 vertex;
layout(location = 3) in highp vec4 color;

out lowp vec4 vcolor;

uniform mat4 mvp;

void main()
{
   vcolor               = color;
   gl_Position          = mvp * vec4(vertex.xy, 0.0, 1.0);
   gl_PointSize         = vertex.z;
}

fragment shader:

#version 300 es

uniform sampler2D stexture;
in lowp vec4 vcolor;

layout(location = 0) out lowp vec4 ocolor;

void main()
{ 
    ocolor = texture(stexture, gl_PointCoord) * vcolor;    
}

Nothing gets rendered on-screen, my glxinfo can be found in this pastebin. When I render the same texture onto a triangle it works.

Here is also the render loop as captured with apitrace:

250155 glClearColor(red = 0.5, green = 0.5, blue = 0.5, alpha = 1)
250157 glClear(mask = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT)
250159 glUseProgram(program = 9)
250161 glEnable(cap = GL_TEXTURE_2D)
250163 glActiveTexture(texture = GL_TEXTURE0)
250165 glBindTexture(target = GL_TEXTURE_2D, texture = 2)
250167 glUniformMatrix4fv(location = 0, count = 1, transpose = GL_FALSE, value = {0.001953125, 0, 0, 0, 0, 0.002604167, 0, 0, 0, 0, -1, 0, -1, -1, -0, 1})
250168 glEnableVertexAttribArray(index = 0)
250170 glEnableVertexAttribArray(index = 3)
250174 glVertexAttribPointer(index = 0, size = 3, type = GL_FLOAT, normalized = GL_FALSE, stride = 0, pointer = blob(24))
250175 glVertexAttribPointer(index = 3, size = 4, type = GL_FLOAT, normalized = GL_FALSE, stride = 0, pointer = blob(32))
250176 glDrawArrays(mode = GL_POINTS, first = 0, count = 2)
250178 glXSwapBuffers(dpy = 0x1564010, drawable = 50331661)
arul
  • 13,998
  • 1
  • 57
  • 77
  • The way I read the matrix in the API trace, the points would be outside the clip volume. I don't think a `z` value of 10.0f is within the visible range using that matrix. – Reto Koradi Oct 17 '15 at 02:11
  • @RetoKoradi The 'z' coordinate is interpreted in the shader as point size. – arul Oct 17 '15 at 11:44
  • @id256 How would I know? I'm not the one asking the question. – Reto Koradi Oct 19 '15 at 14:19
  • Since this is on Linux, which normally also supports desktop OpenGL: Are you specifically creating an ES 3.0 context? There are some differences in point rendering between OpenGL ES and OpenGL. – Reto Koradi Oct 19 '15 at 14:21
  • @RetoKoradi Sorry man, my intention was to ask the OP. – tonso Oct 19 '15 at 14:29
  • @arul What do you mean by "render the same texture onto a triangle"? glDrawArrays(GL_TRIANGLES, ... with some other organization of the position data? And what happens, when you try to render it with GL_LINES? – tonso Oct 19 '15 at 14:30
  • @RetoKoradi yes, this is OpenGL ES 3.0 context. – arul Oct 19 '15 at 15:45
  • @id256 yes, I can render `GL_TRIANGLES / GL_TRIANGLE_STRIPS / GL_LINES` just fine. The problem happends when rendering `GL_POINTS`. – arul Oct 19 '15 at 15:48
  • @arul Does it render anything if you use something like `ocolor = vec4(1.0, 0.0, 0.0, 1.0);` in the fragment shader? – tonso Oct 19 '15 at 19:46
  • @id256 Yes, I can see 1px red dots at the expected locations! The texture is actually transparent at (0, 0) so that's why it probably didn't render anything. But why is the `gl_PointSize` ignored? Btw. I just tried `gl_PointSize = 30.0f;` but still 1px dots. – arul Oct 19 '15 at 20:24

1 Answers1

1

I guess that could mean, that the range of point sizes, that your GLES implementation supports, may be not what you are expecting. You can try something like:

GLint range[2];
glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, range); // for example, (1, 511) in my implementation

to check it out. Any implementation guarantees, that range[1] is at least 1.0. The value gl_PointSize is getting clamped to the range, so in the worst case you won't be able to set point with size, greater than 1. In this case gl_PointCoord seems to evaluate to (1, 0) (according to formula from specs) at the only fragment, that is going to be drawn for each point. After the texture's wrap mode come into play, (1, 0) may turn into (0, 0), for example if you are using GL_REPEAT as the texture's wrap mode. If you'd like to safely draw a point with side, greater than one, you should try using the ordinary way to draw squares (for example using four vertices and GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP mode).

tonso
  • 1,760
  • 1
  • 11
  • 19
  • I've got (1, 2047), so it should be supported. Any idea besides buggy drivers? – arul Oct 19 '15 at 21:06
  • @arul None yet. And ignoring `gl_PointSize` looks very strange ... Though if the range was (1,1) everything would be pretty explainable. – tonso Oct 19 '15 at 21:28
  • @arul Are you using scissor or stencil test? – tonso Oct 19 '15 at 21:42
  • @arul Anyway, if it takes a lost of time to figure out the issue, I'd stick to the obvious solution, that I mentioned in the end of my answer. – tonso Oct 19 '15 at 21:50
  • Neither of them. I'm reporting the error to NVIDIA. Well, this part of codebase is supposed to handle point clouds and CPU particles, so I really can't make it quads. I want to have +/- megaparticles for GPU particle system. I'll wait some more time then accept your answer, as it helped me to confirm that what I have _should_ work, and also that it _works_ only for single pixel :) – arul Oct 19 '15 at 21:56
  • @arul Ok, good luck. When you find something, could you share your knowledge? ;) – tonso Oct 19 '15 at 22:02