//--------------------------------------------------------------------------- // // This implementation of NfGetLocalTM removes all scales from the returned // Matrix3, but also stores them in the parameter pScaleOut (if specified) // so that they can be pushed down to the geometry level. // Matrix3 U2MaxSceneExport::GetLocalTM(INode* pMaxNode, TimeValue t) { Matrix3 localScaleTM; INode* pParent = pMaxNode->GetParentNode(); if(pParent) { Matrix3 parentTM = pParent->GetNodeTM(t); Matrix3 thisTM = pMaxNode->GetNodeTM(t); localScaleTM = thisTM * Inverse(parentTM); } else localScaleTM.IdentityMatrix(); Matrix3 localNoScaleTM; localNoScaleTM = UniformMatrix(localScaleTM); return localNoScaleTM; }
// // End // void Nixin::SpriteBuffer::End( Canvas& canvas ) { // Check for validity of end call. if( !hasBegun ) { Debug::FatalError( "End was called before begin." ); } // Unmap the buffer data pointer, because we're about to draw with it. spriteDataBuffer.Unmap( GL_ARRAY_BUFFER ); // Use custom shader. gl->glUseProgram( shader->GetID() ); // Set the projection matrix, and vertex attributes in the shader. shader->SetUniform( "projection", UniformMatrix( canvas.camera.GetProjectionMatrix() ) ); shader->SetAttribute( "vertexPosition", 3, GL_FALSE, GL_FLOAT, 0, 0 ); shader->SetAttribute( "texCoords", 2, GL_FALSE, GL_FLOAT, 0, 12 * maxSpriteCount * sizeof( float ) ); shader->SetAttribute( "tint", 4, GL_FALSE, GL_FLOAT, 0, 20 * maxSpriteCount * sizeof( float ) ); // Sort sprites. if( spriteSortMode != SpriteSortMode::NO_SORTING ) { // Prepared for drawing. SortSprites(); OrderIndices(); } if( drawingMode == SpriteDrawingMode::DEPTH_TESTED ) { canvas.EnableDepthTesting(); } // This will be the total number of sprites draw. int count = 0; // While we haven't drawn all the sprites. while( count < sprites.size() ) { // We assume that at least one sprite is going to be drawn this loop. int drawCount = 1; // Set the texture sampler. shader->SetUniform<UniformSampler2D>( "spriteTexture", UniformSampler2D( sprites[count].texture, GL_TEXTURE0, false ) ); // We step through the buffer, looking for a change in texture. If we find one, then take all the sprites that are next to each, that also have the same texture. for( int i = count + 1; i < sprites.size(); i++ ) { if( sprites[count].texture == sprites[i].texture ) { drawCount++; } else { break; } } // Finally, draw this group of sprites. gl->glDrawRangeElements( GL_TRIANGLES, NULL + count * indicesPerSprite * sizeof( unsigned int ), NULL + count * indicesPerSprite * sizeof( unsigned int ) + indicesPerSprite * drawCount, indicesPerSprite * drawCount, GL_UNSIGNED_INT, ( GLvoid* )( NULL + count * indicesPerSprite * sizeof( unsigned int ) ) ); // Increase the number of sprites drawn. count += drawCount; } if( drawingMode == SpriteDrawingMode::DEPTH_TESTED ) { canvas.DisableDepthTesting(); } // Check if the sprite buffer needs to grow. if( growNextEnd ) { Grow( 2.0f ); // Set this to false, as the growing is complete. growNextEnd = false; } else { //glInvalidateBufferData( spriteBuffer->spriteDataBufferLocation ); spriteDataBuffer.SetData( GL_ARRAY_BUFFER, sizeof( float ) * 36 * maxSpriteCount ); } // Clear the sprite list. sprites.clear(); // No longer drawing. hasBegun = false; }