Example #1
0
void PostProcessor::_initBlur()
{
	m_extractBloomProgram = _createShaderProgram(vertexShader, extractBloomShader);
	glUseProgram(m_extractBloomProgram);
	int loc = glGetUniformLocation(m_extractBloomProgram, "Sample0");
	assert(loc >= 0);
	glUniform1i(loc, 0);
	loc = glGetUniformLocation(m_extractBloomProgram, "ThresholdLevel");
	assert(loc >= 0);
	glUniform1i(loc, config.bloomFilter.thresholdLevel);

	m_seperableBlurProgram = _createShaderProgram(vertexShader, seperableBlurShader);
	glUseProgram(m_seperableBlurProgram);
	loc = glGetUniformLocation(m_seperableBlurProgram, "Sample0");
	assert(loc >= 0);
	glUniform1i(loc, 0);
	loc = glGetUniformLocation(m_seperableBlurProgram, "TexelSize");
	assert(loc >= 0);
	glUniform2f(loc, 1.0f / video().getWidth(), 1.0f / video().getHeight());
	loc = glGetUniformLocation(m_seperableBlurProgram, "Orientation");
	assert(loc >= 0);
	glUniform1i(loc, 0);
	loc = glGetUniformLocation(m_seperableBlurProgram, "BlurAmount");
	assert(loc >= 0);
	glUniform1i(loc, config.bloomFilter.blurAmount);
	loc = glGetUniformLocation(m_seperableBlurProgram, "BlurScale");
	assert(loc >= 0);
	glUniform1f(loc, 1.0f);
	loc = glGetUniformLocation(m_seperableBlurProgram, "BlurStrength");
	assert(loc >= 0);
	glUniform1f(loc, config.bloomFilter.blurStrength/100.0f);

	m_glowProgram = _createShaderProgram(vertexShader, glowShader);
	glUseProgram(m_glowProgram);
	loc = glGetUniformLocation(m_glowProgram, "Sample0");
	assert(loc >= 0);
	glUniform1i(loc, 0);
	loc = glGetUniformLocation(m_glowProgram, "Sample1");
	assert(loc >= 0);
	glUniform1i(loc, 1);
	loc = glGetUniformLocation(m_glowProgram, "BlendMode");
	assert(loc >= 0);
	glUniform1i(loc, config.bloomFilter.blendMode);

	m_pTextureGlowMap = _createTexture();
	m_pTextureBlur = _createTexture();

	m_FBO_glowMap = _createFBO(m_pTextureGlowMap);
	m_FBO_blur = _createFBO(m_pTextureBlur);

	glUseProgram(0);
}
Example #2
0
void ParticleRenderer::_initGL()
{
    m_vertexShader = glCreateShader(GL_VERTEX_SHADER);
    m_pixelShader = glCreateShader(GL_FRAGMENT_SHADER);

    const char* v = vertexShader;
    const char* p = pixelShader;
    glShaderSource(m_vertexShader, 1, &v, 0);
    glShaderSource(m_pixelShader, 1, &p, 0);
    
    glCompileShader(m_vertexShader);
    glCompileShader(m_pixelShader);

    m_program = glCreateProgram();

    glAttachShader(m_program, m_vertexShader);
    glAttachShader(m_program, m_pixelShader);

    glLinkProgram(m_program);

    _createTexture(32);

    glGenBuffers(1, (GLuint*)&m_vboColor);
    glBindBuffer( GL_ARRAY_BUFFER_ARB, m_vboColor);
    glBufferData( GL_ARRAY_BUFFER_ARB, m_numParticles * 4 * sizeof(float), 0, GL_STATIC_DRAW_ARB);
    glBindBuffer( GL_ARRAY_BUFFER_ARB, 0);
}
void PostProcessor::_initCommon()
{
	m_pTextureOriginal = _createTexture();
	m_FBO_original = _createFBO(m_pTextureOriginal);

	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
Example #4
0
void TextureNode::prepareBackTexture( const QSize& size, TextureFormat )
{
    if( _backTexture->textureSize() == size )
        return;

    _backTexture = _createTexture( size );
}
Example #5
0
//------------------------------------------------------------------------------
// ctor
//------------------------------------------------------------------------------
cDirectX9Texture::cDirectX9Texture( s32 iWidth, s32 iHeight, u32 flags )
{
	X_BreakOutIf(!gpkDirect3DDevice);
	RefObjectInit(cDirectX9Texture);
	mkDimension.dx = (i2d)iWidth;
	mkDimension.dy = (i2d)iHeight;
	_createTexture( 0, flags );
}
Example #6
0
TextureNode::TextureNode( const QSize& size, QQuickWindow* window,
                          TextureFormat )
    : _window( window )
    , _frontTexture( window->createTextureFromId( 0 , QSize( 1 ,1 )))
    , _backTexture( _createTexture( size ))
{
    setTexture( _frontTexture.get( ));
    setFiltering( QSGTexture::Linear );
    setMipmapFiltering( QSGTexture::Linear );
}
Example #7
0
	void TextureManager::create(const Size &Size)
	{
		remove();

		for (int k = 0; k < 1; k++)
		{
		     _createTexture(mTextures[k], mTextureNames[k], Size);
		}

		mHydrax->getMaterialManager()->reload(MaterialManager::MAT_WATER);

		mCreated = true;
	}
Example #8
0
void PostProcessor::_initCommon()
{
	if (config.video.multisampling != 0) {
		m_pTextureResolved = _createTexture();
		m_FBO_resolved = _createFBO(m_pTextureResolved);
	}

	m_pResultBuffer = new FrameBuffer();
	_initTexture(m_pResultBuffer->m_pTexture);
	_initFBO(m_pResultBuffer->m_FBO, m_pResultBuffer->m_pTexture);

	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
void ParticleRenderer::_initGL()
{
    m_vertexShader = glCreateShader(GL_VERTEX_SHADER);
    m_fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    const char *v = vertexShader;
    const char *f = fragmentShader;
    glShaderSource(m_vertexShader, 1, &v, 0);
    glShaderSource(m_fragmentShader, 1, &f, 0);

    checkGLErrors("Shader Source");

    glCompileShader(m_vertexShader);
    glCompileShader(m_fragmentShader);

    if (!CheckCompiled(m_vertexShader) || !CheckCompiled(m_fragmentShader))
    {
        printf("A shader failed to compile.\n");
        exit(1);
    }

    m_programSprites = glCreateProgram();

    checkGLErrors("create program");

    glAttachShader(m_programSprites, m_vertexShader);
    glAttachShader(m_programSprites, m_fragmentShader);

    checkGLErrors("attaching shaders");

    glLinkProgram(m_programSprites);

    checkGLErrors("linking program");

    EGLint linked;
    glGetProgramiv(m_programSprites, GL_LINK_STATUS, &linked);
    if (!linked)
    {
        printf ("A shader failed to link.\n");
        exit(1);
    }

    _createTexture(32);

    glGenBuffers(1, (GLuint *)&m_vboColor);
    glBindBuffer(GL_ARRAY_BUFFER, m_vboColor);
    glBufferData(GL_ARRAY_BUFFER, m_numParticles * 4 * sizeof(float), 0, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Example #10
0
void ParticleRenderer::_initGL()
{
    m_program_sphere = _compileProgram(vertexShader_sphere, pixelShader_sphere);
	m_program_cosmos   = _compileProgram(vertexShader_cosmos,   pixelShader_cosmos); _createTexture(32);

#if !defined(__APPLE__) && !defined(MACOSX)
    glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE);
    glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);
#endif

	// load floor texture
	char imagePath[] = "../src/data/floortile.ppm";
    if (imagePath == 0) {
        fprintf(stderr, "Error finding floor image file\n");
        fprintf(stderr, "  FAILED\n");
        exit(EXIT_FAILURE);
    }
    floorTex = loadTexture(imagePath);
   
    // load sky texture
	char imagePath2[] = "../src/data/pansky2.ppm";
    if (imagePath2 == 0) {
        fprintf(stderr, "Error finding floor image file\n");
        fprintf(stderr, "  FAILED\n");
        exit(EXIT_FAILURE);
    }
    
    skyboxTex[0] = loadTexture("../src/data/faesky02back.ppm");
    skyboxTex[1] = loadTexture("../src/data/faesky02down.ppm");
    skyboxTex[2] = loadTexture("../src/data/faesky02front.ppm");
    skyboxTex[3] = loadTexture("../src/data/faesky02left.ppm");
    skyboxTex[4] = loadTexture("../src/data/faesky02right.ppm");
    skyboxTex[5] = loadTexture("../src/data/faesky02up.ppm");    
     
    for (int i=0; i<6; i++){
		glBindTexture(GL_TEXTURE_2D, skyboxTex[i]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
		
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glBindTexture(GL_TEXTURE_2D, 0);
	}
    //floorProg = new GLSLProgram(floorVS, floorPS);	
}
Example #11
0
//------------------------------------------------------------------------------
// ctor
//------------------------------------------------------------------------------
cDirectX9Texture::cDirectX9Texture( cSoftwareTexture *Image, u32 flags )
{
	X_BreakOutIf(!gpkDirect3DDevice);
	RefObjectInit(cDirectX9Texture);
	
	bool generateMipLevels = (flags & TCF_MIPMAPS) != 0;

	if (Image)
	{
		_createTexture( Image, flags );

		if(mpkTexture)
		{
			if ( _copyTexture( Image ) && generateMipLevels )
			{
				_createMipMaps();
				muFlags |= HasMipMaps;
			}				
		}
		else
			ReportBug( ERROR1, "cDirectX9Texture" );
	}
}
void ProcessedMaterial::_setStageData()
{
   // Only do this once
   if ( mHasSetStageData ) 
      return;
   mHasSetStageData = true;

   U32 i;

   // Load up all the textures for every possible stage
   for( i=0; i<Material::MAX_STAGES; i++ )
   {
      // DiffuseMap
      if( mMaterial->mDiffuseMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_DiffuseMap, _createTexture( mMaterial->mDiffuseMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if (!mStages[i].getTex( MFT_DiffuseMap ))
         {
            mMaterial->logError("Failed to load diffuse map %s for stage %i", _getTexturePath(mMaterial->mDiffuseMapFilename[i]).c_str(), i);
            
            // Load a debug texture to make it clear to the user 
            // that the texture for this stage was missing.
            mStages[i].setTex( MFT_DiffuseMap, _createTexture( GFXTextureManager::getMissingTexturePath().c_str(), &GFXDefaultStaticDiffuseProfile ) );
         }
      }

      // OverlayMap
      if( mMaterial->mOverlayMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_OverlayMap, _createTexture( mMaterial->mOverlayMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_OverlayMap ))
            mMaterial->logError("Failed to load overlay map %s for stage %i", _getTexturePath(mMaterial->mOverlayMapFilename[i]).c_str(), i);
      }

      // LightMap
      if( mMaterial->mLightMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_LightMap, _createTexture( mMaterial->mLightMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_LightMap ))
            mMaterial->logError("Failed to load light map %s for stage %i", _getTexturePath(mMaterial->mLightMapFilename[i]).c_str(), i);
      }

      // ToneMap
      if( mMaterial->mToneMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_ToneMap, _createTexture( mMaterial->mToneMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_ToneMap ))
            mMaterial->logError("Failed to load tone map %s for stage %i", _getTexturePath(mMaterial->mToneMapFilename[i]).c_str(), i);
      }

      // DetailMap
      if( mMaterial->mDetailMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_DetailMap, _createTexture( mMaterial->mDetailMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_DetailMap ))
            mMaterial->logError("Failed to load detail map %s for stage %i", _getTexturePath(mMaterial->mDetailMapFilename[i]).c_str(), i);
      }

      // NormalMap
      if( mMaterial->mNormalMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_NormalMap, _createTexture( mMaterial->mNormalMapFilename[i], &GFXDefaultStaticNormalMapProfile ) );
         if(!mStages[i].getTex( MFT_NormalMap ))
            mMaterial->logError("Failed to load normal map %s for stage %i", _getTexturePath(mMaterial->mNormalMapFilename[i]).c_str(), i);
      }

      // Detail Normal Map
      if( mMaterial->mDetailNormalMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_DetailNormalMap, _createTexture( mMaterial->mDetailNormalMapFilename[i], &GFXDefaultStaticNormalMapProfile ) );
         if(!mStages[i].getTex( MFT_DetailNormalMap ))
            mMaterial->logError("Failed to load normal map %s for stage %i", _getTexturePath(mMaterial->mDetailNormalMapFilename[i]).c_str(), i);
      }
      
      // SpecularMap
      if( mMaterial->mSpecularMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_SpecularMap, _createTexture( mMaterial->mSpecularMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_SpecularMap ))
            mMaterial->logError("Failed to load specular map %s for stage %i", _getTexturePath(mMaterial->mSpecularMapFilename[i]).c_str(), i);
      }
   //Sahara
	  // AccuMap
      if( mMaterial->mAccuMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_AccuMap, _createTexture( mMaterial->mAccuMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_AccuMap ))
            mMaterial->logError("Failed to load accu map %s for stage %i", _getTexturePath(mMaterial->mAccuMapFilename[i]).c_str(), i);
      }
   //Sahara
      // EnironmentMap
      if( mMaterial->mEnvMapFilename[i].isNotEmpty() )
      {
         mStages[i].setTex( MFT_EnvMap, _createTexture( mMaterial->mEnvMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
         if(!mStages[i].getTex( MFT_EnvMap ))
            mMaterial->logError("Failed to load environment map %s for stage %i", _getTexturePath(mMaterial->mEnvMapFilename[i]).c_str(), i);
      }
   }

	mMaterial->mCubemapData = dynamic_cast<CubemapData*>(Sim::findObject( mMaterial->mCubemapName ));
	if( !mMaterial->mCubemapData )
		mMaterial->mCubemapData = NULL;
		
		
   // If we have a cubemap put it on stage 0 (cubemaps only supported on stage 0)
   if( mMaterial->mCubemapData )
   {
      mMaterial->mCubemapData->createMap();
      mStages[0].setCubemap( mMaterial->mCubemapData->mCubemap ); 
      if ( !mStages[0].getCubemap() )
         mMaterial->logError("Failed to load cubemap");
   }
}
void ProcessedCustomMaterial::_setStageData()
{
   // Only do this once
   if ( mHasSetStageData ) 
      return;
   mHasSetStageData = true;   

   ShaderRenderPassData* rpd = _getRPD(0);   
   mConditionerMacros.clear();

   // Loop through all the possible textures, set the right flags, and load them if needed
   for(U32 i=0; i<CustomMaterial::MAX_TEX_PER_PASS; i++ )
   {
      rpd->mTexType[i] = Material::NoTexture;   // Set none as the default in case none of the cases below catch it.
      String filename = mCustomMaterial->mTexFilename[i];

      if(filename.isEmpty())
         continue;

      if(filename.equal(String("$dynamiclight"), String::NoCase))
      {
         rpd->mTexType[i] = Material::DynamicLight;
         mMaxTex = i+1;
         continue;
      }

      if(filename.equal(String("$dynamiclightmask"), String::NoCase))
      {
         rpd->mTexType[i] = Material::DynamicLightMask;
         mMaxTex = i+1;
         continue;
      }

      if(filename.equal(String("$lightmap"), String::NoCase))
      {
         rpd->mTexType[i] = Material::Lightmap;
         mMaxTex = i+1;
         continue;
      }

      if(filename.equal(String("$cubemap"), String::NoCase))
      {
         if( mCustomMaterial->mCubemapData )
         {
            rpd->mTexType[i] = Material::Cube;
            mMaxTex = i+1;
         }
         else
         {
            mCustomMaterial->logError( "Could not find CubemapData - %s", mCustomMaterial->mCubemapName.c_str());
         }
         continue;
      }

      if(filename.equal(String("$dynamicCubemap"), String::NoCase))
      {
         rpd->mTexType[i] = Material::SGCube;
         mMaxTex = i+1;
         continue;
      }

      if(filename.equal(String("$backbuff"), String::NoCase))
      {
         rpd->mTexType[i] = Material::BackBuff;
         mMaxTex = i+1;
         continue;
      }

      if(filename.equal(String("$reflectbuff"), String::NoCase))
      {
         rpd->mTexType[i] = Material::ReflectBuff;
         mMaxTex = i+1;
         continue;
      }

      if(filename.equal(String("$miscbuff"), String::NoCase))
      {
         rpd->mTexType[i] = Material::Misc;
         mMaxTex = i+1;
         continue;
      }

      // Check for a RenderTexTargetBin assignment
      if (filename.substr( 0, 1 ).equal("#"))
      {
         String texTargetBufferName = filename.substr(1, filename.length() - 1);
         NamedTexTarget *texTarget = NamedTexTarget::find( texTargetBufferName ); 
         rpd->mTexSlot[i].texTarget = texTarget;

         // Get the conditioner macros.
         if ( texTarget )
            texTarget->getShaderMacros( &mConditionerMacros );

         rpd->mTexType[i] = Material::TexTarget;
         mMaxTex = i+1;
         continue;
      }

      rpd->mTexSlot[i].texObject = _createTexture( filename, &GFXDefaultStaticDiffuseProfile );
      if ( !rpd->mTexSlot[i].texObject )
      {
         mMaterial->logError("Failed to load texture %s", _getTexturePath(filename).c_str());
         continue;
      }
      rpd->mTexType[i] = Material::Standard;
      mMaxTex = i+1;
   }

   // We only get one cubemap
   if( mCustomMaterial->mCubemapData )
   {
      mCustomMaterial->mCubemapData->createMap();      
      rpd->mCubeMap = mMaterial->mCubemapData->mCubemap; // BTRTODO ?
      if ( !rpd->mCubeMap )
         mMaterial->logError("Failed to load cubemap");
   }

   // If this has a output target defined, it may be writing 
   // to a tex target bin with a conditioner, so search for 
   // one and add its macros.
   if ( mCustomMaterial->mOutputTarget.isNotEmpty() )
   {
      NamedTexTarget *texTarget = NamedTexTarget::find( mCustomMaterial->mOutputTarget );
      if ( texTarget )
         texTarget->getShaderMacros( &mConditionerMacros );
   }

   // Copy the glow state over.
   mHasGlow = mCustomMaterial->mGlow[0];
}