1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00
XNI/Classes/Retronator/Xni/Framework/Content/IndexBufferReader.m
Matej Jan d5b2897d8b Added 3D Model support.
git-svn-id: http://xni.googlecode.com/svn/XNI@42 ac433895-eea3-a490-d80a-17149a75e588
2010-11-30 23:26:03 +00:00

41 lines
1.2 KiB
Objective-C

//
// IndexBufferReader.m
// XNI
//
// Created by Matej Jan on 23.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import "IndexBufferReader.h"
#import "Retronator.Xni.Framework.Content.h"
#import "Retronator.Xni.Framework.Graphics.h"
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
@implementation IndexBufferReader
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
IndexCollection *content = input.content;
GraphicsDevice *graphicsDevice = [[input.contentManager.serviceProvider getServiceOfType:@protocol(IGraphicsDeviceService)] graphicsDevice];
// Create an index array.
ShortIndexArray *indexArray = [[[ShortIndexArray alloc] initWithInitialCapacity:content.count] autorelease];
for (NSNumber *index in content) {
short shortIndex = (short)[index intValue];
[indexArray addIndex:shortIndex];
}
// Create the buffer.
IndexBuffer *buffer = [[[IndexBuffer alloc] initWithGraphicsDevice:graphicsDevice
indexElementSize:IndexElementSizeSixteenBits
indexCount:content.count
usage:BufferUsageWriteOnly] autorelease];
// Load data from array to buffer.
[buffer setData:indexArray];
return buffer;
}
@end