소스 검색

ios: texture loading test.

legacy
Sam Hocevar sam 14 년 전
부모
커밋
4667bbfb47
3개의 변경된 파일50개의 추가작업 그리고 10개의 파일을 삭제
  1. +2
    -0
      src/Makefile.am
  2. +47
    -10
      src/image.cpp
  3. +1
    -0
      src/image.mm

+ 2
- 0
src/Makefile.am 파일 보기

@@ -20,3 +20,5 @@ liblol_a_SOURCES = \
debugquad.cpp debugquad.h debugquad.cpp debugquad.h
liblol_a_CPPFLAGS = @LOL_CFLAGS@ liblol_a_CPPFLAGS = @LOL_CFLAGS@


EXTRA_DIST = image.mm


+ 47
- 10
src/image.cpp 파일 보기

@@ -15,7 +15,9 @@
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>


#if defined USE_SDL #if defined __APPLE__ && defined __MACH__
#
#elif defined USE_SDL
# include <SDL.h> # include <SDL.h>
# include <SDL_image.h> # include <SDL_image.h>
#elif defined ANDROID_NDK #elif defined ANDROID_NDK
@@ -45,14 +47,16 @@ private:
vec2i size; vec2i size;
Image::format_t format; Image::format_t format;


#if defined USE_SDL #if defined __APPLE__ && defined __MACH__
uint8_t *pixels;
#elif defined USE_SDL
SDL_Surface *img; SDL_Surface *img;
#elif defined ANDROID_NDK #elif defined ANDROID_NDK
jobject bmp; jobject bmp;
jintArray array; jintArray array;
jint *pixels; jint *pixels;
#else #else
uint8_t *dummy; uint8_t *pixels;
#endif #endif
}; };


@@ -63,7 +67,36 @@ private:
Image::Image(char const *path) Image::Image(char const *path)
: data(new ImageData()) : data(new ImageData())
{ {
#if defined USE_SDL #if defined __APPLE__ && defined __MACH__
NSString *path = [[NSBundle mainBundle] pathForResource:@"ascii" ofType:@"png"];
NSData *pngdata = [[NSData alloc] initWithContentsOfFile:path];
UIImage *image = [[UIImage alloc] initWithData:pngdata];
if (!image)
{
#if !LOL_RELEASE
fprintf(stderr, "ERROR: could not load %s\n", path);
#endif
exit(1);
}

int w = CGImageGetWidth(image.CGImage);
int h = CGImageGetHeight(image.CGImage);
data->size = vec2i(w, h);
data->format = FORMAT_RGBA;

CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
data->pixels = (uint8_t *)malloc(w * h * 4);
CGContextRef ctx =
CGBitmapContextCreate(data->pixels, w, h, 8, 4 * w, cspace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(cspace);
CGContextClearRect(ctx, CGRectMake(0, 0, w, h));
CGContextTranslateCTM(ctx, 0, h - h);
CGContextDrawImage(ctx, CGRectMake(0, 0, w, h), image.CGImage);
CGContextRelease(ctx);
[image release];
[pngdata release];
#elif defined USE_SDL
for (char const *name = path; *name; name++) for (char const *name = path; *name; name++)
if ((data->img = IMG_Load(name))) if ((data->img = IMG_Load(name)))
break; break;
@@ -113,8 +146,8 @@ Image::Image(char const *path)
#else #else
data->size = 256; data->size = 256;
data->format = FORMAT_RGBA; data->format = FORMAT_RGBA;
data->dummy = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*data->dummy)); data->pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*data->pixels));
uint8_t *parser = data->dummy; uint8_t *parser = data->pixels;
for (int j = 0; j < 256; j++) for (int j = 0; j < 256; j++)
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
{ {
@@ -138,18 +171,22 @@ Image::format_t Image::GetFormat() const


void * Image::GetData() const void * Image::GetData() const
{ {
#if defined USE_SDL #if defined __APPLE__ && defined __MACH__
return data->pixels;
#elif defined USE_SDL
return data->img->pixels; return data->img->pixels;
#elif defined ANDROID_NDK #elif defined ANDROID_NDK
return data->pixels; return data->pixels;
#else #else
return data->dummy; return data->pixels;
#endif #endif
} }


Image::~Image() Image::~Image()
{ {
#if defined USE_SDL #if defined __APPLE__ && defined __MACH__
free(data->pixels);
#elif defined USE_SDL
SDL_FreeSurface(data->img); SDL_FreeSurface(data->img);
#elif defined ANDROID_NDK #elif defined ANDROID_NDK
jclass cls = g_env->GetObjectClass(g_ctx); jclass cls = g_env->GetObjectClass(g_ctx);
@@ -163,7 +200,7 @@ Image::~Image()
g_env->CallVoidMethod(g_ctx, mid, data->bmp); g_env->CallVoidMethod(g_ctx, mid, data->bmp);
g_env->DeleteGlobalRef(data->bmp); g_env->DeleteGlobalRef(data->bmp);
#else #else
free(data->dummy); free(data->pixels);
#endif #endif
delete data; delete data;
} }


+ 1
- 0
src/image.mm 파일 보기

@@ -0,0 +1 @@
#include "image.cpp"

||||||
x
 
000:0
불러오는 중...
취소
저장