Exemple #1
0
bool LLWebBrowserTexture::updateBrowserTexture()
{
	if (!adjustSize())
		return false;
		
	LLPluginClassMedia* media = mMediaSource->getMediaPlugin();
	
	if(!media->textureValid())
		return false;
	
	if(mMediaSource->mNeedsNewTexture
		|| media->getTextureWidth() != mWidth
		|| media->getTextureHeight() != mHeight )
	{
		releaseGLTexture();
		
		mWidth = media->getTextureWidth();
		mHeight = media->getTextureHeight();
		mTextureCoordsOpenGL = media->getTextureCoordsOpenGL();

		// will create mWidth * mHeight sized texture, using the texture params specified by the media.
		LLDynamicTexture::generateGLTexture(
				media->getTextureFormatInternal(), 
				media->getTextureFormatPrimary(), 
				media->getTextureFormatType(), 
				media->getTextureFormatSwapBytes());


		mMediaSource->mNeedsNewTexture = false;
	}
	
	return true;
}
Exemple #2
0
//-----------------------------------------------------------------------------
// LLDynamicTexture()
//-----------------------------------------------------------------------------
LLDynamicTexture::~LLDynamicTexture()
{
	releaseGLTexture();
	for( S32 order = 0; order < ORDER_COUNT; order++ )
	{
		LLDynamicTexture::sInstances[order].erase(this);  // will fail in all but one case.
	}
}
Exemple #3
0
void LLDynamicTexture::generateGLTexture(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
{
	if (mComponents < 1 || mComponents > 4)
	{
		llerrs << "Bad number of components in dynamic texture: " << mComponents << llendl;
	}
	releaseGLTexture();
	LLPointer<LLImageRaw> raw_image = new LLImageRaw(mWidth, mHeight, mComponents);
	mTexture = new LLImageGL(mWidth, mHeight, mComponents, FALSE);
	if (internal_format >= 0)
	{
		mTexture->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes);
	}
// 	llinfos << "ALLOCATING " << (mWidth*mHeight*mComponents)/1024 << "K" << llendl;
	mTexture->createGLTexture(0, raw_image);
	mTexture->setClamp(mClamp, mClamp);
}
void LLDynamicTexture::generateGLTexture(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
{
	if (mComponents < 1 || mComponents > 4)
	{
		llerrs << "Bad number of components in dynamic texture: " << mComponents << llendl;
	}
	releaseGLTexture();
	LLPointer<LLImageRaw> raw_image = new LLImageRaw(mWidth, mHeight, mComponents);
	mTexture = new LLViewerImage(mWidth, mHeight, mComponents, FALSE);
	if (internal_format >= 0)
	{
		mTexture->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes);
	}
// 	llinfos << "ALLOCATING " << (mWidth*mHeight*mComponents)/1024 << "K" << llendl;
	mTexture->createGLTexture(0, raw_image, 0, TRUE, LLViewerImageBoostLevel::DYNAMIC_TEX);
	mTexture->setAddressMode((mClamp) ? LLTexUnit::TAM_CLAMP : LLTexUnit::TAM_WRAP);
	mTexture->setGLTextureCreated(false);
}
//virtual
void LLDynamicTexture::destroyGLTexture() 
{
	releaseGLTexture() ;
}
void LLWebBrowserTexture::resize( S32 new_width, S32 new_height )
{
	if (!mMediaSource)
		return;
	
	F32 scale_ratio = 1.f;
	if (new_width > MAX_DIMENSION)
	{
		scale_ratio = (F32)MAX_DIMENSION / (F32)new_width;
	}
	if (new_height > MAX_DIMENSION)
	{
		scale_ratio = llmin(scale_ratio, (F32)MAX_DIMENSION / (F32)new_height);
	}

	mBrowserWidth = llround(scale_ratio * (F32)new_width);
	mBrowserHeight = llround(scale_ratio * (F32)new_height);

	mMediaSource->setRequestedMediaSize(mBrowserWidth, mBrowserHeight);

	// HACK - this code is executing a render - resize should call render() instead
	// (and render() should be refactored so it doesn't call resize())
	
	mMediaSource->updateMedia();
	const unsigned char* pixels = mMediaSource->getMediaData();

	S32 media_width  = mMediaSource->getMediaWidth();
	S32 media_height = mMediaSource->getMediaHeight();
	S32 media_depth  = mMediaSource->getMediaDepth();

	// these are both invalid conditions and should never happen but SL-27583 indicates it does
	if ( media_width < 1 || media_depth < 2 )
		return;
	
	releaseGLTexture();

	// calculate the next power of 2 bigger than reqquested size for width and height
	for ( mWidth = 1; mWidth < mBrowserWidth; mWidth <<= 1 )
	{
		if ( mWidth >= MAX_TEXTURE_DIMENSION )
		{
			break;
		};
	};

	for ( mHeight = 1; mHeight < mBrowserHeight; mHeight <<= 1 )
	{
		if ( mHeight >= MAX_TEXTURE_DIMENSION )
		{
			break;
		};
	};
	
	LLGLint internal_format;
	LLGLenum primary_format;
	LLGLenum type_format;
	BOOL	 swap_bytes = FALSE;

	switch(media_depth)
	{
		default:
		case 4:
			internal_format = GL_RGBA8;
			primary_format = GL_BGRA_EXT;
		#if LL_DARWIN
			#if LL_BIG_ENDIAN
				type_format = GL_UNSIGNED_INT_8_8_8_8_REV;
			#else
				type_format = GL_UNSIGNED_INT_8_8_8_8;
			#endif
		#else	// windows or linux
			type_format = GL_UNSIGNED_BYTE;
		#endif
		break;
		
		case 2:
		#if LL_DARWIN
			internal_format = GL_RGBA8;
			primary_format = GL_BGRA_EXT;
			type_format = GL_UNSIGNED_SHORT_1_5_5_5_REV;
			#if LL_LITTLE_ENDIAN
				swap_bytes = TRUE;
			#endif
		#else	// windows or linux
			// MBW -- XXX -- This is just a guess on my part.  Someone needs to verify which GL texture format matches the 16-bit format used on windows.
			internal_format = GL_RGB8;
			primary_format = GL_RGB;
			type_format = GL_UNSIGNED_SHORT_5_6_5;
		#endif
		break;
	}
	
	// will create mWidth * mHeight sized texture, using BGR ordering
	LLDynamicTexture::generateGLTexture(internal_format, primary_format, type_format, swap_bytes);


	S32 width  = llmin(media_width, mBrowserWidth);
	S32 height = llmin(media_height, mBrowserHeight);

	S32 media_data_width  = mMediaSource->getMediaDataWidth();
	S32 media_data_height = mMediaSource->getMediaDataHeight();

	if (pixels)
	{
		mTexture->setSubImage( pixels, media_data_width, media_data_height,
							   0, 0, width, height );
	}
	
	mLastBrowserDepth = media_depth;
}