Jump to content
  • Advertisement
Sign in to follow this  
Rmis

Too much time for a bitmap!!

This topic is 3085 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 there :) I was rendering an object composed of simple QUADS ,and this object keeps rotating along x as the rotation angle value changes every time the drawing method is called . My problem started when I tried to perform texture mapping using bitmap images . When the quads were finally textured , I found that the rotation of the object was too slow .. and then I noticed that the loadBitmap function was the one which took too much time . I'm using Tao framework with C#. Texture class :
public class Texture
    {
        #region Attributes
        public uint[] texture;
        public string path;
        public double texSStep;
        public double texTStep;
        #endregion

        #region Methods

        public Texture(string path)
        {
            texture = new uint[1];
            this.path = path;
            this.texTStep = 1.0 / 256.0;
            this.texSStep = 1.0 / 256.0;
            loadBitmap();
        }

        private void loadBitmap()
        {
            Bitmap image = null;
            System.Drawing.Imaging.BitmapData bitmapdata = null;
            Rectangle rect;
            try
            {
                image = new Bitmap(this.path);
                image.RotateFlip(RotateFlipType.RotateNoneFlipY);
                rect = new Rectangle(0, 0, image.Width, image.Height);

                bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                Gl.glGenTextures(1, texture);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[0]);

                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);	 // Linear Filtering
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);	 // Linear Filtering

                Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB8, image.Width, image.Height,
                0, Gl.GL_BGR_EXT, Gl.GL_UNSIGNED_BYTE, bitmapdata.Scan0);

            }
            catch (Exception e)
            {
                // Handle Any Exceptions While Loading Textures, Exit App
                string errorMsg = "An Error Occurred While Loading Texture:\n\t" + path + "\n" + "\n\nStack Trace:\n\t" + e.StackTrace + "\n";
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            finally
            {
                if (image != null)
                {
                    image.UnlockBits(bitmapdata);
                    image.Dispose();
                }
            }

        }

        #endregion


    }

I found out that the loader was the bottle neck when I tried to "hint" it and rebuild my project, so .. any ideas ?? Regards ..

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I found that the rotation of the object was too slow .. and then I noticed that the loadBitmap function was the one which took too much time .


Are you reloading the texture every time you draw it? This is a huge amount of data and it should only be uploaded once during initialization. Doing it every frame will definitely be very slow.

I don't know anything about Tao, but you should only have to load the texture once and then you can draw it / rotate it as many times as you want.

Share this post


Link to post
Share on other sites
Aha .. that's it !!
New textures were defined every time the Draw function was called .

Thank you karwosts :)

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!