mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
42 lines
1.2 KiB
Objective-C
42 lines
1.2 KiB
Objective-C
//
|
|
// Texture2DContentTypeReader.m
|
|
// XNI
|
|
//
|
|
// Created by Matej Jan on 10.9.10.
|
|
// Copyright 2010 Retronator. All rights reserved.
|
|
//
|
|
|
|
#import "Texture2DReader.h"
|
|
|
|
#import "Retronator.Xni.Framework.Content.h"
|
|
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
|
#import "Retronator.Xni.Framework.Graphics.h"
|
|
|
|
@implementation Texture2DReader
|
|
|
|
- (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];
|
|
|
|
Texture2D *texture = [[[Texture2D alloc] initWithGraphicsDevice:graphicsDevice
|
|
width:bitmap.width
|
|
height:bitmap.height
|
|
mipMaps:generateMipmaps
|
|
format:format] autorelease];
|
|
|
|
for (int i=0;i<[mipmaps count];i++) {
|
|
bitmap = [mipmaps objectAtIndex:i];
|
|
[texture setDataToLevel:i sourceRectangle:nil from:(void*)[[bitmap getPixelData] bytes]];
|
|
}
|
|
|
|
return texture;
|
|
}
|
|
|
|
@end
|