Skip to content

Commit

Permalink
Add pixelStorei - no-ops when UNPACK_FLIP_Y_WEBGL is given.
Browse files Browse the repository at this point in the history
  • Loading branch information
puffnfresh committed May 29, 2011
1 parent 70877b4 commit 5e90e35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
24 changes: 23 additions & 1 deletion src/glcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class GLContext : public ObjectWrap {
SetConstant(proto, "REPEAT", 0x2901);
SetConstant(proto, "CLAMP_TO_EDGE", 0x812F);
SetConstant(proto, "MIRRORED_REPEAT", 0x8370);

// WebGL-specific enums
SetConstant(proto, "UNPACK_FLIP_Y_WEBGL", UNPACK_FLIP_Y_WEBGL);

// Methods
NODE_SET_PROTOTYPE_METHOD(t, "viewport", Viewport);
Expand Down Expand Up @@ -120,6 +123,7 @@ class GLContext : public ObjectWrap {
NODE_SET_PROTOTYPE_METHOD(t, "bindTexture", BindTexture);
NODE_SET_PROTOTYPE_METHOD(t, "texImage2D", TexImage2D);
NODE_SET_PROTOTYPE_METHOD(t, "activeTexture", ActiveTexture);
NODE_SET_PROTOTYPE_METHOD(t, "pixelStorei", PixelStorei);

NODE_SET_PROTOTYPE_METHOD(t, "swapBuffers", SwapBuffers);

Expand Down Expand Up @@ -466,6 +470,23 @@ class GLContext : public ObjectWrap {
return Undefined();
}

static Handle<Value>
PixelStorei (const Arguments& args) {
HandleScope scope;

GLenum pname = args[0]->Uint32Value();
GLint param = args[1]->Int32Value();

// WebGL specific
if (pname == UNPACK_FLIP_Y_WEBGL) {
// TODO: Only flip image if called.
} else {
glPixelStorei(pname, param);
}

return Undefined();
}

static Handle<Value>
TexImage2D (const Arguments& args) {
HandleScope scope;
Expand All @@ -481,7 +502,7 @@ class GLContext : public ObjectWrap {
image->GetHeight(), 0, format,
type, image->GetData());

// We have to
// We have to generate mipmaps
glGenerateMipmapEXT(GL_TEXTURE_2D);

return Undefined();
Expand All @@ -505,6 +526,7 @@ class GLContext : public ObjectWrap {

static Persistent<FunctionTemplate> constructor_template;

static const GLenum UNPACK_FLIP_Y_WEBGL = 0x9240;
};

Persistent<FunctionTemplate> GLContext::constructor_template;
23 changes: 0 additions & 23 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,6 @@ class Image : public EventEmitter {
FreeImage_Initialise(true);
}

void
FlipVertically () {
int width = GetWidth();
int height = GetHeight();

int rowBytes = width * 3;
uint8_t* tempRow = new uint8_t[rowBytes];
for (unsigned i = 0; i < height / 2; i++) {
uint8_t* lowRow = (uint8_t *)data + (rowBytes * i);
uint8_t* highRow = (uint8_t *)data + (rowBytes * (height - i - 1));
memcpy(tempRow, lowRow, rowBytes);
memcpy(lowRow, highRow, rowBytes);
memcpy(highRow, tempRow, rowBytes);
}
delete[] tempRow;
}

int
GetBPP () {
//return FreeImage_GetBPP(image_bmp);
return 32;
}

int
GetWidth () {
return FreeImage_GetWidth(image_bmp);
Expand Down

0 comments on commit 5e90e35

Please sign in to comment.