Exemplo n.º 1
0
	void RE_UploadCinematic( int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty )
	{
#if defined( USE_D3D10 )
		// TODO
#else
		GL_Bind( tr.scratchImage[ client ] );

		// if the scratchImage isn't in the format we want, specify it as a new texture
		if ( cols != tr.scratchImage[ client ]->width || rows != tr.scratchImage[ client ]->height )
		{
			tr.scratchImage[ client ]->width = tr.scratchImage[ client ]->uploadWidth = cols;
			tr.scratchImage[ client ]->height = tr.scratchImage[ client ]->uploadHeight = rows;

			qglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, cols, rows, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );

			qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

			qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
			qglTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
			qglTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, colorBlack );
		}
		else
		{
			if ( dirty )
			{
				// otherwise, just subimage upload it so that drivers can tell we are going to be changing
				// it and don't try and do a texture compression
				qglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, GL_RGBA, GL_UNSIGNED_BYTE, data );
			}
		}

		GL_CheckErrors();
#endif
	}
Exemplo n.º 2
0
/*
========================
idImage::SetTexParameters
========================
*/
void idImage::SetTexParameters() {
	int target = GL_TEXTURE_2D;
	switch ( opts.textureType ) {
		case TT_2D:
			target = GL_TEXTURE_2D;
			break;
		case TT_CUBIC:
			target = GL_TEXTURE_CUBE_MAP_EXT;
			break;
		default:
			idLib::FatalError( "%s: bad texture type %d", GetName(), opts.textureType );
			return;
	}

	// ALPHA, LUMINANCE, LUMINANCE_ALPHA, and INTENSITY have been removed
	// in OpenGL 3.2. In order to mimic those modes, we use the swizzle operators
#if defined( USE_CORE_PROFILE )
	if ( opts.colorFormat == CFM_GREEN_ALPHA ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );
	} else if ( opts.format == FMT_LUM8 ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_ONE );
	} else if ( opts.format == FMT_L8A8 ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );
	} else if ( opts.format == FMT_ALPHA ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );
	} else if ( opts.format == FMT_INT8 ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );
	} else {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_RED );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_GREEN );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_BLUE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_ALPHA );
	}
#else
	if ( opts.colorFormat == CFM_GREEN_ALPHA ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_GREEN );
	} else if ( opts.format == FMT_ALPHA ) {
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_R, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_G, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_B, GL_ONE );
		qglTexParameteri( target, GL_TEXTURE_SWIZZLE_A, GL_RED );
	}
#endif

	switch( filter ) {
		case TF_DEFAULT:
			if ( r_useTrilinearFiltering.GetBool() ) {
				qglTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
			} else {
				qglTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
			}
			qglTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			break;
		case TF_LINEAR:
			qglTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			qglTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			break;
		case TF_NEAREST:
			qglTexParameterf( target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
			qglTexParameterf( target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
			break;
		default:
			common->FatalError( "%s: bad texture filter %d", GetName(), filter );
	}

	if ( glConfig.anisotropicFilterAvailable ) {
		// only do aniso filtering on mip mapped images
		if ( filter == TF_DEFAULT ) {
			int aniso = r_maxAnisotropicFiltering.GetInteger();
			if ( aniso > glConfig.maxTextureAnisotropy ) {
				aniso = glConfig.maxTextureAnisotropy;
			}
			if ( aniso < 0 ) {
				aniso = 0;
			}
			qglTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
		} else {
			qglTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1 );
		}
	}
	if ( glConfig.textureLODBiasAvailable && ( usage != TD_FONT ) ) {
		// use a blurring LOD bias in combination with high anisotropy to fix our aliasing grate textures...
		qglTexParameterf(target, GL_TEXTURE_LOD_BIAS_EXT, r_lodBias.GetFloat() );
	}

	// set the wrap/clamp modes
	switch( repeat ) {
		case TR_REPEAT:
			qglTexParameterf( target, GL_TEXTURE_WRAP_S, GL_REPEAT );
			qglTexParameterf( target, GL_TEXTURE_WRAP_T, GL_REPEAT );
			break;
		case TR_CLAMP_TO_ZERO: {
			float color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
			qglTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, color );
			qglTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
			qglTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
			}
			break;
		case TR_CLAMP_TO_ZERO_ALPHA: {
			float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
			qglTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, color );
			qglTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
			qglTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
			}
			break;
		case TR_CLAMP:
			qglTexParameterf( target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
			qglTexParameterf( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
			break;
		default:
			common->FatalError( "%s: bad texture repeat %d", GetName(), repeat );
	}
}