Skip to content

Commit

Permalink
added bind/unbind to GLRenderbuffer, unbind to GLFramebuffer and GLTe…
Browse files Browse the repository at this point in the history
…xture. Added glTexSubImage2D wrapper method for textures.
  • Loading branch information
rsebbe committed Jul 31, 2013
1 parent 62f04ed commit 7719d6b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/GLDrawCommand.m
Expand Up @@ -58,6 +58,7 @@ - (void)setElementIndexes:(GLBuffer*)buffer type:(GLenum)type
#pragma mark Textures
- (void)setTexture:(GLTexture*)texture target:(GLenum)target unit:(GLenum)unit
{
GL_EXCEPT(texture == nil, NSInvalidArgumentException);
id binder = [NSDictionary dictionaryWithObjectsAndKeys:texture, @"texture", [NSNumber numberWithInt:target],@"target", nil];

[mTextures setObject:binder forKey:[NSNumber numberWithInt:unit]];
Expand Down
1 change: 1 addition & 0 deletions Sources/GLFramebuffer.h
Expand Up @@ -28,5 +28,6 @@

// Binding
- (void)bind;
+ (void)unbind;

@end
5 changes: 5 additions & 0 deletions Sources/GLFramebuffer.m
Expand Up @@ -134,5 +134,10 @@ - (void)bind
GL_EXCEPT(mHandle == 0, @"Trying to bind non-existing buffer");
glBindFramebuffer(GL_FRAMEBUFFER, mHandle);
}
+ (void)unbind
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}


@end
5 changes: 5 additions & 0 deletions Sources/GLRenderbuffer.h
Expand Up @@ -22,4 +22,9 @@
- (void)setFromExistingHandle:(GLuint)handle width:(GLsizei)w height:(GLsizei)h internalFormat:(GLenum)iformat;
- (void)allocateStorageWithWidth:(GLsizei)w height:(GLsizei)h internalFormat:(GLenum)internalFormat ;

// Don't bind a renderbuffer to draw, just bind its associated framebuffer.
// Bind a renderbuffer to edit/query it with glRenderbuffer*
- (void)bind;
+ (void)unbind;

@end
14 changes: 14 additions & 0 deletions Sources/GLRenderbuffer.m
Expand Up @@ -63,6 +63,8 @@ - (void)allocateStorageWithWidth:(GLsizei)w height:(GLsizei)h internalFormat:(GL
glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, w, h);
glBindRenderbuffer(GL_RENDERBUFFER, 0);

GLCheckError();

mWidth = w;
mHeight = h;
mInternalFormat = internalFormat;
Expand All @@ -75,4 +77,16 @@ - (CGSize)size
return CGSizeMake(mWidth, mHeight);
}

#pragma mark - Binding -
- (void)bind
{
GL_EXCEPT(mHandle == 0, @"Trying to bind non-existing renderbuffer");
glBindRenderbuffer(GL_RENDERBUFFER, mHandle);
}
+ (void)unbind
{
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}


@end
5 changes: 5 additions & 0 deletions Sources/GLTexture.h
Expand Up @@ -35,9 +35,14 @@
- (void)loadImage:(const GLvoid *)pixels width:(GLsizei)w height:(GLsizei)h format:(GLenum)format type:(GLenum)type internalFormat:(GLenum)iformat target:(GLenum)target;
- (void)loadImage:(const GLvoid*)pixels level:(GLint)level width:(GLsizei)w height:(GLsizei)h format:(GLenum)format type:(GLenum)type border:(GLint)border internalFormat:(GLenum)iformat target:(GLenum)target magFilter:(GLenum)magfil minFilter:(GLenum)minfil wrapS:(GLenum)wraps wrapT:(GLenum)wrapt;

// Update part of the texture. pixels is a pointer to the first pixel of the new data.
- (void)updateImage:(const GLvoid*)pixels level:(GLint)level xOffset:(GLint)xoff yOffset:(GLint)yoff width:(GLsizei)w height:(GLsizei)h format:(GLenum)format type:(GLenum)type target:(GLenum)target;


- (void)copyFramebufferImageToLevel:(GLint)level x:(GLint)x y:(GLint)y width:(GLint)w height:(GLint)height border:(GLint)border internalFormat:(GLenum)iformat target:(GLenum)target;

// Binding
- (void)bind:(GLenum)target;
+ (void)unbind:(GLenum)target;

@end
18 changes: 18 additions & 0 deletions Sources/GLTexture.m
Expand Up @@ -90,6 +90,8 @@ - (void)loadImage:(const GLvoid*)pixels level:(GLint)level width:(GLsizei)w heig
wrapt = GL_CLAMP_TO_EDGE;
}

// int align = 1;
// glPixelStorei(GL_UNPACK_ALIGNMENT, align);
glTexParameteri(target, GL_TEXTURE_WRAP_S, wraps);
glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapt);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Expand All @@ -106,6 +108,17 @@ - (void)loadImage:(const GLvoid*)pixels level:(GLint)level width:(GLsizei)w heig
mBorder = border;
}

- (void)updateImage:(const GLvoid*)pixels level:(GLint)level xOffset:(GLint)xoff yOffset:(GLint)yoff width:(GLsizei)w height:(GLsizei)h format:(GLenum)format type:(GLenum)type target:(GLenum)target
{
GL_EXCEPT(mHandle == 0, @"Trying to update non-existing buffer");

glBindTexture(target, mHandle);
GLCheckError();

glTexSubImage2D(target, level, xoff, yoff, w, h, format, type, pixels);
GLCheckError();
}

- (void)copyFramebufferImageToLevel:(GLint)level x:(GLint)x y:(GLint)y width:(GLint)w height:(GLint)h border:(GLint)border internalFormat:(GLenum)iformat target:(GLenum)target
{
if(mHandle == 0)
Expand All @@ -129,6 +142,11 @@ - (void)bind:(GLenum)target
glBindTexture(target, mHandle);
GLCheckError();
}
+ (void)unbind:(GLenum)target
{
glBindTexture(target, 0);
}

#pragma mark -
#pragma mark Accessors
- (CGSize)size
Expand Down
1 change: 1 addition & 0 deletions iOS/CeedGL_Prefix.pch
@@ -1,5 +1,6 @@

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <CeedGL/GLDebug.h>
#endif

0 comments on commit 7719d6b

Please sign in to comment.