2010-09-16 17:49:35 +00:00
|
|
|
//
|
|
|
|
// Texture2DContentTypeReader.m
|
|
|
|
// XNI
|
|
|
|
//
|
|
|
|
// Created by Matej Jan on 10.9.10.
|
|
|
|
// Copyright 2010 Retronator. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2010-11-30 23:26:03 +00:00
|
|
|
#import "Texture2DReader.h"
|
2010-09-16 17:49:35 +00:00
|
|
|
|
|
|
|
#import "Retronator.Xni.Framework.Content.h"
|
|
|
|
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
|
|
|
#import "Retronator.Xni.Framework.Graphics.h"
|
|
|
|
|
2010-11-30 23:26:03 +00:00
|
|
|
@implementation Texture2DReader
|
2010-09-16 17:49:35 +00:00
|
|
|
|
|
|
|
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
|
|
|
Texture2DContent *content = input.content;
|
|
|
|
|
|
|
|
GraphicsDevice *graphicsDevice = [[input.contentManager.serviceProvider getServiceOfType:@protocol(IGraphicsDeviceService)] graphicsDevice];
|
|
|
|
MipmapChain *mipmaps = content.mipmaps;
|
|
|
|
BOOL generateMipmaps = [mipmaps count] > 1;
|
|
|
|
BitmapContent *bitmap = [mipmaps objectAtIndex:0];
|
|
|
|
SurfaceFormat format;
|
|
|
|
[bitmap tryGetFormat:&format];
|
|
|
|
|
2010-11-30 23:26:03 +00:00
|
|
|
Texture2D *texture = [[[Texture2D alloc] initWithGraphicsDevice:graphicsDevice
|
2010-09-21 21:46:53 +00:00
|
|
|
width:bitmap.width
|
|
|
|
height:bitmap.height
|
|
|
|
mipMaps:generateMipmaps
|
2010-11-30 23:26:03 +00:00
|
|
|
format:format] autorelease];
|
2010-09-16 17:49:35 +00:00
|
|
|
|
|
|
|
for (int i=0;i<[mipmaps count];i++) {
|
|
|
|
bitmap = [mipmaps objectAtIndex:i];
|
2010-12-08 04:57:47 +00:00
|
|
|
[texture setDataToLevel:i sourceRectangle:nil from:(void*)[[bitmap getPixelData] bytes]];
|
2010-09-16 17:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|