Advertisement Jump to content
Sign in to follow this  

[SOLVED] Render Lags - Issue with SetTexture Calls?

This topic is 3827 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 having trouble with my rendering system lagging up a lot when I added in the ability for the user to add in a background image to draw other things on top of. Basically think of this as your basic paint program with different layers and the background image is a textured quad that starts out with the lowest z-depth so it is rendered to the very bottom. Here is the code where I render the textured quad.
else if (l.IsBackgroundImage)
                        //render a background image - this should handle separate scaling factors based on l.bgscalefactor
                        this.VertexDeclaration(l.BmpObject.Width, l.BmpObject.Height, -.5f, -.5f);

                        device.VertexFormat = CustomVertex.PositionTextured.Format;

                        //load the texture as needed
                        if (l.Texture == null)
                            texture = new Texture(device, l.BmpObject, Usage.None, Pool.Managed);
                            device.SetTexture(0, texture);
                        } else                        
                            device.SetTexture(0, l.Texture);
                        //device.VertexFormat = CustomVertex.TransformedTextured.Format;                                               
                        device.Transform.World = Matrix.RotationZ(l.RotationAngle) * Matrix.Translation(l.XPosition, l.YPosition, zdepth);

                        device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertices);

private void VertexDeclaration(int width, int height, float modifierX, float modifierY)
            //use width and height of the bitmap to determine the positions of our triangles
            //then we will have it translated later so orient to the origin for now
            vertices = new CustomVertex.PositionTextured[6];


            vertices[0].Position = new Microsoft.DirectX.Vector3(width/2 - modifierX, height/2 - modifierY, 0f);
            vertices[0].Tu = 0;
            vertices[0].Tv = 0;

            vertices[1].Position = new Microsoft.DirectX.Vector3(-width/2 - modifierX, -height/2 - modifierY, 0f);
            vertices[1].Tu = 1;
            vertices[1].Tv = 1;

            vertices[2].Position = new Microsoft.DirectX.Vector3(width/2 - modifierX, -height/2 - modifierY, 0f);
            vertices[2].Tu = 0;
            vertices[2].Tv = 1;

            vertices[3].Position = new Microsoft.DirectX.Vector3(-width/2 - modifierX, -height/2 - modifierY, 0f);
            vertices[3].Tu = 1;
            vertices[3].Tv = 1;

            vertices[4].Position = new Microsoft.DirectX.Vector3(width/2 - modifierX, height/2 - modifierY, 0f);
            vertices[4].Tu = 0;
            vertices[4].Tv = 0;

            vertices[5].Position = new Microsoft.DirectX.Vector3(-width/2 - modifierX, height/2 - modifierY, 0f);
            vertices[5].Tu = 1;
            vertices[5].Tv = 0;


Where i'm guessing the problem is is that i'm calling .SetTexture every single frame which is probably really bad. Originally it was loading the texture off the disk every time which I KNOW is really bad so I put a check in to only load the texture the first time. The issue I have is that there are other things being rendered such as text layers or just regular polygonal shapes as well so I can't just set the texture once and leave it since other image layers would also get messed up. Is my best bet to create some sort of mesh object, texture it, and then store it in my layer object (layer object is denoted by the letter "L" in the code) to use each time? EDIT: Whoops, I forgot to actually put the texture into my layer object after loading it the first time! After I fixed that it works fine!

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!