当前位置: 首页>>代码示例>>C++>>正文


C++ VisualGraphics::get8BitPixelsOfCurrentTexture方法代码示例

本文整理汇总了C++中VisualGraphics::get8BitPixelsOfCurrentTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ VisualGraphics::get8BitPixelsOfCurrentTexture方法的具体用法?C++ VisualGraphics::get8BitPixelsOfCurrentTexture怎么用?C++ VisualGraphics::get8BitPixelsOfCurrentTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VisualGraphics的用法示例。


在下文中一共展示了VisualGraphics::get8BitPixelsOfCurrentTexture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getTexturePixels

UInt32* VisualTextureContainer::getTexturePixels(const UInt16 format, const UInt16 type) {

	bool debug = false;

	UInt8* pixelBuffer8Bit = NULL;
		
	char errStr[256];

	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
	
	if (debug == true) {
		if (this->pixelBuffer != NULL) {
			free(this->pixelBuffer);
			this->pixelBuffer = NULL;
		}
		this->pixelBuffer = theVisualGraphics->createARGBCheckPixels(this->textureWidth, this->textureHeight);
		return this->pixelBuffer;
	}
	
	if ((debug == false) && (this->pixelBuffer != NULL)) {
		//return this->pixelBuffer;
	}
	
	UInt8 numberOfBytesPerChannel = 0;
	UInt8 numberOfChannels = 0; // channel == color resp. alpha channel
	UInt8 numberOfBytesPerPixel = 0;
	UInt32 numberOfBytesPerRow = 0;
	if ((format == kGL_RGBA) || (format == kGL_BGRA)) {
		numberOfChannels = 4;
	} else {
		sprintf(errStr, "unknown format %d in file: %s (line: %d) [%s])", format, __FILE__, __LINE__, __FUNCTION__);
		writeLog(errStr);
		return this->pixelBuffer;
	}
	
	if ((type == kGL_UNSIGNED_INT_8_8_8_8_REV) || (type == kGL_UNSIGNED_INT_8_8_8_8) || (type == kGL_UNSIGNED_BYTE)) {
		numberOfBytesPerChannel = 1; // 1 byte (== 8 bits) per color/channel
	} else {
		sprintf(errStr, "unknown type %d in file: %s (line: %d) [%s])", type, __FILE__, __LINE__, __FUNCTION__);
		writeLog(errStr);
		return this->pixelBuffer;
	}

	if (this->pixelBuffer != NULL) {
		free(this->pixelBuffer);
		this->pixelBuffer = NULL;
	}

	if (this->useRectExtension == false) {
		numberOfBytesPerPixel = numberOfBytesPerChannel * numberOfChannels;
		numberOfBytesPerRow = numberOfBytesPerPixel * this->textureWidth;
		if ((format == kGL_RGBA) || (format == kGL_BGRA)) {
			if ((type == kGL_UNSIGNED_INT_8_8_8_8_REV) || (type == kGL_UNSIGNED_INT_8_8_8_8)) {
				this->pixelBuffer = (UInt32*)calloc((numberOfBytesPerRow / numberOfBytesPerPixel) * this->textureHeight, numberOfBytesPerPixel);
			} else if (type == kGL_UNSIGNED_BYTE) {
				this->pixelBuffer = (UInt32*)calloc((numberOfBytesPerRow / numberOfBytesPerPixel) * this->textureHeight, numberOfBytesPerPixel);
				pixelBuffer8Bit = (UInt8*)malloc(this->textureWidth * this->textureHeight * 4);
			}
		}
		
		theVisualGraphics->enableTexturing(this->useRectExtension);
		theVisualGraphics->bindTexture(this->textureName, this->useRectExtension);
		theVisualGraphics->setPixelStorageParams();
		if ((type == kGL_UNSIGNED_INT_8_8_8_8_REV) || (type == kGL_UNSIGNED_INT_8_8_8_8)) {
			theVisualGraphics->get32BitPixelsOfCurrentTexture(this->useRectExtension, format, type, &(this->pixelBuffer));
		} else if (type == kGL_UNSIGNED_BYTE) {
			theVisualGraphics->get8BitPixelsOfCurrentTexture(this->useRectExtension, format, type, &pixelBuffer8Bit);
		}
		theVisualGraphics->disableTexturing(this->useRectExtension);

	} else {
#if TARGET_OS_MAC
		// glGetTexImage() does not always reliably return the pixelBuffer
		// of npot (non-power-of-two, GL_TEXTURE_RECTANGLE_EXT) textures
		// because of inconsistencies with Nvidia's GeForce4 MX card (1.4.18) [only with some not all textures the pixel data was returned]
		// we grab the pixels with glReadPixels()
		// (HW, 20070208)
		this->pixelBuffer = this->getRectPixels(format, type);
#endif
	}

	if (type == kGL_UNSIGNED_BYTE) {
		UInt32 b, g, r, a, color32bit;
		UInt32 pixelBufferIdx = 0;
		UInt32 pixelBuffer8BitIdx = 0;
		for (UInt32 i = 0; i < this->textureHeight; i++) {
			for (UInt32 k = 0; k < this->textureWidth; k++) {
				b = pixelBuffer8Bit[pixelBuffer8BitIdx + 0] << 24;
				g = pixelBuffer8Bit[pixelBuffer8BitIdx + 1] << 16;
				r = pixelBuffer8Bit[pixelBuffer8BitIdx + 2] << 8;
				a = pixelBuffer8Bit[pixelBuffer8BitIdx + 3];
				color32bit = b | g | r | a;
				this->pixelBuffer[pixelBufferIdx] = color32bit;
				pixelBufferIdx++;
				pixelBuffer8BitIdx += 4;
			}
		}
		free(pixelBuffer8Bit);
	}

//.........这里部分代码省略.........
开发者ID:alexpaulzor,项目名称:projectm,代码行数:101,代码来源:VisualTextureContainer.cpp


注:本文中的VisualGraphics::get8BitPixelsOfCurrentTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。