Transform feedback working on Windows but not MacOS

Hello,

Trying to get a project working cross-platform, and have hit something of a wall with the Mac version. Transform feedback works fine on Windows, but doesn’t on Mac. I suspect something is being done in the wrong order- my desktop Windows graphics card has been rather more tolerant than the integrated graphics on my MacBook- but I can’t see what it is. I have bootcamp installed on the MacBook, and running the windows version on the same machine works absolutely fine.

The aim is to get a series of particles to leave trails. I have two texture buffers that I am using alternately to read from and write values to. These write a series of values, which are then rendered as line strips, or as points (as they are in the modified code below)

Here’s the code for the set up:

void ofApp::setupTrails() {

  int totalTrailParticles = numTrails * pointsPerTrail;
  int bufferSize = sizeof(glm::vec4) * totalTrailParticles;

  feedbackMesh.setMode(OF_PRIMITIVE_POINTS);
  feedbackMesh.getVertices().resize(totalTrailParticles);

  feedbackBuffer1.allocate(bufferSize, GL_STATIC_DRAW);
  fromBuffer = &feedbackBuffer1;

  feedbackBuffer2.allocate(bufferSize, GL_STATIC_DRAW);
  toBuffer = &feedbackBuffer2;

  feedbackSourceBuffer.allocate(bufferSize, GL_STATIC_DRAW);

  int i, j;
  std::vector<float> positionElements;
  std::vector<int> indices;

  string s;

  for (i = 0; i < numTrails; i++) {

    for (j = 0; j < pointsPerTrail; j++) {
      positionElements.insert(positionElements.end(), {
        // Particle values is for now a random set of points
        particleValues[i * 4],
        particleValues[i * 4 + 1],
        particleValues[i * 4 + 2],
        particleValues[i * 4 + 3]
        });

      indices.insert(indices.end(), i * pointsPerTrail + j);
    }

    indices.insert(indices.end(), restartIndex);

  }

  feedbackSourceBuffer.setData(positionElements, GL_STATIC_DRAW);
  feedbackSourceBuffer.copyTo(feedbackBuffer1);
  feedbackSourceBuffer.copyTo(feedbackBuffer2);

  feedbackSourceTexture.allocateAsBufferTexture(feedbackSourceBuffer, GL_RGBA32F);
  feedbackTexture1.allocateAsBufferTexture(*fromBuffer, GL_RGBA32F);
  fromTexture = &feedbackTexture1;

  feedbackTexture2.allocateAsBufferTexture(*toBuffer, GL_RGBA32F);
  toTexture = &feedbackTexture2;

  feedbackRenderVbo.getVertexBuffer().allocate(bufferSize, GL_STATIC_DRAW);

  trailIndexBuffer.allocate(sizeof(int) * indices.size(), GL_STATIC_DRAW);
  trailIndexBuffer.setData(indices, GL_STATIC_DRAW);
  feedbackRenderVbo.enableIndices();
  feedbackRenderVbo.setIndexBuffer(trailIndexBuffer);

  feedbackSettings.shaderFiles[GL_VERTEX_SHADER] = "shaders/transformShader.vert";
  feedbackSettings.bindDefaults = false;
  feedbackSettings.varyingsToCapture = { "outputVec" };
  
  feedbackShader.setup(feedbackSettings);

}

Here’s the code for performing the feedback:

void ofApp::doFeedback() {
  // Reallocate the texture
  fromTexture->allocateAsBufferTexture(*fromBuffer, GL_RGBA32F);

  // rm: rotation manager, which is just slowly adding rotation to a matrix
  model = rm.matrix; 
  feedbackShader.begin();
  feedbackShader.beginTransformFeedback(GL_POINTS, *toBuffer);
  feedbackShader.setUniform1i("trailSize", pointsPerTrail);
  feedbackShader.setUniformMatrix4f("modelMatrix", model);
  feedbackShader.setUniformTexture("sourceTex", feedbackSourceTexture, feedbackShader.getUniformLocation("sourceTex"));
  feedbackShader.setUniformTexture("tex", feedbackTexture1, feedbackShader.getUniformLocation("tex"));
  feedbackMesh.draw();
  feedbackShader.endTransformFeedback();

  feedbackRenderVbo.setVertexBuffer(*toBuffer, 4, 0);

  ofBufferObject* tmp = fromBuffer;
  fromBuffer = toBuffer;
  toBuffer = tmp;

  ofTexture* tmpTex = fromTexture;
  fromTexture = toTexture;
  toTexture = tmpTex;

}

And then to draw:

feedbackRenderVbo.drawElements(GL_LINE_STRIP, numTrails * pointsPerTrail + numTrails);
hypershader.end();

Annoyingly I was just about to post the transform feedback shader when my internet fell over, but I’ll do that when it comes back up (editing on mobile now)

Any help much appreciated!

Hello @Godwhacker . Most of the time those applications with shaders that work on windows and linux but not on mac, they do not run because they are using some… ehm… “new” openGL functionality that mac does not support. What is the openGL version that are you using? In your shader you should have as first line something like: version 150, or another number.

I’ve got #version 330 in the shader- as far as I can tell it’s not doing anything fancy, and there’s no compilation errors.

#version 330
uniform int trailSize;
uniform samplerBuffer tex;
uniform samplerBuffer sourceTex;
uniform mat4 modelMatrix;
out vec4 outputVec;

void main() {
  
  int id = gl_VertexID;
  vec4 pos;

  if (id % trailSize == 0) {
    pos = modelMatrix * texelFetch(sourceTex, id);
    outputVec = pos;
    
  }
  else {
    pos = texelFetch(tex, id - 1);
    outputVec = pos;
  }

}

I noticed that the TransformFeedbackExample that OpenFrameworks comes with isn’t included in the Mac download, so I downloaded it separately and put it in a new project, which didn’t work either.

Fortunately, checking Github, it seems all this will be fixed in an upcoming release.

Putting the rasteriser discard instructions in my local copy works just fine, so panic over.

1 Like