Community
FBX Forum
Welcome to Autodesk’s FBX Forums. Share your knowledge, ask questions, and explore popular FBX topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[SOLVED] vertex buffer object - needed for shading?

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
414 Views, 3 Replies

[SOLVED] vertex buffer object - needed for shading?

Trying to understand the examples/ViewScene code, and this came to my attention in the drawMesh function.

When drawing the mesh, the code attempts to get the vertex buffer object for the mesh if it texists:

(from "examples/ViewScene/DrawScene.cxx")

const VBOMesh * lMeshCache = static_cast<const VBOMesh *>(lMesh->GetUserDataPtr());


After the necessary deformations occur, the mesh is drawn in two ways based on whether or not the VBOMesh exists:



if (lMeshCache)
{
lMeshCache->BeginDraw(pShadingMode);
const int lSubMeshCount = lMeshCache->GetSubMeshCount();
for (int lIndex = 0; lIndex < lSubMeshCount; ++lIndex)
{
if (pShadingMode == SHADING_MODE_SHADED)
{
const KFbxSurfaceMaterial * lMaterial = pNode->GetMaterial(lIndex);
if (lMaterial)
{
const MaterialCache * lMaterialCache = static_cast<const MaterialCache *>(lMaterial->GetUserDataPtr());
if (lMaterialCache)
{
lMaterialCache->SetCurrentMaterial();
}
}
else
{
// Draw green for faces without material
MaterialCache::SetDefaultMaterial();
}
}

lMeshCache->Draw(lIndex, pShadingMode);
}
lMeshCache->EndDraw(pShadingMode);
}
else
{
// OpenGL driver is too lower and use Immediate Mode
glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
const int lPolygonCount = lMesh->GetPolygonCount();
for (int lPolygonIndex = 0; lPolygonIndex < lPolygonCount; lPolygonIndex++)
{
const int lVerticeCount = lMesh->GetPolygonSize(lPolygonIndex);
glBegin(GL_LINE_LOOP);
for (int lVerticeIndex = 0; lVerticeIndex < lVerticeCount; lVerticeIndex++)
{
glVertex3dv((GLdouble *)lVertexArray);
}
glEnd();
}
}


So it appears that if no VBO is available, the mesh is drawn as a wire frame (primitives are drawn as just lines) I do not quite understand this. I thought VBO was just to improve speed. Why should the lack of a VBO just produce a wireframe?
3 REPLIES 3
Message 2 of 4
RobertGoulet
in reply to: Anonymous

I am not the author of this sample, but I believe sometimes different mesh types, such as nurbs curves and the likes, are not converted to a VBO. But I am not sure of that. Perhaps you can go and check the part where it decides create the VBO based on the Node Attribute type, that might tell you. Of course, I agree with you, everything should be drawn using VBO, otherwise its a huge performance hit.
Robert Goulet, FBX Dev Lead
Message 3 of 4
RobertGoulet
in reply to: Anonymous

I am not the author of this sample, but I believe sometimes different mesh types, such as nurbs curves and the likes, are not converted to a VBO. But I am not sure of that. Perhaps you can go and check the part where it decides create the VBO based on the Node Attribute type, that might tell you. Of course, I agree with you, everything should be drawn using VBO, otherwise its a huge performance hit.


Also, this sample code is not written around performance, so don't use it as a reference if you intend to write a fast real-time renderer. But it shows how to get the data using the FBX SDK API at least.
Robert Goulet, FBX Dev Lead
Message 4 of 4
Anonymous
in reply to: RobertGoulet

So, I looked over the VBO initialization and it looks like a VBO is created for every mesh, provided VBO support is available. But still, what seems strange to me is that drawing a shaded model is dependent on the existance of a vertex buffer object. What happens if you don't have enough GPU memory or VBO support for whatever reason? By my understanding, that should only result in slower performance, not switching over to wire-frame rendering!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report