Jump to content
  • Advertisement
Sign in to follow this  
Monkan

FSAA opengl

This topic is 2944 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 I'm just starting to look into graphics programming and was trying to do Full Screen Anti-aliasing using mean filtering in openGL just as an example for myself.

How I'm doing it at the moment is really slow and I can see why as it has to do lots of things each draw call. Can anyone advise some optimisation I might use, I've read that glReadPixels is very slow and the fact it is looping loads of times cant help.

Here is my code:


int windowWidth3 = windowWidth * 3;
int windowHeight3 = windowHeight * 3;
int screenSize = windowWidth3 * windowHeight3;
float* bitmapData;
bitmapData = new float[screenSize];

//Read all the pixels from the screen into an array
glReadPixels(0, 0, windowWidth, windowHeight, GL_RGB, GL_FLOAT, bitmapData);

int currentPixel = 0; //stores the current center pixel
float average = 0; //stores the average of the current and all the surrounding pixels
for(int i = 0; i < windowWidth3; i += 3) //Loop through the rows of the array
{
for(int j = 0; j < windowHeight3; j += 3) //Loop through the columns of the array
{
for(int h = 0; h < 3; h++) //Loop through the r, g and b values for each pixel
{
if(currentPixel > 3 && currentPixel < screenSize - 3)
{
average += bitmapData[currentPixel]; //Center pixel
average += bitmapData[currentPixel + 3 + h]; //Right pixel
average += bitmapData[currentPixel - 3 + h]; //Left pixel
}

if(currentPixel - windowHeight3 > 3)
{
average += bitmapData[currentPixel - windowHeight3]; //Top pixel
average += bitmapData[currentPixel - windowHeight3 - 3 + h]; //Top-Left pixel
average += bitmapData[currentPixel - windowHeight3 + 3 + h]; //Top-Right pixel
}

if(currentPixel + windowHeight3 < screenSize - 3)
{
average += bitmapData[currentPixel + windowHeight3]; //Bottom pixel
average += bitmapData[currentPixel + windowHeight3 - 3 + h]; //Bottom-Left pixel
average += bitmapData[currentPixel + windowHeight3 + 3 + h]; //Bottom-Right pixel
}

average /= 9; //Take the average

bitmapData[currentPixel + h] = average; //Change the value
}

currentPixel += 3;
}
}

//Draw all the pixels back onto the screen
glDrawPixels(windowWidth, windowHeight, GL_RGB, GL_FLOAT, bitmapData);



The internet has not really offered me any advice.

Help please........

Thanks

Share this post


Link to post
Share on other sites
Advertisement
Thanks, I've been looking into shaders now and it all seems really fun, just got some simple ones working so I'll try doing what you suggest. Thanks

Share this post


Link to post
Share on other sites
FSAA in software is rarely a good idea.

OpenGL has built-in support for one style of anti-aliasing (supersampling), and others can be accomplished using shaders, with varying degrees of quality and performance.

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!