//----------------------------------------------------------------// void MOAIMesh::DrawIndex ( u32 idx, MOAIMeshSpan* span, MOAIMaterialBatch& materials, ZLVec3D offset, ZLVec3D scale ) { UNUSED ( offset ); UNUSED ( scale ); materials.LoadGfxState ( this, idx, MOAIShaderMgr::MESH_SHADER ); // TODO: make use of offset and scale MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get (); this->FinishInit (); gfxDevice.BindVertexArray ( this ); if ( this->IsReady ()) { // I am super lazy, so set this up here instead of adding if's below MOAIMeshSpan defaultSpan; if ( !span ) { defaultSpan.mBase = 0; defaultSpan.mTop = this->mTotalElements; defaultSpan.mNext = 0; span = &defaultSpan; } gfxDevice.SetVertexMtxMode ( MOAIGfxDevice::VTX_STAGE_MODEL, MOAIGfxDevice::VTX_STAGE_MODEL ); gfxDevice.SetUVMtxMode ( MOAIGfxDevice::UV_STAGE_MODEL, MOAIGfxDevice::UV_STAGE_TEXTURE ); gfxDevice.SetPenWidth ( this->mPenWidth ); gfxDevice.UpdateShaderGlobals (); // TODO: use gfxDevice to cache buffers if ( this->mIndexBuffer ) { gfxDevice.BindIndexBuffer ( this->mIndexBuffer ); if ( this->mIndexBuffer->IsReady ()) { u32 indexSizeInBytes = this->mIndexBuffer->GetIndexSize (); for ( ; span; span = span->mNext ) { zglDrawElements ( this->mPrimType, span->mTop - span->mBase, indexSizeInBytes == 2 ? ZGL_TYPE_UNSIGNED_SHORT : ZGL_TYPE_UNSIGNED_INT, ( const void* )(( size_t )this->mIndexBuffer->GetAddress () + ( span->mBase * indexSizeInBytes )) ); } gfxDevice.BindIndexBuffer (); } } else { for ( ; span; span = span->mNext ) { zglDrawArrays ( this->mPrimType, span->mBase, span->mTop - span->mBase ); } } gfxDevice.BindVertexArray (); } }
//----------------------------------------------------------------// void MOAIMesh::DrawIndex ( u32 idx, float xOff, float yOff, float zOff, float xScl, float yScl, float zScl ) { UNUSED ( idx ); UNUSED ( xOff ); UNUSED ( yOff ); UNUSED ( zOff ); UNUSED ( xScl ); UNUSED ( yScl ); UNUSED ( zScl ); // TODO: make use of offset and scale if ( !this->mVertexBuffer ) return; if ( this->mVertexBuffer->Bind ()) { MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get (); gfxDevice.SetVertexMtxMode ( MOAIGfxDevice::VTX_STAGE_MODEL, MOAIGfxDevice::VTX_STAGE_MODEL ); gfxDevice.SetUVMtxMode ( MOAIGfxDevice::UV_STAGE_MODEL, MOAIGfxDevice::UV_STAGE_TEXTURE ); gfxDevice.SetGfxState ( this->mTexture ); gfxDevice.SetPenWidth ( this->mPenWidth ); gfxDevice.SetPointSize ( this->mPointSize ); // TODO: use gfxDevice to cache buffers if ( this->mIndexBuffer ) { if ( this->mIndexBuffer->LoadGfxState ()) { zglDrawElements ( this->mPrimType, this->mIndexBuffer->GetIndexCount (), ZGL_TYPE_UNSIGNED_SHORT, 0 ); this->mIndexBuffer->Unbind(); } } else { zglDrawArrays ( this->mPrimType, 0, this->mVertexBuffer->GetVertexCount ()); } this->mVertexBuffer->Unbind(); } }