Commits

Brian McKenna committed 5e90e35

Add pixelStorei - no-ops when UNPACK_FLIP_Y_WEBGL is given.

  • Participants
  • Parent commits 70877b4

Comments (0)

Files changed (2)

File src/glcontext.h

 	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);
         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);
 
     }
 
     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;
 
 		     image->GetHeight(), 0, format,
 		     type, image->GetData());
 
-	// We have to 
+	// We have to generate mipmaps
 	glGenerateMipmapEXT(GL_TEXTURE_2D);
 
 	return Undefined();
 
     static Persistent<FunctionTemplate> constructor_template;
 
+    static const GLenum UNPACK_FLIP_Y_WEBGL = 0x9240;
 };
 
 Persistent<FunctionTemplate> GLContext::constructor_template;
 	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);