# OpenGL Transform Feedback empty on iOS

## Recommended Posts

Posted (edited)

I have used transform feedback for particle system update in my Win32 app. All is working correctly. I have transported the app to OpenGL ES 3.0 on iOS. However, when I run my app, no data are shown. If I look at content of vertex buffer, I can see positions (OUTPUT.xy) to be numbers like 1e+38 etc. Tha rand function return numbers in [0,1], so there is no reason why x and y should end in such high values (run time of app is aprox 5s, before I pause it and examine buffers).

Also, I dotn see the reason for app to fullfill the shader condition for RebornParticle, since the initalized z is always 0 and w is always > 0. It seems to me, that input values to transform feedback are not inited, but on the other hand, on Win32 all is OK and rendering  buffers without transform feedback gives correct initial result.

If I dont run transform feedback and just render initialized buffers, I can see correct random points on the screen at their initial positions.

Here is my code (only relevant parts)

typedef struct WindParticle
{
float x;
float y;
float t;
float maxT;
} WindParticle;

Initialization:

    auto mt = std::mt19937(rd());
auto dist01 = std::uniform_real_distribution<float>(0.0f, 1.0f);

std::vector<WindParticle> particles;
for (int i = 0; i < particlesCount; i++)
{
WindParticle wp;
wp.x = dist01(mt);
wp.y = dist01(mt);
wp.t = 0;
wp.maxT = 5 * dist01(mt);

particles.push_back(wp);
}

GL_CHECK(glGenTransformFeedbacks(2, transformFeedback));
GL_CHECK(glGenBuffers(2, vertexBuffer));

for (int i = 0; i < 2; i++)
{
GL_CHECK(glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedback[i]));
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[i]));
GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(WindParticle) * particles.size(), particles.data(), GL_DYNAMIC_DRAW));
GL_CHECK(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vertexBuffer[i]));
}

//init transform feedback vao
int posId = ef->attributes["PARTICLE_DATA"][0]->location;

GL_CHECK(glGenVertexArrays(2, this->transformFeedbackVao));

for (int i = 0; i < 2; i++)
{
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[i]));
GL_CHECK(glBindVertexArray(this->transformFeedbackVao[i]));

GL_CHECK(glEnableVertexAttribArray(posId));
GL_CHECK(glVertexAttribPointer(posId, 4, GL_FLOAT, GL_FALSE, sizeof(WindParticle), 0)); // x, y, time, maxTime
}

//init render vao
posId = ef->attributes["PARTICLE_DATA"][0]->location;

GL_CHECK(glGenVertexArrays(2, this->renderVao));

for (int i = 0; i < 2; i++)
{
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[i]));
GL_CHECK(glBindVertexArray(this->renderVao[i]));

GL_CHECK(glEnableVertexAttribArray(posId));
GL_CHECK(glVertexAttribPointer(posId, 2, GL_FLOAT, GL_FALSE, sizeof(WindParticle), (const GLvoid*)0));  // x, y
}

GL_CHECK(glBindVertexArray(0));
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0));

//init default id
currVB = 0;
currTFB = 1;

Update:

    G_Effect * ef = MyGraphics::G_ShadersSingletonFactory::Instance()->GetEffect("particle_position_update");
ef->SetFloat("rndSeed", dist01(mt));

ef->Start();

GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[currVB]));
GL_CHECK(glBindVertexArray(this->transformFeedbackVao[currVB]));

GL_CHECK(glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedback[currTFB]));
GL_CHECK(glBeginTransformFeedback(GL_POINTS));
GL_CHECK(glDrawArrays(GL_POINTS, 0, this->particlesCount));
GL_CHECK(glEndTransformFeedback());
GL_CHECK(glBindVertexArray(0));

ef->End();

Render:

    G_Effect * ef = MyGraphics::G_ShadersSingletonFactory::Instance()->GetEffect("particle_position_render");

ef->Start();
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[currTFB]));
GL_CHECK(glBindVertexArray(this->renderVao[currTFB]));

GL_CHECK(glDrawArrays(GL_POINTS, 0, this->particlesCount));

GL_CHECK(glBindVertexArray(0));

ef->End();

currVB = currTFB;
currTFB = (currTFB + 1) & 0x1;

And in shader, I have created juat a dummy update:

#version 300 es //for iOS ... in Win32, there is #vesrion 330
in vec4 PARTICLE_DATA;
out vec4 OUTPUT;

uniform float rndSeed;

float rand(vec2 co)
{
float a = 12.9898;
float b = 78.233;
float c = 43758.5453;
float dt = dot(co.xy, vec2(a, b));
float sn = mod(dt, 3.14);
return fract(sin(sn) * c);
}

vec4 RebornParticle(vec4 old)
{
vec4 p = vec4(0.0);
p.x = rand(old.xy * rndSeed);
p.y = rand(old.yx * rndSeed);

p.z = 0.0;
p.w = old.w;
return p;
}

void main()
{
vec4 p = PARTICLE_DATA;

p.x += 1.0;
if (p.z > p.w)
{
OUTPUT = RebornParticle(p);
return;
}

OUTPUT = p;
}


Edited by Martin Perry

##### Share on other sites

Have you set up the transform feedback varyings before linking the shader program?

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627667
• Total Posts
2978532
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 10
• 12
• 22
• 13