glTexSubImage2D help

Started by
1 comment, last by Kalidor 16 years, 11 months ago
I am trying to draw a scanning radar display using a fan of 1024 textured GL_TRIANGLES. The texture is a 512 x 1024 array. I texture each triangle 'spoke' with a single row from the texture array. When I first implemented this, every time the frame was drawn I updated the whole texture

glTexSubImage2D( GL_TEXTURE_2D,
                 0,
                 0,
                 0,
                 TEXTURE_RESOLUTION_X,
                 TEXTURE_RESOLUTION_Y,
                 GL_RGBA,
                 GL_UNSIGNED_BYTE, 
                 mapTexture);

This works fine except that its quite inefficient. I wish only to update the part of the texture that is equal to the current directon of the radar scanner. I wish the remainder of the texture to remain intact and unchanged. I tried the following but it draws the same textured row across all of the spokes. The variable nCurrentSpoke runs from 0 to 1023 as the scanner rotates.

glTexSubImage2D(   GL_TEXTURE_2D,	//target
		   0,                   //level
                   0,                   //xOffset
                   m_nCurrentSpoke,     //yOffset
                   TEXTURE_RESOLUTION_X,//width
                   1,                   //height
                   GL_RGBA,             //format
                   GL_UNSIGNED_BYTE,    //type
                   mapTexture);         //pixels

The following only updates what was previously updated and is faster, but as the scanner reaches the latter part of its scan it slows down since its fetching and carrying an ever larger portion of the texture.

glTexSubImage2D(   GL_TEXTURE_2D,	//target
		   0,                   //level
                   0,                   //xOffset
                   1,                   //yOffset
                   TEXTURE_RESOLUTION_X,//width
                   m_nCurrentSpoke,     //height
                   GL_RGBA,             //format
                   GL_UNSIGNED_BYTE,    //type
                   mapTexture);         //pixels

Am I missing something here? Any help would be appreciated since I've been working on this for ages now and performance is becoming a big issue. Thanks
Advertisement
I posted the same article on the OpenGL newsgroup. The problem was that I needed to supply the row's address. The solution is below:

glTexSubImage2D(GL_TEXTURE_2D,	//target0,				//level0,				//xOffsetm_nCurrentSpoke,		//yOffsetTEXTURE_RESOLUTION_X,		//width1,				//heightGL_RGBA,			//formatGL_UNSIGNED_BYTE,		//type&checkImage[m_nCurrentSpoke][0][0]);//pixels 
I think it would be better to just forget about updating the texture completely. What I'm thinking is to just have the radar "sweep" line pointing up in the texture then just rendering a quad with this texture applied and either rotating the quad itself or the texture coordinates.

This topic is closed to new replies.

Advertisement