Exemple #1
0
void activateAndClearTarget(ImageOutport& outport, ImageType type) {
    activateTarget(outport, type);
    clearCurrentTarget();
}
Exemple #2
0
void activateAndClearTarget(Image& image, ImageType type) {
    activateTarget(image, type);
    clearCurrentTarget();
}
Exemple #3
0
void GLTexture::download(Bitmap *bitmap) {
	if (bitmap == NULL)
		bitmap = getBitmap();

	Assert(bitmap != NULL);

	activateTarget();
	GLenum format, dataFormat;

	switch (bitmap->getComponentFormat()) {
		case Bitmap::EUInt8:   dataFormat = GL_UNSIGNED_BYTE; break;
		case Bitmap::EUInt16:  dataFormat = GL_UNSIGNED_SHORT; break;
		case Bitmap::EUInt32:  dataFormat = GL_UNSIGNED_INT; break;
		case Bitmap::EFloat16: dataFormat = GL_HALF_FLOAT_ARB; break;
		case Bitmap::EFloat32: dataFormat = GL_FLOAT; break;
		case Bitmap::EFloat64: dataFormat = GL_DOUBLE; break;
		default:
			Log(EError, "GLTexture::download(): Unknown/unsupported component format %i!",
					(int) bitmap->getComponentFormat());
			return;
	}

	switch (bitmap->getPixelFormat()) {
		case Bitmap::ELuminance:
			if (m_fbType == EDepthBuffer)
				format = GL_DEPTH_COMPONENT;
			else
				format = GL_LUMINANCE;
			break;
		case Bitmap::ELuminanceAlpha: format = GL_LUMINANCE_ALPHA; break;
		case Bitmap::ERGB: format = GL_RGB; break;
		case Bitmap::ERGBA: format = GL_RGBA; break;
		default:
			Log(EError, "GLTexture::download(): Unknown/unsupported pixel format %i!",
					(int) bitmap->getPixelFormat());
			return;
	}

	glPixelStorei(GL_PACK_ALIGNMENT, 1);

	switch (m_type) {
		case ETexture2D:
			glReadPixels(0, 0, bitmap->getWidth(), bitmap->getHeight(), format,
				dataFormat, bitmap->getUInt8Data());
			/* OpenGL associates (0, 0) with the lower left position and
			   the resulting bitmap must thus be vertically flipped. */
			bitmap->flipVertically();
			break;
		case ETextureCubeMap:
			for (int i=0; i<6; ++i) {
				activateSide(i);
				bitmap = getBitmap(i);
				glReadPixels(0, 0, bitmap->getWidth(), bitmap->getHeight(), format,
					dataFormat, bitmap->getUInt8Data());
				bitmap->flipVertically();
			}
			break;
		default:
			Log(EError, "download(): Unsupported texture type!");
	}

	releaseTarget();
}