void VisualTextureContainer::applyConvolutionFilter(const VisualConvolutionFilter& aConvolutionFilter) {
	
	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();

	int prevReadBuffer = theVisualGraphics->getCurrentColorBufferForPixelReadingOperations();
	theVisualGraphics->setColorBufferForPixelReadingOperations(kGL_BACK_COLOR_BUFFER);

	int prevDrawBuffer = theVisualGraphics->getCurrentColorBufferForPixelDrawingOperations();
	theVisualGraphics->setColorBufferForPixelDrawingOperations(kGL_BACK_COLOR_BUFFER);
	
	UInt32* prevPixels = NULL;

	char errStr[512];

	UInt8 numberOfBytesPerChannel = 0;
	UInt8 numberOfChannels = 0; // channel == color resp. alpha channel
	UInt8 numberOfBytesPerPixel = 0;
	UInt32 numberOfBytesPerRow = 0;
	if ((this->pixelFormat == kGL_RGBA) || (this->pixelFormat == kGL_BGRA)) {
		numberOfChannels = 4;
	} else {
		sprintf(errStr, "unknown format %d in file: %s (line: %d) [%s])", this->pixelFormat, __FILE__, __LINE__, __FUNCTION__);
		writeLog(errStr);
		return;
	}
	
	if ((this->dataType == kGL_UNSIGNED_INT_8_8_8_8_REV) || (this->dataType == kGL_UNSIGNED_INT_8_8_8_8) || (this->dataType == kGL_UNSIGNED_BYTE)) {
		numberOfBytesPerChannel = 1; // // 1 byte (== 8 bits) per color/channel
	} else {
		sprintf(errStr, "unknown type %d in file: %s (line: %d) [%s])", this->dataType, __FILE__, __LINE__, __FUNCTION__);
		writeLog(errStr);
		return;
	}
	
	numberOfBytesPerPixel = numberOfBytesPerChannel * numberOfChannels;
	numberOfBytesPerRow = numberOfBytesPerPixel * this->textureWidth;

	// read previous pixels
	if ((this->pixelFormat == kGL_RGBA) || (this->pixelFormat == kGL_BGRA)) {
		prevPixels = (UInt32*)calloc((numberOfBytesPerRow / numberOfBytesPerPixel) * this->textureHeight, numberOfBytesPerPixel);
	}
	theVisualGraphics->readPixels(theVisualGraphics->getMaxLeftCoordOfCanvas(), theVisualGraphics->getMaxBottomCoordOfCanvas(), this->textureWidth, this->textureHeight, &prevPixels, this->pixelFormat, this->dataType);

	UInt32* pixels = this->getTexturePixels(this->pixelFormat, this->dataType);
	UInt32* passedPixels = (UInt32*)malloc(this->textureWidth * this->textureHeight * 4);
	memcpy(passedPixels, pixels, this->textureWidth * this->textureHeight * 4); // VisualStudio does not like when we pass a non-const pointer to instance variable (crashes in runtime)
	theVisualGraphics->drawPixels((UInt32**)&(passedPixels), theVisualGraphics->getMaxLeftCoordOfCanvas(), theVisualGraphics->getMaxBottomCoordOfCanvas(), this->textureWidth, this->textureHeight, this->pixelFormat, this->dataType, &aConvolutionFilter);
	if (passedPixels != NULL) {
		free(passedPixels);
		passedPixels = NULL;
	}

	theVisualGraphics->copyFramebufferToTexture(this->textureName, this->useRectExtension, 0, 0, this->textureWidth, this->textureHeight, this->pixelFormat, this->dataType);

	// restore previous pixels
	theVisualGraphics->drawPixels(&prevPixels, theVisualGraphics->getMaxLeftCoordOfCanvas(), theVisualGraphics->getMaxBottomCoordOfCanvas(), this->textureWidth, this->textureHeight, this->pixelFormat, this->dataType);
	
	free(prevPixels);

	theVisualGraphics->setColorBufferForPixelDrawingOperations(prevDrawBuffer);
	theVisualGraphics->setColorBufferForPixelReadingOperations(prevReadBuffer);

	if (this->pixelBuffer != NULL) {
		free(this->pixelBuffer);
		this->pixelBuffer = NULL;
	}
	
}
示例#2
0
void monitorRenderMessageProcess() {

	static float framesPerSecond = 0.0f;
	static UInt16 frameCount = 0;
	::Rect viewportRect;
	UInt32 elapsedMilliseconds, remainingMilliseconds, totalMilliseconds = 0;
	VisualAudioLab* theVisualAudioLab = NULL;
	VisualPlayerState* theVisualPlayerState = NULL;
	VisualGraphics* theVisualGraphics = NULL;
	UInt8 playState;
	char cStr64[64];
	
	theVisualPlayerState = VisualPlayerState::getInstance();
	
    elapsedMilliseconds = VisualTiming::getElapsedMilliSecsSinceReset("fps");
    
    if (elapsedMilliseconds > 1000) {
        framesPerSecond = (float)frameCount / (float)elapsedMilliseconds * 1000.0f;
        frameCount = 0;
        VisualTiming::resetTimestamp("fps");
    }
	frameCount++;
    
    sprintf(cStr64, "%.2f",  framesPerSecond);
    setProcessInfo("FramesPerSecond", cStr64);
	
	theVisualGraphics = VisualGraphics::getInstance();

	setProcessInfo("RendererName",theVisualGraphics->getRendererName());

	setProcessInfo("RendererVendor",theVisualGraphics->getRendererVendor());

	setProcessInfo("RendererVersion",theVisualGraphics->getRendererVersion());

	sprintf(cStr64, "%#x", theVisualGraphics->getGLVersion());
	setProcessInfo("GLVersion", cStr64);
	
	sprintf(cStr64, "%ld", theVisualGraphics->getMaxTextureSize());
	setProcessInfo("Maximum Texture Size", cStr64);
	
	// screen measurements
	sprintf(cStr64, "width: %d, height: %d, refreshRate: %d", theVisualGraphics->getScreenWidth(), theVisualGraphics->getScreenHeight(), theVisualGraphics->getRefreshRateOfScreen());
	setProcessInfo("Screen", cStr64);
	
	sprintf(cStr64, "%d", theVisualGraphics->getBitsPerPixelOfScreen());
	setProcessInfo("BitsPerPixel", cStr64);
	
	sprintf(cStr64, "%d", theVisualGraphics->getCanvasPixelHeight());
	setProcessInfo("CanvasPixelHeight", cStr64);
	
	sprintf(cStr64, "%d", theVisualGraphics->getCanvasPixelWidth());
	setProcessInfo("CanvasPixelWidth", cStr64);

	::Rect theCanvasRect;
	theVisualGraphics->getCanvasRect(&theCanvasRect);
	sprintf(cStr64, "top: %d, left: %d", theCanvasRect.top, theCanvasRect.left);
	setProcessInfo("CanvasRectTopLeft", cStr64);
	sprintf(cStr64, "bottom: %d, right: %d", theCanvasRect.bottom, theCanvasRect.right);
	setProcessInfo("CanvasRectBottomRight", cStr64);

	::Rect theCanvasSurroundingRect;
	theVisualGraphics->getCanvasSurroundingRect(&theCanvasSurroundingRect);
	sprintf(cStr64, "top: %d, left: %d", theCanvasSurroundingRect.top, theCanvasSurroundingRect.left);
	setProcessInfo("CanvasSurroundRectTopLeft", cStr64);
	sprintf(cStr64, "bottom: %d, right: %d", theCanvasSurroundingRect.bottom, theCanvasSurroundingRect.right);
	setProcessInfo("CanvasSurroundRectBottomRight", cStr64);
	
	sprintf(cStr64, "top: %.2f, left: %.2f", theVisualGraphics->getMaxTopCoordOfCanvas(), theVisualGraphics->getMaxLeftCoordOfCanvas());
	setProcessInfo("CoordMaxTopLeft", cStr64);
	sprintf(cStr64, "bottom: %.2f, right: %.2f", theVisualGraphics->getMaxBottomCoordOfCanvas(), theVisualGraphics->getMaxRightCoordOfCanvas());
	setProcessInfo("CoordMaxBottomRight", cStr64);
	sprintf(cStr64, "near: %.2f, far: %.2f", theVisualGraphics->getMaxNearCoordOfCanvas(), theVisualGraphics->getMaxFarCoordOfCanvas());
	setProcessInfo("CoordMaxNearFar", cStr64);

	theVisualGraphics->getViewportRect(&viewportRect);
	sprintf(cStr64, "top: %d, left: %d, bottom: %d, right: %d",  viewportRect.top, viewportRect.left, viewportRect.bottom, viewportRect.right);
	setProcessInfo("ViewportRect", cStr64);

	playState = theVisualPlayerState->getAudioPlayState();
	switch (playState) {
		case kAudioIsPlaying:
			sprintf(cStr64, "kAudioIsPlaying");
			break;
		case kAudioPlayStarted:
			sprintf(cStr64, "kAudioPlayStarted");
			break;		
		case kAudioPlayResumed:
			sprintf(cStr64, "kAudioPlayResumed");
			break;
		case kAudioPlayPaused:
			sprintf(cStr64, "kAudioPlayPaused");
			break;
		case kAudioIsNotPlaying:
			sprintf(cStr64, "kAudioIsNotPlaying");
			break;
		default:
			sprintf(cStr64, "unknown");
	}
	setProcessInfo("AudioPlayState", cStr64);
	
	elapsedMilliseconds = theVisualPlayerState->getElapsedAudioTime();
	sprintf(cStr64, "%ld", elapsedMilliseconds);
	setProcessInfo("TrackTimeElapsed", cStr64);

	remainingMilliseconds = theVisualPlayerState->getRemainingAudioTime();
	sprintf(cStr64, "%ld", remainingMilliseconds);
	setProcessInfo("TrackTimeRemaining", cStr64);

	theVisualAudioLab = VisualAudioLab::getInstance();
	totalMilliseconds = theVisualAudioLab->getTotalTimeOfCurrentTrack();
	sprintf(cStr64, "%ld", totalMilliseconds);
	setProcessInfo("TrackTimeTotal", cStr64);

}