Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3DXLoadTextureFromFile

Started by f1engineer Aug 10, 2007 at 9:10 AM 4 replies 1.7k views
Original Post
f1engineer
f1engineer
Hello all I use D3DXLoadTextureFromFile function. Everything work fine, but with a problem: When loading textures in such way, rendering of the vertex buffers become very slow. It is not very nice when catch the object and begin drag it. Are there any ways to improve performance of rendering?
dave
dave
Hey,

1. The loading of the texture won't have any effect on rendering speed directly unless you are loading it from file every frame? Is this what you are doing?

2. What are you making? Sounds like a GUI of some description.

THanks,
jollyjeffers
jollyjeffers
This makes no sense at all - as Dave posted, simple texturing should have little to no effect on rendering performance. You need to be using HUGE textures or complex pixel shaders (or fixed-function blending) to really stress an GPU from the last few years...

Could you post a high-level pseudo-code listing of how you're rendering your images? Might well help us to help you.


Cheers,
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
f1engineer
f1engineer
Hi friends
Sorry for the late answer.

1. I create vertex buffers:
- Allocate memory place and initialize all the vectors of vertex buffers. This function is called one time when create the graphical objects.

- After it with created vertex buffers I call PrepareMatrices member function that move and rotate all the objects.

I do not load each time textures form file during all the interactions with the objects.

I'm sorry that I do not post any code here. I shall do it tomorrow.

regards
Kamen
f1engineer
f1engineer
I understand what You mean

1. I create vertex buffers:

- Allocate memory place and initialize all the vectors of vertex buffers. This function is called one time when create the graphical objects.

- After it with created vertex buffers I call PrepareMatrices member function that move and rotate all the objects.
------ But at this point I call each time SetTexture for each vertex buffer. My be it is a problem because i call this function in each mouse position.

Is it possible to call m_pD3DDevice->SetTexture(...) only when creating vertex buffers? If it is possible the problem is solved.


regards
Kamen
f1engineer
f1engineer
Hello all
I promise to post some code. I resolve the problem, and the cause was that I call SetTexture function during render process.

1. At function bellow I prepare my vertex buffers:

owner class:: ...CreateVertexBufferByPoints(LPDIRECT3DDEVICE9 pd3dDevice,
CPtrArray* pSrfArr, CString* pTextureFile)
{
m_nPointsCount = pSrfArr->GetSize();

pd3dDevice->CreateVertexBuffer(m_nPointsCount*sizeof(CUSTOMVERTEX), 0,
D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL);

CUSTOMVERTEX* pVertices;
m_pVB->Lock(0, 0, (void**)&pVertices, 0);

float fDivisor = (float)(1.0/((float)m_nPointsCount - 1));

CSurfacePt* pSrfPt = (CSurfacePt*)pSrfArr->GetAt(0);
CSurfacePt* pSrfPt1 = (CSurfacePt*)pSrfArr->GetAt(1);
CSurfacePt* pSrfPt2 = (CSurfacePt*)pSrfArr->GetAt(3);
CSurfacePt* pSrfPt3 = (CSurfacePt*)pSrfArr->GetAt(2);

float fScale = CDirectXTransformer::GetScale();

pVertices[0].m_pVector = D3DXVECTOR3(pSrfPt->m_dX*fScale,
pSrfPt->m_dY*fScale, pSrfPt->m_dZ*fScale);

pVertices[1].m_pVector = D3DXVECTOR3(pSrfPt1->m_dX*fScale,
pSrfPt1->m_dY*fScale, pSrfPt1->m_dZ*fScale);

pVertices[2].m_pVector = D3DXVECTOR3(pSrfPt2->m_dX*fScale,
pSrfPt2->m_dY*fScale, pSrfPt2->m_dZ*fScale);

pVertices[3].m_pVector = D3DXVECTOR3(pSrfPt3->m_dX*fScale,
pSrfPt3->m_dY*fScale, pSrfPt3->m_dZ*fScale);

//float fTV = ((float)0)*fDivisor;
float fTV = 0.0;

pVertices[0].m_color = 0xffffffff;
pVertices[0].m_fTV = fTV;
pVertices[0].m_fTU = 1.0;

fTV = ((float)1)*fDivisor;
pVertices[1].m_color = 0xff808080;
pVertices[1].m_fTV = fTV;
pVertices[1].m_fTU = 0.0;

fTV = ((float)2)*fDivisor;
pVertices[2].m_color = 0xffffffff;
pVertices[2].m_fTV = fTV;
pVertices[2].m_fTU = 1.0;

fTV = ((float)3)*fDivisor;
pVertices[3].m_color = 0xff808080;
pVertices[3].m_fTV = fTV;
pVertices[3].m_fTU = 0.0;

m_pVB->Unlock();

HRESULT hResult;
if(pTextureFile != NULL)
{
hResult = D3DXCreateTextureFromFile(pd3dDevice, *pTextureFile, &m_pTexture);
}
if(FAILED(hResult))
{
if(m_pTexture != NULL)
{
m_pTexture->Release();
m_pTexture = NULL;
}
}
}

2. After vertexes are created i call render, every time when I have selected object:

void CGS_DESIGNERView::Render()
{
m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffff, 1.0f, 0);
m_pd3dDevice->BeginScene();
SetupLights();

CGS_DESIGNERData* pGSData = GetDocument();

unsigned short nSize = pGSData->m_pRoom->GetD3DVertexSrfArrSize();
for(unsigned short q = 0; q < nSize; q++)
{
CD3DVertexSrf* pD3DSrf = (CD3DVertexSrf*)pGSData->m_pRoom->GetNextD3DVertexSrf(q);
unsigned short nVertexSize = pD3DSrf->GetVertexArrSize();

SetupMatricesDevice(pD3DSrf->GetZYAngle(), pD3DSrf->GetZXAngle(),
pD3DSrf->GetXYAngle(), pD3DSrf->GetXPos(), pD3DSrf->GetYPos(),
pD3DSrf->GetZPos());

for(unsigned short k = 0; k < nVertexSize; k++)
{
CVertexBuffer* pVertex = (CVertexBuffer*)pD3DSrf->GetNextVertexBuffer(k);



here is my mistake -> m_pd3dDevice->SetTexture(0, pVertex->m_pTexture);
I set this line in previous function where I create vertexes.



m_pd3dDevice->SetStreamSource(0, pVertex->m_pVB, 0, sizeof(CUSTOMVERTEX));
m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
m_pd3dDevice->DrawPrimitive(pVertex->m_PrimType, 0, pVertex->m_nPrimCount);
}
}
m_pd3dDevice->EndScene();
m_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}

So the problem is solved. Thank You very much
Best regards
Kamen

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.