PDA

View Full Version : Problems with VTF



k_szczech
08-03-2006, 07:40 AM
I'm implementing a simple 2D particle system but sampling a texture in vertex shader returns vec4(0, 0, 0, 0) under some circumstances despite the texture is filled with random data.

I use my own framework, but it's API is clear enough to post a code without rewritting it. I'll just explain what are the objects I use:

texState1 - 128x128 texture, RGBA32F, GL_NEAREST
-red and green components store positions of particles
texState2 - same as above (used for ping-pong updating)
tgtState2 - FBO with texState2 attached, no depth buffer

simShader2 - shader that offsets a polygon (in 2D) using VTF

My code looks like this (I have simplified it to update from state 1 to state 2 only - no ping-pong):

////// STEP 1 - update the state2 texture //////
texState1->Use(); //bind first texture
tgtState2->Use(); //bind second render target (render to second texture)

// the line below causes problems //
texState1->Enable(); //glEnable(GL_TEXTURE_2D)
fog::Shader::Disable(); //disable GLSL shader

glDisable(GL_BLEND);
glColor3ub(255, 255, 255);
glViewport(0, 0, 128, 128); //all textures are 128 x 128
glBegin(GL_POINTS); //render just one point - leave rest of texture unchanged
glTexCoord2f(0.5f, 0.5f); glVertex2f(0.25f, 0.25f);
glEnd();
texState1->Disable();

////// STEP 2 - render particles using state2 texture //////

fog::RenderTarget::GetDefault()->Use();
fog::vec2i size(fog::RenderTarget::GetDefault()->GetSize());
glViewport(0, 0, size.x, size.y);

texState2->Use(); //bind the texture we just rendered to
texState1->Enable(); //glEnable(GL_TEXTURE_2D
simShader2->Use(); //use GLSL shader with VTF

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
fog::si32 x, y;
for (y = 0; y < 128; y++)
{
float ty = (float)y / 128.0f;
for (x = 0; x < 128; x++)
{
float tx = (float)x / 128.0f;
glTexCoord2f(tx, ty);
glVertex2f(-1.0f, -1.0f);
glVertex2f( 1.0f, -1.0f);
glVertex2f( 1.0f, 1.0f);
glVertex2f(-1.0f, 1.0f);
}
}
glEnd();
texState1->Disable();It works fine (particles are rendered according to what's in texState2) as long as I don't use texState1 when rendering that GL_POINT to texState2.
I can render anything I want to texState2 - it will affect particle positions - I just can't use texState1 when rendering to texState2 - it will cause all particles to be placed at (0,0) because VTF returns (0, 0) in vertex shader despite the texState2 is still filled with random data.

It's very unlikely this is a bug in my framework - I've been using VTF in my game wchich is based on this frameork.

I also had problems in other project when using VTF in GL_FEEDBACK mode - vertices were not offsetted by textre, although the same code worked in GL_RENDER mode.

No gl errors, FBO complete, shader is compiled successfuly.

I'm always carefull when assuming something is a driver bug. I've discovered aboud 6 driver bugs (including 4 GLSL bugs) in both ATI and NVIDIA GPU's during development of my game - most of them are fixed now. This could be another one.
Please let me know if you think I'm doing something wrong.
GeForce7800GT / Forceware 91.31

k_szczech
11-23-2006, 04:30 AM
Just received word that this is fixed in release 95 drivers. Not sure if that will also affect the problem with GL_FEEDBACK mode. If not, then I'll probably have to create another reproducer application :)