Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Trying to get my rendering working with DX and cul

Sign in to follow this  


I am about to pull my hair out!!!!! With DX I am trying to do what I have in OpenGL and its driving me nuts. So far I am trying to use view frutsum culling and patches for my terrain and thats not working out... I can render one huge chunk and when I try to render more than one chunk my mesh is all screwed up! I can't figure out the DrawIndexedPrimitive(). One book I read says the parameters are for the VB and another the IB. Then one site says the minIndex + this = that?????? Good grief GL's calls are much better if thats the case. I am not sure what I should be sending to the parameters with all the confusion and have tried almost ever combo and still get nothing... Any ideas you DX gurus?

On the GL front looks like Khronos stated today that GL will run full force under Vista and may actually fun faster they say. So will Aero UI work with GL now also? This bit of info would be nice to know.

Anyway back to pull hair out... :(
Sign in to follow this  


Recommended Comments

Theres a nice section about DrawIndexedPrimitive in Tom Forsyth’s blog. It's about 90% down the page, called (surprisingly) DrawIndexedPrimitive.
At least, that should get you started.
Hope this helps.

Share this comment

Link to comment
Original post by DukeAtreides076
Yeah, I always though the DIP parameters were pretty bizarre. Have you tried reading through this article?

Hmm not sure that is applicable to what I am trying to do. I have one huge VB and one huge IB that store all the vertices and indices for the whole mesh. I just have the IB holding all the vertices rendering orders, but loop however many times I need to for the amount of patches I have. e.g. 65x65 terrain mesh with a 33x33 patch will loop 4 times in the rendering function. So I build the VB once with all my data. Then the IB I loop through all the patches in this case 4 times and upload all the index data into one IB. I am not sure DX can do this? I do it in GL so I am not sure what I am doing wrong on the DX side. I just wanted to make sure my call is correct... Thanks for the link though.

Share this comment

Link to comment
Original post by sirob
Theres a nice section about DrawIndexedPrimitive in Tom Forsyth’s blog. It's about 90% down the page, called (surprisingly) DrawIndexedPrimitive.
At least, that should get you started.
Hope this helps.

Yeah I read it, but its Greek to me! The whole part here I can't get my head around it...

HRESULT DrawIndexedPrimitive(
20, // INT BaseVertexIndex,
3, // UINT MinIndex,
5, // UINT NumVertices,
6, // UINT StartIndex,
3 // UINT PrimitiveCount

You have told it that you are only using vertices from MinIndex=3 to (MinIndex+NumVertices)=8, not including the last one, so you say you are only using vertices 3 to 7. Which is true - only the numbers 3 to 7 appear in this draw, even though other vertices are used elsewhere in the index buffer.

Then BaseVertexIndex is added to the indices before the vertices are fetched from the vertex buffer. So the vertex numbers actually used will be:

23,24,25, 24,25,26, 26,25,27

...and the software T&L pipe will know it only needs to transform vertices 23 to 27 inclusive.

what about 20? and is 20 a vertex index starting point? then onto minIndex =3? and the 8 he comes up with? well 3-7 isn't 8 and if you count them its still not 8 its 9 total? Like I said it to confusing IMO... I am lost but here is my code...

for(unsigned long z = 0; z < (mapData.map_Z - 1) / (PATCH_SIZE - 1); ++z)
for(unsigned long x = 0; x < (mapData.map_X - 1) / (PATCH_SIZE - 1); ++x)
maxX = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].maxX;
maxY = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].maxY;
maxZ = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].maxZ;
minX = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].minX;
minY = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].minY;
minZ = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].minZ;

// Check to see if the corners of the patches are within the frustum.
if (!gCamera.pointInFrustum(maxX, maxY, maxZ) &&
!gCamera.pointInFrustum(minX, maxY, minZ) &&
!gCamera.pointInFrustum(minX, maxY, maxZ) &&
!gCamera.pointInFrustum(maxX, maxY, minZ) &&
!gCamera.pointInFrustum(maxX, minY, maxZ) &&
!gCamera.pointInFrustum(minX, minY, minZ) &&
!gCamera.pointInFrustum(minX, minY, maxZ) &&
!gCamera.pointInFrustum(maxX, minY, minZ))
indicesSum += NUM_INDICES;
dxApp.d3dDevice->DrawIndexedPrimitive(type, 0, 0, NUM_VERTICES, indicesSum, NUM_POLYGONS);
indicesSum += NUM_INDICES;

//IB setup

unsigned long currentIndex = 0;
unsigned long index = 0;
unsigned long index1 = 0;
unsigned long index2 = 0;
unsigned long index3 = 0;
unsigned long startx = 0;
unsigned long startz = 0;
unsigned long endx = 0;
unsigned long endz = 0;
unsigned long rows = ((mapData.map_Z - 1) / (PATCH_SIZE - 1));
unsigned long columns = ((mapData.map_X - 1) / (PATCH_SIZE - 1));
float maxX = 0.0f, maxY = 0.0f, maxZ = 0.0f;
float minX = 0.0f, minY = 0.0f, minZ = 0.0f;


// Calculate the triangle index lists for each patch
for(unsigned long z = 0; z < rows; ++z)
for(unsigned long x = 0; x < columns; ++x)
index = z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x;

// Calculate the extents of the chunk.
startx = x * PATCH_SIZE;
startz = z * PATCH_SIZE;
endx = startx + PATCH_SIZE;
endz = startz + PATCH_SIZE;

index1 = (startz * mapData.map_X + startx);
maxX = float(startx);
minX = float(startx);
maxY = vertices[index1].pos.y;
minY = vertices[index1].pos.y;
maxZ = float(startz);
minZ = float(startz);

// Loop through the chunk extents and create the list.
indexBuffer->Lock(0, 0, (void**)&patch[index].index_buffer, 0);
for(unsigned long zz = startz; zz < endz - 1; ++zz) <

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!