Texture::Texture(const Image& image, MipmapGeneration mipmapGeneration, TextureFiltering filtering, bool clamp, const GLInfo& glInfo)
{
   glGenTextures(1, &id);

   Bind();

   bool linearFiltering = (filtering == TextureFiltering::Linear);

   GLint minFilterParam;

   if (mipmapGeneration == MipmapGeneration::None)
   {
      minFilterParam = linearFiltering ? GL_LINEAR : GL_NEAREST;
   }
   else
   {
      minFilterParam = linearFiltering ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_LINEAR;
   }

   GLint magFilterParam = linearFiltering ? GL_LINEAR : GL_NEAREST;

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilterParam);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilterParam);

   GenerateMipmaps(image, mipmapGeneration, glInfo);

   bool doClamp = (clamp && (GLEW_VERSION_1_2 || glewIsExtensionSupported("GL_EXT_texture_edge_clamp")));

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, doClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, doClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
}
RenderVolumeCollection* VoxelMipmapRenderPass::Execute (const Scene* scene, const Camera* camera, RenderVolumeCollection* rvc)
{
	if (_firstTime || _continuousVoxelization) {

		/*
		* Start mipmapping pass
		*/

		StartVoxelMipmaping ();

		/*
		* Mipmapping pass
		*/

		GenerateMipmaps (rvc);

		/*
		* End mipmapping pass
		*/

		EndVoxelMipmaping ();

		_firstTime = false;
	}

	return rvc;
}
Exemple #3
0
bool CD3DTexture::CreateInternal(const void* pixels /* nullptr */, unsigned int srcPitch /* 0 */)
{
  ID3D11Device* pD3DDevice = g_Windowing.Get3D11Device();
  ID3D11DeviceContext* pD3D11Context = g_Windowing.Get3D11Context();

  UINT miscFlags = 0;
  bool autogenmm = false;
  if (m_mipLevels == 0 && g_Windowing.IsFormatSupport(m_format, D3D11_FORMAT_SUPPORT_MIP_AUTOGEN))
  {
    autogenmm = pixels != nullptr;
    miscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
  }
  else
    m_mipLevels = 1;

  CD3D11_TEXTURE2D_DESC textureDesc(m_format, m_width, m_height, 1, m_mipLevels, m_bindFlags, m_usage, m_cpuFlags, 1, 0, miscFlags);
  D3D11_SUBRESOURCE_DATA initData = { 0 };
  initData.pSysMem = pixels;
  initData.SysMemPitch = srcPitch ? srcPitch : CD3DHelper::BitsPerPixel(m_format) * m_width / 8;
  initData.SysMemSlicePitch = 0;

  HRESULT hr = pD3DDevice->CreateTexture2D(&textureDesc, (!autogenmm && pixels) ? &initData : nullptr, &m_texture);
  if (SUCCEEDED(hr) && autogenmm)
  {
    pD3D11Context->UpdateSubresource(m_texture, 0, nullptr, pixels,
      (srcPitch ? srcPitch : CD3DHelper::BitsPerPixel(m_format) * m_width / 8), 0);
  }

  if (autogenmm)
    GenerateMipmaps();

  return SUCCEEDED(hr);
}
Exemple #4
0
	void TextureOpenGL::check_mips() {
		if (m_mip_filter!=TEX_FILTER_NONE) {
			if (!m_have_mipmaps) {
				GenerateMipmaps();
			}
		}
	}
Exemple #5
0
//-----------------------------------------------------------------------------
// Gets the texture all internally consistent assuming you've loaded
// mip 0 of all faces of all frames
//-----------------------------------------------------------------------------
void CVTFTexture::PostProcess(bool bGenerateSpheremap, LookDir_t lookDir)
{
	Assert( m_Format == IMAGE_FORMAT_RGBA8888 );

	// Set up the cube map faces
	if (IsCubeMap())
	{
		// Rotate the cubemaps so they're appropriate for the material system
		FixCubemapFaceOrientation();

		// FIXME: We could theoretically not compute spheremap mip levels
		// in generate spheremaps; should we? The trick is when external
		// clients can be expected to call it

		// Compute the spheremap fallback for cubemaps if we weren't able to load up one...
		if (bGenerateSpheremap)
			GenerateSpheremap(lookDir);
	}

	// Generate mipmap levels
	GenerateMipmaps();

	if( Flags() & TEXTUREFLAGS_ONEOVERMIPLEVELINALPHA )
	{
		PutOneOverMipLevelInAlpha();
	}
	
	// Compute reflectivity
	ComputeReflectivity();

	// Are we 8-bit or 1-bit alpha?
	// NOTE: We have to do this *after*	computing the spheremap fallback for
	// cubemaps or it'll throw the flags off
	ComputeAlphaFlags();
}
void Texture2D::ApplyTextureParameters(bool _generateMipmaps)
{
	// Check if we should generate the mipmaps
	if (_generateMipmaps)
	{
		// Generate the mipmaps
		GenerateMipmaps();
	}

	// Check if we have a param list
	if (m_NameArray.size())
	{
		// For each param
		for (int i = 0; i < m_NameArray.size(); i++)
		{
			// Apply the param
			glTexParameteri(GL_TEXTURE_2D, m_NameArray[i], m_Param[i]);
		}
	}
	// Use the default param list
	else
	{
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		_generateMipmaps ? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) : glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	}
}
Exemple #7
0
void Texture::AllocateResources()
{
	glGenTextures(1, &mTextureId);
	glBindTexture(GL_TEXTURE_2D, mTextureId);
	SetUpFilter();
	SetUpWrapping();

	if (mDataType == DF_UNSIGNED_CHAR)
	{
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	}

	glTexImage2D(GL_TEXTURE_2D, 0, mBytesPerPixel, mWidth, mHeight, 0, GetInternalFormatMapping(), GetDataTypeMapping(), mpData);

	if (mFilter == FM_MIPMAPS)
	{
		GenerateMipmaps();
	}

	// TODO: check allocation errors!
}