bool LLWebBrowserTexture::updateBrowserTexture()
{
	if (!adjustSize())
		return false;
		
	LLPluginClassMedia* media = mMediaSource->getMediaPlugin();
	
	if(!media->textureValid())
		return false;
	
	if(mMediaSource->mNeedsNewTexture
		|| media->getTextureWidth() != getFullWidth()
		|| media->getTextureHeight() != getFullHeight() )
	{
		//releaseGLTexture();
		
		mFullWidth = media->getTextureWidth();
		mFullHeight = media->getTextureHeight();
		mTextureCoordsOpenGL = media->getTextureCoordsOpenGL();

		const LLColor4U fill_color(0,0,0,255);
		// will create mWidth * mHeight sized texture, using the texture params specified by the media.
		generateGLTexture(
				media->getTextureFormatInternal(), 
				media->getTextureFormatPrimary(), 
				media->getTextureFormatType(), 
				media->getTextureFormatSwapBytes(),
				&fill_color); //Initialize the texture to black.


		mMediaSource->mNeedsNewTexture = false;
	}
	
	return true;
}
		void createTexture()
		{
			// create the texture used to display the browser data
			if(mMediaSource->textureValid())
			{
				mAppTextureWidth = mMediaSource->getTextureWidth();
				mAppTextureHeight = mMediaSource->getTextureHeight();
				mAppTextureCoordsOpenGL = mMediaSource->getTextureCoordsOpenGL();
				
				if(mAppTexture != 0)
				{
					glDeleteTextures( 1, &mAppTexture );
					mAppTexture = 0;
				}
				
				glGenTextures( 1, &mAppTexture );
				glBindTexture( GL_TEXTURE_2D, mAppTexture );
				glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
				glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
				glTexImage2D( GL_TEXTURE_2D, 0,
						mMediaSource->getTextureFormatInternal(),
						mAppTextureWidth, 
						mAppTextureHeight,
						0, 
						mMediaSource->getTextureFormatPrimary(), 
						mMediaSource->getTextureFormatType(), 
						NULL );
			}
		}
