[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [430] trunk/fuse/fusepb
Brought to you by:
fredm
|
From: <fr...@us...> - 2007-07-13 13:51:01
|
Revision: 430
http://svn.sourceforge.net/fuse-for-macosx/?rev=430&view=rev
Author: fredm
Date: 2007-07-13 06:49:45 -0700 (Fri, 13 Jul 2007)
Log Message:
-----------
Factor out some icon texture loading bits.
Modified Paths:
--------------
trunk/fuse/fusepb/Fuse.xcodeproj/project.pbxproj
trunk/fuse/fusepb/views/DisplayOpenGLView.h
trunk/fuse/fusepb/views/DisplayOpenGLView.m
Added Paths:
-----------
trunk/fuse/fusepb/views/Texture.h
trunk/fuse/fusepb/views/Texture.m
Modified: trunk/fuse/fusepb/Fuse.xcodeproj/project.pbxproj
===================================================================
--- trunk/fuse/fusepb/Fuse.xcodeproj/project.pbxproj 2007-07-05 13:58:08 UTC (rev 429)
+++ trunk/fuse/fusepb/Fuse.xcodeproj/project.pbxproj 2007-07-13 13:49:45 UTC (rev 430)
@@ -292,6 +292,8 @@
B6CA2A2F0C33F8C10003CF90 /* plusd.h in Headers */ = {isa = PBXBuildFile; fileRef = B6CA2A2B0C33F8C10003CF90 /* plusd.h */; };
B6CA2A300C33F8C10003CF90 /* wd1770.c in Sources */ = {isa = PBXBuildFile; fileRef = B6CA2A2C0C33F8C10003CF90 /* wd1770.c */; };
B6CA2A310C33F8C10003CF90 /* wd1770.h in Headers */ = {isa = PBXBuildFile; fileRef = B6CA2A2D0C33F8C10003CF90 /* wd1770.h */; };
+ B6CADD570C47AD90004BA954 /* Texture.h in Headers */ = {isa = PBXBuildFile; fileRef = B6CADD550C47AD90004BA954 /* Texture.h */; };
+ B6CADD580C47AD90004BA954 /* Texture.m in Sources */ = {isa = PBXBuildFile; fileRef = B6CADD560C47AD90004BA954 /* Texture.m */; };
B6CE7F410B2830A300EB65B3 /* cocoadisplay.h in Headers */ = {isa = PBXBuildFile; fileRef = B6CE7F3B0B2830A300EB65B3 /* cocoadisplay.h */; };
B6CE7F420B2830A300EB65B3 /* cocoajoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = B6CE7F3C0B2830A300EB65B3 /* cocoajoystick.c */; };
B6CE7F440B2830A300EB65B3 /* cocoaui.h in Headers */ = {isa = PBXBuildFile; fileRef = B6CE7F3E0B2830A300EB65B3 /* cocoaui.h */; };
@@ -540,6 +542,8 @@
B6CA2A2D0C33F8C10003CF90 /* wd1770.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = wd1770.h; sourceTree = "<group>"; };
B6CA304C049CEC410037E9F2 /* psg.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = psg.c; path = ../psg.c; sourceTree = SOURCE_ROOT; };
B6CA304D049CEC410037E9F2 /* psg.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = psg.h; path = ../psg.h; sourceTree = SOURCE_ROOT; };
+ B6CADD550C47AD90004BA954 /* Texture.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Texture.h; sourceTree = "<group>"; };
+ B6CADD560C47AD90004BA954 /* Texture.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Texture.m; sourceTree = "<group>"; };
B6CC82FF0800E408006EFFB9 /* CAMachines.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = CAMachines.h; path = content_arrays/CAMachines.h; sourceTree = SOURCE_ROOT; };
B6CC83000800E408006EFFB9 /* CAMachines.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = CAMachines.m; path = content_arrays/CAMachines.m; sourceTree = SOURCE_ROOT; };
B6CD0B9E06069F4A00847338 /* fuse.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = fuse.cpp; path = ../fuse.cpp; sourceTree = SOURCE_ROOT; };
@@ -1007,6 +1011,8 @@
B6CE7FCF0B28FBEC00EB65B3 /* Views */ = {
isa = PBXGroup;
children = (
+ B6CADD550C47AD90004BA954 /* Texture.h */,
+ B6CADD560C47AD90004BA954 /* Texture.m */,
B6CE7FCB0B28FBD600EB65B3 /* DisplayOpenGLView.h */,
B6CE7FCC0B28FBD600EB65B3 /* DisplayOpenGLView.m */,
);
@@ -1328,6 +1334,7 @@
B6CA2A2F0C33F8C10003CF90 /* plusd.h in Headers */,
B6CA2A310C33F8C10003CF90 /* wd1770.h in Headers */,
B6AB34910C3BC91A0005935E /* menu.h in Headers */,
+ B6CADD570C47AD90004BA954 /* Texture.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1575,6 +1582,7 @@
B6CA2A2E0C33F8C10003CF90 /* plusd.c in Sources */,
B6CA2A300C33F8C10003CF90 /* wd1770.c in Sources */,
B6AB34900C3BC91A0005935E /* menu.c in Sources */,
+ B6CADD580C47AD90004BA954 /* Texture.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: trunk/fuse/fusepb/views/DisplayOpenGLView.h
===================================================================
--- trunk/fuse/fusepb/views/DisplayOpenGLView.h 2007-07-05 13:58:08 UTC (rev 429)
+++ trunk/fuse/fusepb/views/DisplayOpenGLView.h 2007-07-13 13:49:45 UTC (rev 430)
@@ -40,6 +40,7 @@
#define MAX_SCREEN_BUFFERS 2
@class Emulator;
+@class Texture;
@interface DisplayOpenGLView : NSOpenGLView
{
@@ -48,18 +49,12 @@
GLuint screenTexId[MAX_SCREEN_BUFFERS];
int currentScreenTex;
- Cocoa_Texture redCassetteTex;
- GLuint redCassette;
- Cocoa_Texture greenCassetteTex;
- GLuint greenCassette;
- Cocoa_Texture redMdrTex;
- GLuint redMdr;
- Cocoa_Texture greenMdrTex;
- GLuint greenMdr;
- Cocoa_Texture redDiskTex;
- GLuint redDisk;
- Cocoa_Texture greenDiskTex;
- GLuint greenDisk;
+ Texture *redCassette;
+ Texture *greenCassette;
+ Texture *redMdr;
+ Texture *greenMdr;
+ Texture *redDisk;
+ Texture *greenDisk;
BOOL screenTexInitialised;
@@ -91,23 +86,17 @@
-(void) createTexture:(Cocoa_Texture*)newScreen;
-(void) destroyTexture;
--(void) uploadIconTexture:(GLuint*)textureName
- width:(GLsizei)width
- height:(GLsizei)height
- pixels:(unsigned char *)pixels;
--(void) blitIcon:(Cocoa_Texture*)texture name:(GLuint)textureName;
+-(void) blitIcon:(Texture*)iconTexture;
-(void) setServer:(id)anObject;
-(id) initWithFrame:(NSRect)frameRect;
-(void) awakeFromNib;
-(void) loadPicture:(NSString *) name
- greenTex:(Cocoa_Texture*)greenTexture
- greenIcon:(GLuint*)greenTextureName
- redTex:(Cocoa_Texture*)redTexture
- redIcon:(GLuint*)redTextureName
- xOrigin:(int)x
- yOrigin:(int)y;
+ greenTex:(Texture*) greenTexture
+ redTex:(Texture*) redTexture
+ xOrigin:(int) x
+ yOrigin:(int) y;
-(void) setNeedsDisplayYes;
Modified: trunk/fuse/fusepb/views/DisplayOpenGLView.m
===================================================================
--- trunk/fuse/fusepb/views/DisplayOpenGLView.m 2007-07-05 13:58:08 UTC (rev 429)
+++ trunk/fuse/fusepb/views/DisplayOpenGLView.m 2007-07-13 13:49:45 UTC (rev 430)
@@ -26,6 +26,7 @@
#import "Emulator.h"
#import "FuseController.h"
#import "DebuggerController.h"
+#import "Texture.h"
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
@@ -36,54 +37,6 @@
#include "settings.h"
#include "ui/cocoa/dirty.h"
-unsigned char *
-NSBitmapImageRepToRGBAPixelArray(NSBitmapImageRep * bitmap, int red)
-{
- unsigned char * pixels;
- NSBitmapImageRep * bitmap2;
- NSGraphicsContext * context;
-#define BYTES_PER_PIXEL 4
- int targetWidth = [bitmap pixelsWide];
- int targetHeight = [bitmap pixelsHigh];
-
- pixels = (unsigned char *) malloc(BYTES_PER_PIXEL * targetWidth * targetHeight);
- bitmap2 = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: &pixels
- pixelsWide: targetWidth
- pixelsHigh: targetHeight
- bitsPerSample: 8
- samplesPerPixel: 4
- hasAlpha: YES
- isPlanar: NO
- colorSpaceName: NSDeviceRGBColorSpace
- bitmapFormat: NSAlphaNonpremultipliedBitmapFormat
- bytesPerRow: (targetWidth * BYTES_PER_PIXEL)
- bitsPerPixel: (BYTES_PER_PIXEL * 8)];
-
- context = [NSGraphicsContext graphicsContextWithBitmapImageRep: bitmap2];
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext: context];
- [bitmap drawInRect: NSMakeRect(0, 0, targetWidth, targetHeight)];
- [NSGraphicsContext restoreGraphicsState];
-
- int i;
- for( i = 0; i < targetWidth * targetHeight; i++ ) {
-#ifdef WORDS_BIGENDIAN
- pixels[i*4+3] = red ? pixels[i*4+0] : 0; // r on ppc
- pixels[i*4+2] = red ? 0 : pixels[i*4+1]; // g on ppc
- pixels[i*4+0] = 0;
- pixels[i*4+1] = 0;
-#else /* #ifdef WORDS_BIGENDIAN */
- pixels[i*4+0] = red ? pixels[i*4+0] : 0; // r on i386
- pixels[i*4+1] = red ? 0 : pixels[i*4+1]; // g on i386
- pixels[i*4+2] = 0;
-#endif /* #ifdef WORDS_BIGENDIAN */
- }
-
- [bitmap2 release];
-
- return pixels;
-}
-
const void *
get_byte_pointer(void *bitmap)
{
@@ -222,22 +175,22 @@
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
- [self loadPicture: @"cassette" greenTex:&greenCassetteTex
- greenIcon:&greenCassette
- redTex:&redCassetteTex
- redIcon:&redCassette
+ greenCassette = [Texture alloc];
+ redCassette = [Texture alloc];
+ [self loadPicture: @"cassette" greenTex:greenCassette
+ redTex:redCassette
xOrigin:285
yOrigin:220];
- [self loadPicture: @"microdrive" greenTex:&greenMdrTex
- greenIcon:&greenMdr
- redTex:&redMdrTex
- redIcon:&redMdr
+ greenMdr = [Texture alloc];
+ redMdr = [Texture alloc];
+ [self loadPicture: @"microdrive" greenTex:greenMdr
+ redTex:redMdr
xOrigin:264
yOrigin:218];
- [self loadPicture: @"plus3disk" greenTex:&greenDiskTex
- greenIcon:&greenDisk
- redTex:&redDiskTex
- redIcon:&redDisk
+ greenDisk = [Texture alloc];
+ redDisk = [Texture alloc];
+ [self loadPicture: @"plus3disk" greenTex:greenDisk
+ redTex:redDisk
xOrigin:243
yOrigin:218];
screenTexInitialised = NO;
@@ -310,18 +263,18 @@
[real_emulator release];
real_emulator = nil;
- glDeleteTextures(1, &redCassette);
- redCassette = 0;
- glDeleteTextures(1, &greenCassette);
- greenCassette = 0;
- glDeleteTextures(1, &redMdr);
- redMdr = 0;
- glDeleteTextures(1, &greenMdr);
- greenMdr = 0;
- glDeleteTextures(1, &redDisk);
- redDisk = 0;
- glDeleteTextures(1, &greenDisk);
- greenDisk = 0;
+ [redCassette release];
+ redCassette = nil;
+ [greenCassette release];
+ greenCassette = nil;
+ [redMdr release];
+ redMdr = nil;
+ [greenMdr release];
+ greenMdr = nil;
+ [redDisk release];
+ redDisk = nil;
+ [greenDisk release];
+ greenDisk = nil;
[buffered_screen_lock release];
@@ -329,12 +282,10 @@
}
-(void) loadPicture: (NSString *) name
- greenTex:(Cocoa_Texture*)greenTexture
- greenIcon:(GLuint*)greenTextureName
- redTex:(Cocoa_Texture*)redTexture
- redIcon:(GLuint*)redTextureName
- xOrigin:(int)x
- yOrigin:(int)y
+ greenTex:(Texture*) greenTexture
+ redTex:(Texture*) redTexture
+ xOrigin:(int) x
+ yOrigin:(int) y
{
NSBitmapImageRep *bitmap;
NSImage *image = [NSImage imageNamed: name];
@@ -344,28 +295,12 @@
if (bitmap == nil) NSLog(@"in loadPicture: NSBitmapImageRep not loaded");
/* Colour first image green */
- greenTexture->pixels = NSBitmapImageRepToRGBAPixelArray( bitmap, 0 );
- greenTexture->image_width = [bitmap pixelsWide];
- greenTexture->image_height = [bitmap pixelsHigh];
- greenTexture->image_xoffset = x;
- greenTexture->image_yoffset = y;
+ greenTexture = [greenTexture initWithBitmap:bitmap withXOrigin:x
+ withYOrigin:y colourRed:0];
- [self uploadIconTexture:greenTextureName
- width:greenTexture->image_width
- height:greenTexture->image_height
- pixels:greenTexture->pixels];
-
/* Colour second image red */
- redTexture->pixels = NSBitmapImageRepToRGBAPixelArray( bitmap, 1 );
- redTexture->image_width = [bitmap pixelsWide];
- redTexture->image_height = [bitmap pixelsHigh];
- redTexture->image_xoffset = x;
- redTexture->image_yoffset = y;
-
- [self uploadIconTexture:redTextureName
- width:redTexture->image_width
- height:redTexture->image_height
- pixels:redTexture->pixels];
+ redTexture = [redTexture initWithBitmap:bitmap withXOrigin:x
+ withYOrigin:y colourRed:1];
}
-(void) setNeedsDisplayYes
@@ -373,8 +308,11 @@
[super setNeedsDisplay:YES];
}
--(void) blitIcon:(Cocoa_Texture*)texture name:(GLuint)textureName
+-(void) blitIcon:(Texture*)iconTexture
{
+ Cocoa_Texture* texture = [iconTexture getTexture];
+ GLuint textureName = [iconTexture getTextureId];
+
/* Map pixel icon position to appropriate position on -1.0 to 1.0 canvas */
float target_x1 = texture->image_xoffset * 2.0f / (float)DISPLAY_ASPECT_WIDTH
- 1.0f;
@@ -409,10 +347,10 @@
{
switch( disk_state ) {
case UI_STATUSBAR_STATE_ACTIVE:
- [self blitIcon:&greenDiskTex name:greenDisk];
+ [self blitIcon:greenDisk];
break;
case UI_STATUSBAR_STATE_INACTIVE:
- [self blitIcon:&redDiskTex name:redDisk];
+ [self blitIcon:redDisk];
break;
case UI_STATUSBAR_STATE_NOT_AVAILABLE:
break;
@@ -420,10 +358,10 @@
switch( mdr_state ) {
case UI_STATUSBAR_STATE_ACTIVE:
- [self blitIcon:&greenMdrTex name:greenMdr];
+ [self blitIcon:greenMdr];
break;
case UI_STATUSBAR_STATE_INACTIVE:
- [self blitIcon:&redMdrTex name:redMdr];
+ [self blitIcon:redMdr];
break;
case UI_STATUSBAR_STATE_NOT_AVAILABLE:
break;
@@ -431,11 +369,11 @@
switch( tape_state ) {
case UI_STATUSBAR_STATE_ACTIVE:
- [self blitIcon:&greenCassetteTex name:greenCassette];
+ [self blitIcon:greenCassette];
break;
case UI_STATUSBAR_STATE_INACTIVE:
case UI_STATUSBAR_STATE_NOT_AVAILABLE:
- [self blitIcon:&redCassetteTex name:redCassette];
+ [self blitIcon:redCassette];
break;
}
}
@@ -651,28 +589,6 @@
[view_lock unlock];
}
--(void) uploadIconTexture:(GLuint*)textureName
- width:(GLsizei)width
- height:(GLsizei)height
- pixels:(unsigned char *)pixels
-{
- glGenTextures(1, textureName);
-
- /* Set memory alignment parameters for unpacking the bitmap. */
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
- /* Specify the texture's properties. */
- glBindTexture( GL_TEXTURE_RECTANGLE_EXT, *textureName );
- glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
-
- /* Upload the texture bitmap. */
- glTexImage2D( GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, width, height, 0, GL_RGBA,
- GL_UNSIGNED_INT_8_8_8_8_REV, pixels );
-}
-
-(void) openFile:(const char *)filename
{
[proxy_emulator openFile:filename];
Added: trunk/fuse/fusepb/views/Texture.h
===================================================================
--- trunk/fuse/fusepb/views/Texture.h (rev 0)
+++ trunk/fuse/fusepb/views/Texture.h 2007-07-13 13:49:45 UTC (rev 430)
@@ -0,0 +1,47 @@
+/* DisplayOpenGLView.h: Implementation for the DisplayOpenGLView class
+ Copyright (c) 2006-2007 Fredrick Meunier
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Author contact information:
+
+ E-mail: fr...@sp...
+ Postal address: 3/66 Roslyn Gardens, Ruscutters Bay, NSW 2011, Australia
+
+*/
+
+#import <Cocoa/Cocoa.h>
+
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#include <OpenGL/glu.h>
+
+#include "ui/cocoa/cocoadisplay.h"
+
+@interface Texture : NSObject
+{
+ Cocoa_Texture texture;
+ GLuint textureId;
+}
+-(id) initWithBitmap:(NSBitmapImageRep*)bitmap withXOrigin:(int)x
+ withYOrigin:(int)y colourRed:(int)red;
+-(void) dealloc;
+
+-(Cocoa_Texture*) getTexture;
+-(GLuint) getTextureId;
+
+-(void) uploadIconTexture;
+
+@end
Added: trunk/fuse/fusepb/views/Texture.m
===================================================================
--- trunk/fuse/fusepb/views/Texture.m (rev 0)
+++ trunk/fuse/fusepb/views/Texture.m 2007-07-13 13:49:45 UTC (rev 430)
@@ -0,0 +1,130 @@
+/* DisplayOpenGLView.m: Implementation for the DisplayOpenGLView class
+ Copyright (c) 2006-2007 Fredrick Meunier
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Author contact information:
+
+ E-mail: fr...@sp...
+ Postal address: 3/66 Roslyn Gardens, Ruscutters Bay, NSW 2011, Australia
+
+*/
+
+#import "Texture.h"
+
+unsigned char *
+NSBitmapImageRepToRGBAPixelArray(NSBitmapImageRep * bitmap, int red)
+{
+ unsigned char * pixels;
+ NSBitmapImageRep * bitmap2;
+ NSGraphicsContext * context;
+#define BYTES_PER_PIXEL 4
+ int targetWidth = [bitmap pixelsWide];
+ int targetHeight = [bitmap pixelsHigh];
+
+ pixels = (unsigned char *) malloc(BYTES_PER_PIXEL * targetWidth * targetHeight);
+ bitmap2 = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: &pixels
+ pixelsWide: targetWidth
+ pixelsHigh: targetHeight
+ bitsPerSample: 8
+ samplesPerPixel: 4
+ hasAlpha: YES
+ isPlanar: NO
+ colorSpaceName: NSDeviceRGBColorSpace
+ bitmapFormat: NSAlphaNonpremultipliedBitmapFormat
+ bytesPerRow: (targetWidth * BYTES_PER_PIXEL)
+ bitsPerPixel: (BYTES_PER_PIXEL * 8)];
+
+ context = [NSGraphicsContext graphicsContextWithBitmapImageRep: bitmap2];
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext: context];
+ [bitmap drawInRect: NSMakeRect(0, 0, targetWidth, targetHeight)];
+ [NSGraphicsContext restoreGraphicsState];
+
+ int i;
+ for( i = 0; i < targetWidth * targetHeight; i++ ) {
+#ifdef WORDS_BIGENDIAN
+ pixels[i*4+3] = red ? pixels[i*4+0] : 0; // r on ppc
+ pixels[i*4+2] = red ? 0 : pixels[i*4+1]; // g on ppc
+ pixels[i*4+0] = 0;
+ pixels[i*4+1] = 0;
+#else /* #ifdef WORDS_BIGENDIAN */
+ pixels[i*4+0] = red ? pixels[i*4+0] : 0; // r on i386
+ pixels[i*4+1] = red ? 0 : pixels[i*4+1]; // g on i386
+ pixels[i*4+2] = 0;
+#endif /* #ifdef WORDS_BIGENDIAN */
+ }
+
+ [bitmap2 release];
+
+ return pixels;
+}
+
+@implementation Texture
+
+-(id) initWithBitmap:(NSBitmapImageRep*)bitmap withXOrigin:(int)x
+ withYOrigin:(int)y colourRed:(int)red
+{
+ if( ( self = [super init] ) ) {
+ texture.pixels = NSBitmapImageRepToRGBAPixelArray( bitmap, red );
+ texture.image_width = [bitmap pixelsWide];
+ texture.image_height = [bitmap pixelsHigh];
+ texture.image_xoffset = x;
+ texture.image_yoffset = y;
+
+ [self uploadIconTexture];
+ }
+
+ return self;
+}
+
+-(void) dealloc
+{
+ glDeleteTextures(1, &textureId);
+ free( texture.pixels );
+ [super dealloc];
+}
+
+-(Cocoa_Texture*) getTexture
+{
+ return &texture;
+}
+
+-(GLuint) getTextureId
+{
+ return textureId;
+}
+
+-(void) uploadIconTexture;
+{
+ glGenTextures(1, &textureId);
+
+ /* Set memory alignment parameters for unpacking the bitmap. */
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+
+ /* Specify the texture's properties. */
+ glBindTexture( GL_TEXTURE_RECTANGLE_EXT, textureId );
+ glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
+ glTexParameteri( GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+
+ /* Upload the texture bitmap. */
+ glTexImage2D( GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, texture.image_width,
+ texture.image_height, 0, GL_RGBA,
+ GL_UNSIGNED_INT_8_8_8_8_REV, texture.pixels );
+}
+
+@end
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|