Original Post
I have been working on a 2d engine/game for a while now and its finally playable and becoming quite enjoyable so now I would like to go back and improve upon it. From reading articles about 2d drawing I think I have some fundamental issues that may be easy to fix but I don't fully understand how to do it and was hoping for some tips.
Most of my render code ends up calling one function,
One of the tips I often read about optimizing 2d drawing is to limit the DrawPrimitive calls. The problem is I dont see how I can do this. In my draw function I create a list of visible actors in order of their z position and then render them. Each actor may use a different texture which I thought made this impossible but maybe I misunderstand how batch drawing works.
I also often see that its better for performance to use 1 big texture than a group of smaller textures but it is not clear to me the intended goal. Is this to limit switching the active texture or just to limit the texture count?
Any hints or tips would be greatly appreciated. Or even a good book recommendation. I have looked for books but most are general DirectX programming which I know would help but I'd love to find something focused on 2d.
Most of my render code ends up calling one function,
void Renderer::drawImage(Image* image, Box_BL* dest, float rotate, bool flip){ float X; float Y; D3DXMATRIX matTranslation; D3DXMATRIX matScaling; D3DXMATRIX matTransform; d3ddev->SetFVF (D3DFVF_TLVERTEX); //Get coordinates X = dest->left() - (float)(this->width) / 2; Y = -height + ((float)(this->height) / 2) + dest->top(); float dWidth = dest->width(); float dHeight = dest->height(); //Setup translation and scaling matrices D3DXMatrixScaling (&matScaling, dWidth, dHeight, 1.0f); D3DXMatrixTranslation (&matTranslation, X, Y, 0.0f); matTransform = matScaling * matTranslation; //Check if quad is rotated if (rotate) { D3DXMATRIX matRotate; //Create rotation matrix about the z-axis D3DXMatrixRotationZ (&matRotate, rotate); //Multiply matrices together matTransform *= matRotate; } if (flip) d3ddev->SetStreamSource(0, reverseVertexBuffer, 0, sizeof(TLVERTEX)); else d3ddev->SetStreamSource(0, vertexBuffer, 0, sizeof(TLVERTEX)); //Draw the quad d3ddev->SetTransform (D3DTS_WORLD, &matTransform); d3ddev->SetTexture (0, image->ppTexture); d3ddev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);}One of the tips I often read about optimizing 2d drawing is to limit the DrawPrimitive calls. The problem is I dont see how I can do this. In my draw function I create a list of visible actors in order of their z position and then render them. Each actor may use a different texture which I thought made this impossible but maybe I misunderstand how batch drawing works.
I also often see that its better for performance to use 1 big texture than a group of smaller textures but it is not clear to me the intended goal. Is this to limit switching the active texture or just to limit the texture count?
Any hints or tips would be greatly appreciated. Or even a good book recommendation. I have looked for books but most are general DirectX programming which I know would help but I'd love to find something focused on 2d.