Jump to content
  • Advertisement
Sign in to follow this  
SmegPlaza

OpenGL Result of logical operations

This topic is 3966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, As a relative newcomer to OpenGL I have a question which I'm struggling to find a definitive answer for - maybe you guys can help me please ? I'm developing an application where I am blitting 2D, rectangular pixel arrays from one context to another, and I want to perform logical operations on the pixels as they are transferred. I've found the glLogicOp() function, in conjunction with the XOR operation, which seems to do the trick. If I blit an array of (source) pixels onto an array of pre-existing, and different, (destination) pixels, using the XOR logical operation, I would expect the resulting pixel array to be dissimilar to both the original source and destination arrays. If the source and destination arrays are the same I would expect the resulting array to be empty i.e. full of 'blank' pixels. My question is, is there a way to detect what the result of that XOR operation is ? In other words can I tell whether the resulting pixel array is empty or not ? Ideally, this should be a fast test. The pixel arrays may be large, and the test has to be done frequently, so checking every pixel individually would not be a good solution. Any suggestions you can make would be greatly appreciated. Smeg

Share this post


Link to post
Share on other sites
Advertisement
Quote:
is there a way to detect what the result of that XOR operation is ? In other words can I tell whether the resulting pixel array is empty or not ?
You can read them pixels back to main RAM and scan the array for any values !=0.
Quote:
Ideally, this should be a fast test.
It's definitely not fast.

Quote:
Any suggestions you can make would be greatly appreciated.
Sorry, can't help you.

On the other hand, if you provide more information about what you actually want to achieve - then we may come up with some ideas... [smile]
Sometimes it's better to rethink the approach instead of trying to make the bad one work.

Share this post


Link to post
Share on other sites
My source pixel array is being modified by another (uncontrollable) process, and I want to know when it stops changing.

Share this post


Link to post
Share on other sites
Quote:
Original post by SmegPlaza
My source pixel array is being modified by another (uncontrollable) process, and I want to know when it stops changing.
Something like VNC? [smile]

Ok, here is the only thing that comes to mind:

1. Grab the source & destination to the textures.
2. Draw the rect to a separate buffer.
In the fragment shader compare the colors of a source and destination and use the result to output one of two depth values (true & false).
3. Start occlusion query.
4. Draw the rect with depth test enabled, depth set to separate "true" and "false".
5. Get the result of an occlusion query.

Share this post


Link to post
Share on other sites
Sort of like VNC... but not ;)

As I said in my first post - I am something of a newbie to OpenGL so I don't really follow what you were trying to explain there Serge K.

Can you elaborate a little please ? Fragment shader ? Occlusion query ?

Thanks !

Share this post


Link to post
Share on other sites
Fragment shader replaces all the fixed fragment processing functionality -
computes colors, applies textures, etc.
GLSL Tutorial - Fragment Processor
GLSL - An Introduction

You can use it to do the following operations:
1. fetch the source and destination texels (before that get the source and destination images to the textures with glCopyTexSubImage2D) => src, dst
2. compare the colors, output the depth value as depth = (src==dst) ? z_true : z_false;
3. ouput the source color. (if you need to xor it with the destination buffer)

After that you will have the per-pixel result of comparison in the destination framebuffer's depth.
To get it all fast you can use occlusion query.
It allows to find out if any pixels have passed through the depth test.
Basically, you start the query, draw something, then read the result - number of the pixels that passed.
So, if you'll draw the rectangle with depth==z_false and the depth test set to GL_EQUAL, you'll find the number of pixels that were different.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!