//----------------------------------------------------------------// MOAIVertexFormatMgr::MOAIVertexFormatMgr () { MOAIVertexFormat* format; format = &this->mFormats [ XYZWC ]; format->DeclareAttribute ( XYZWC_POSITION, GL_FLOAT, 4, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZWC_COLOR, GL_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); format = &this->mFormats [ XYZWUVC ]; format->DeclareAttribute ( XYZWUVC_POSITION, GL_FLOAT, 4, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZWUVC_TEXCOORD, GL_FLOAT, 2, MOAIVertexFormat::ARRAY_TEX_COORD, false ); format->DeclareAttribute ( XYZWUVC_COLOR, GL_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); }
//----------------------------------------------------------------// void MOAIGfxDevice::DrawPrims ( const MOAIVertexFormat& format, GLenum primType, void* buffer, u32 size ) { if ( !( buffer && size )) return; this->Flush (); this->SetVertexFormat (); // load the software render state //glColor4f ( this->mPenColor.mR, this->mPenColor.mG, this->mPenColor.mB, this->mPenColor.mA ); // TODO //glMatrixMode ( GL_MODELVIEW ); //MOAIGfxDevice::LoadMatrix ( this->mModelToWorldMtx ); // //glMatrixMode ( GL_TEXTURE ); //MOAIGfxDevice::LoadMatrix ( this->mUVTransform ); // draw the prims u32 nVerts = ( u32 )( size / format.GetVertexSize ()); if ( nVerts ) { if ( this->mIsProgrammable ) { format.BindProgrammable ( buffer ); glDrawArrays ( primType, 0, nVerts ); format.UnbindProgrammable (); } else { format.BindFixed ( buffer ); glDrawArrays ( primType, 0, nVerts ); format.UnbindFixed (); } } // reset //glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ); //glMatrixMode ( GL_MODELVIEW ); //glLoadIdentity (); //glMatrixMode ( GL_TEXTURE ); // glLoadIdentity (); }
//----------------------------------------------------------------// MOAIVertexFormat* MOAIVertexFormatMgr::GetFormat ( u32 formatID ) { MOAIVertexFormat* format = 0; if ( formatID < TOTAL_FORMATS ) { format = this->mFormats [ formatID ]; if ( !format ) { format = new MOAIVertexFormat (); this->LuaRetain ( format ); switch ( formatID ) { case XYZC: format->DeclareAttribute ( XYZC_POSITION, ZGL_TYPE_FLOAT, 3, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZC_COLOR, ZGL_TYPE_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); break; case XYZWC: format->DeclareAttribute ( XYZWC_POSITION, ZGL_TYPE_FLOAT, 4, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZWC_COLOR, ZGL_TYPE_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); break; case XYZWUVC: format->DeclareAttribute ( XYZWUVC_POSITION, ZGL_TYPE_FLOAT, 4, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZWUVC_TEXCOORD, ZGL_TYPE_FLOAT, 2, MOAIVertexFormat::ARRAY_TEX_COORD, false ); format->DeclareAttribute ( XYZWUVC_COLOR, ZGL_TYPE_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); break; case XYZWNNNC: format->DeclareAttribute ( XYZWNNNC_POSITION, ZGL_TYPE_FLOAT, 4, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZWNNNC_NORMAL, ZGL_TYPE_FLOAT, 3, MOAIVertexFormat::ARRAY_NORMAL, false ); format->DeclareAttribute ( XYZWNNNC_COLOR, ZGL_TYPE_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); break; case XYZWNNNUVC: format->DeclareAttribute ( XYZWNNNUVC_POSITION, ZGL_TYPE_FLOAT, 4, MOAIVertexFormat::ARRAY_VERTEX, false ); format->DeclareAttribute ( XYZWNNNUVC_NORMAL, ZGL_TYPE_FLOAT, 3, MOAIVertexFormat::ARRAY_NORMAL, false ); format->DeclareAttribute ( XYZWNNNUVC_TEXCOORD, ZGL_TYPE_FLOAT, 2, MOAIVertexFormat::ARRAY_TEX_COORD, false ); format->DeclareAttribute ( XYZWNNNUVC_COLOR, ZGL_TYPE_UNSIGNED_BYTE, 4, MOAIVertexFormat::ARRAY_COLOR, true ); break; } this->mFormats [ formatID ] = format; } } return format; }