Esempio n. 3
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;
}
/*LLViewerMediaTexture*/LLViewerTexture* LLViewerMediaImpl::updatePlaceholderImage()
{
	if(mTextureId.isNull())
	{
		// The code that created this instance will read from the plugin's bits.
		return NULL;
	}
	
	LLViewerMediaTexture* placeholder_image = (LLViewerMediaTexture*)LLViewerTextureManager::getFetchedTexture( mTextureId );
	LLPluginClassMedia* plugin = getMediaPlugin();

	placeholder_image->getLastReferencedTimer()->reset();

	if (mNeedsNewTexture 
		|| placeholder_image->getUseMipMaps()
		|| ! placeholder_image->mIsMediaTexture
		|| (placeholder_image->getWidth() != plugin->getTextureWidth())
		|| (placeholder_image->getHeight() != plugin->getTextureHeight())
		|| (mTextureUsedWidth != plugin->getWidth())
		|| (mTextureUsedHeight != plugin->getHeight())
		)
	{
		llinfos << "initializing media placeholder" << llendl;
		llinfos << "movie image id " << mTextureId << llendl;

		int texture_width = plugin->getTextureWidth();
		int texture_height = plugin->getTextureHeight();
		int texture_depth = plugin->getTextureDepth();
		
		// MEDIAOPT: check to see if size actually changed before doing work
		placeholder_image->destroyGLTexture();
		// MEDIAOPT: apparently just calling setUseMipMaps(FALSE) doesn't work?
		placeholder_image->reinit(FALSE);	// probably not needed

		// MEDIAOPT: seems insane that we actually have to make an imageraw then
		// immediately discard it
		LLPointer<LLImageRaw> raw = new LLImageRaw(texture_width, texture_height, texture_depth);
		raw->clear(0x0f, 0x0f, 0x0f, 0xff);
		int discard_level = 0;

		// ask media source for correct GL image format constants
		placeholder_image->setExplicitFormat(plugin->getTextureFormatInternal(),
											 plugin->getTextureFormatPrimary(),
											 plugin->getTextureFormatType(),
											 plugin->getTextureFormatSwapBytes());

		placeholder_image->createGLTexture(discard_level, raw);

		// placeholder_image->setExplicitFormat()
		placeholder_image->setUseMipMaps(FALSE);

		// MEDIAOPT: set this dynamically on play/stop
		placeholder_image->mIsMediaTexture = true;
		mNeedsNewTexture = false;
				
		// If the amount of the texture being drawn by the media goes down in either width or height, 
		// recreate the texture to avoid leaving parts of the old image behind.
		mTextureUsedWidth = plugin->getWidth();
		mTextureUsedHeight = plugin->getHeight();
	}
	
	return placeholder_image;
}
		void display()
		{
			mMediaSource->idle();

			// Check whether the texture needs to be recreated.
			if(mMediaSource->textureValid())
			{
				if(
					(mAppTextureWidth != mMediaSource->getTextureWidth() ||	mAppTextureHeight != mMediaSource->getTextureHeight()) &&
					(mAppWindowWidth == mMediaSource->getWidth() && mAppWindowHeight == mMediaSource->getHeight())
				)
				{
					// Attempt to (re)create the texture
					createTexture();
				}
			}
						
			// clear screen
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

			glLoadIdentity();
			
			if(mAppTexture != 0)
			{
				// use the browser texture
				glBindTexture( GL_TEXTURE_2D, mAppTexture );

				// If dirty, update the texture.
				LLRect dirtyRect;
				if(!mMediaSource->textureValid())
				{
//					LL_DEBUGS("media_plugin_test") << "Resize in progress, skipping update..." << LL_ENDL;
				}
				else if(mAppWindowWidth != mMediaSource->getWidth() || mAppWindowHeight != mMediaSource->getHeight())
				{
					// A resize is in progress.  Just wait for it...
				}
				else if(mMediaSource->getDirty(&dirtyRect))
				{
					// grab the page
					const unsigned char* pixels = mMediaSource->getBitsData();
					if ( pixels )
					{
						// write them into the texture
						
						// Paranoia: intersect dirtyRect with (0, 0, mAppTextureWidth, mAppTextureHeight)?

						int x_offset = dirtyRect.mLeft;
						int y_offset = dirtyRect.mBottom;
						int width = dirtyRect.mRight - dirtyRect.mLeft;
						int height = dirtyRect.mTop - dirtyRect.mBottom;

						LL_DEBUGS("media_plugin_test") << "Updating, dirty rect is (" 
							<< dirtyRect.mLeft << ", " 
							<< dirtyRect.mTop << ", " 
							<< dirtyRect.mRight << ", " 
							<< dirtyRect.mBottom << "), update params are: (" 
							<< x_offset << ", " 
							<< y_offset << ", " 
							<< width << ", " 
							<< height << ")" 
							<< LL_ENDL; 
						
						// Offset the pixels pointer properly
						pixels += (y_offset * mMediaSource->getTextureDepth() * mMediaSource->getTextureWidth());
						pixels += (x_offset * mMediaSource->getTextureDepth());
						
						glPixelStorei(GL_UNPACK_ROW_LENGTH, mMediaSource->getTextureWidth());
						
						glTexSubImage2D( GL_TEXTURE_2D, 0, 
							x_offset, 
							y_offset,
							width, 
							height,
							mMediaSource->getTextureFormatPrimary(), 
							mMediaSource->getTextureFormatType(), 
							pixels );
						
						mMediaSource->resetDirty();
					}
				}
				
				// scale the texture so that it fits the screen
				GLdouble media_texture_x = mAppWindowWidth / (double)mAppTextureWidth;
				GLdouble media_texture_y = mAppWindowHeight / (double)mAppTextureHeight;

				// draw the single quad full screen (orthographic)

				glEnable( GL_TEXTURE_2D );
				glColor3f( 1.0f, 1.0f, 1.0f );
				glBegin( GL_QUADS );
				if(mAppTextureCoordsOpenGL)
				{
					// Render the texture as per opengl coords (where 0,0 is at the lower left)
					glTexCoord2d( 0, 0 );
					glVertex2d( 0, 0 );

					glTexCoord2d( 0 , media_texture_y );
					glVertex2d( 0, mAppWindowHeight);

					glTexCoord2d( media_texture_x, media_texture_y );
					glVertex2d( mAppWindowWidth , mAppWindowHeight);

					glTexCoord2d( media_texture_x, 0 );
					glVertex2d( mAppWindowWidth, 0 );
				}
				else
				{
					// Render the texture the "other way round" (where 0,0 is at the upper left)
					glTexCoord2d( 0, media_texture_y );
					glVertex2d( 0, 0 );

					glTexCoord2d( 0 , 0 );
					glVertex2d( 0, mAppWindowHeight);

					glTexCoord2d( media_texture_x, 0 );
					glVertex2d( mAppWindowWidth , mAppWindowHeight);

					glTexCoord2d( media_texture_x, media_texture_y );
					glVertex2d( mAppWindowWidth, 0 );
				}
				glEnd();

			}
			
			glutSwapBuffers();
		};