Ejemplo n.º 1
0
void AtmosphereSample :: WindowResize( Uint32 Width, Uint32 Height )
{
    m_pLightSctrPP->OnWindowResize( m_pDevice, Width, Height );
    // Flush is required because Intel driver does not release resources until
    // command buffer is flushed. When window is resized, WindowResize() is called for
    // every intermediate window size, and light scattering object creates resources
    // for the new size. This resources are then released by the light scattering object, but 
    // not by Intel driver, which results in memory exhaustion.
    m_pImmediateContext->Flush();

    m_pOffscreenColorBuffer.Release();
    m_pOffscreenDepthBuffer.Release();

    TextureDesc ColorBuffDesc;
    ColorBuffDesc.Name = "Offscreen color buffer";
    ColorBuffDesc.Type = RESOURCE_DIM_TEX_2D;
    ColorBuffDesc.Width  = Width;
    ColorBuffDesc.Height = Height;
    ColorBuffDesc.MipLevels = 1;
    ColorBuffDesc.Format = TEX_FORMAT_R11G11B10_FLOAT;
    ColorBuffDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET;
    m_pDevice->CreateTexture( ColorBuffDesc, TextureData(), &m_pOffscreenColorBuffer );

    TextureDesc DepthBuffDesc = ColorBuffDesc;
	DepthBuffDesc.Name = "Offscreen depth buffer";
    DepthBuffDesc.Format = TEX_FORMAT_D32_FLOAT;
    DepthBuffDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_DEPTH_STENCIL;
    m_pDevice->CreateTexture( DepthBuffDesc, TextureData(), &m_pOffscreenDepthBuffer );
}
Ejemplo n.º 2
0
void AtmosphereSample::CreateShadowMap()
{
    ReleaseShadowMap();

    static const bool bIs32BitShadowMap = true;
	//ShadowMap
    TextureDesc ShadowMapDesc;
    ShadowMapDesc.Name = "Shadow map";
    ShadowMapDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
    ShadowMapDesc.Width  = m_uiShadowMapResolution;
    ShadowMapDesc.Height = m_uiShadowMapResolution;
    ShadowMapDesc.MipLevels = 1;
    ShadowMapDesc.ArraySize = m_TerrainRenderParams.m_iNumShadowCascades;
    ShadowMapDesc.Format = bIs32BitShadowMap ? TEX_FORMAT_D32_FLOAT : TEX_FORMAT_D16_UNORM;
    ShadowMapDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_DEPTH_STENCIL;

	RefCntAutoPtr<ITexture> ptex2DShadowMap;
	m_pDevice->CreateTexture(ShadowMapDesc, TextureData(), &ptex2DShadowMap);

    m_pShadowMapSRV = ptex2DShadowMap->GetDefaultView( TEXTURE_VIEW_SHADER_RESOURCE );

    m_pShadowMapDSVs.resize(ShadowMapDesc.ArraySize);
    for(Diligent::Uint32 iArrSlice=0; iArrSlice < ShadowMapDesc.ArraySize; iArrSlice++)
    {
        TextureViewDesc ShadowMapDSVDesc;
        ShadowMapDSVDesc.Name = "Shadow map cascade DSV";
        ShadowMapDSVDesc.ViewType = TEXTURE_VIEW_DEPTH_STENCIL;
        ShadowMapDSVDesc.FirstArraySlice = iArrSlice;
        ShadowMapDSVDesc.NumArraySlices = 1;
        ptex2DShadowMap->CreateView(ShadowMapDSVDesc, &m_pShadowMapDSVs[iArrSlice]);
    }
}
Ejemplo n.º 3
0
/**
 * @brief Helper to set basic texture params via config file.
 * @param aName Name of object in texture pairing.
 */
void PCShaderSurface::AddTexturePairing(HashString const &aName)
{
    GLint minFilter = GL_LINEAR;
    GLint magFilter = GL_LINEAR;
    GLint wrapS = GL_REPEAT;
    GLint wrapT = GL_REPEAT;
    if(Constants::GetString("OpenGLMinFilter") == "GL_NEAREST")
    {
        minFilter = GL_NEAREST;
    }
    if(Constants::GetString("OpenGLMagFilter") == "GL_NEAREST")
    {
        magFilter = GL_NEAREST;
    }
    if(Constants::GetString("OpenGLWrapModeS") == "GL_CLAMP_TO_EDGE")
    {
        wrapS = GL_CLAMP_TO_EDGE;
    }
    if(Constants::GetString("OpenGLWrapModeT") == "GL_CLAMP_TO_EDGE")
    {
        wrapT = GL_CLAMP_TO_EDGE;
    }

    glGenTextures(1, &mTextureID);
    glBindTexture(GL_TEXTURE_2D, mTextureID);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mSurface->w, mSurface->h, 0, mTextureFormat, GL_UNSIGNED_BYTE, mSurface->pixels);

    GetManager()->AddTexturePairing(aName, TextureData(mTextureID, mSurface->w, mSurface->h));
}
Ejemplo n.º 4
0
GraphicsManager::GraphicsManager(GameApp *aApp, int aWidth, int aHeight, bool aFullScreen) : Manager(aApp, "GraphicsManager", GraphicsManager::sUID),
                                                                           mSurfaces(), mUIElements(), mTextures(), mShaders(), mScreen(nullptr), mProperties()
{
  // Add Default Texture
  AddTexturePairing(DEFAULT_TEXTURE_NAME, TextureData(-1, 0, 0));
#ifndef SHADER_COMPATIBLE
  mScreen = new PCScreen(aWidth, aHeight, aFullScreen);
#else
  mScreen = new PCShaderScreen(aWidth, aHeight, aFullScreen);
#endif
}
Ejemplo n.º 5
0
TextureData ModelLoader::loadTexture(const string& filename, const aiMaterial* material)
{
    Q_ASSERT(material != nullptr);

    string dir;
    string::size_type slashIndex = filename.find_last_of("/");

    if(slashIndex == string::npos) dir = ".";
    else if(slashIndex == 0) dir = "/";
    else dir = filename.substr(0, slashIndex);

    TextureData data = TextureData();
    aiString path;

    data.hasTexture = false;

//    if(material->GetTextureCount(aiTextureType_DIFFUSE)      > 0) qDebug() << "aiTextureType_DIFFUSE";
//    if(material->GetTextureCount(aiTextureType_SPECULAR)     > 0) qDebug() << "aiTextureType_SPECULAR";
//    if(material->GetTextureCount(aiTextureType_AMBIENT)      > 0) qDebug() << "aiTextureType_AMBIENT";
//    if(material->GetTextureCount(aiTextureType_EMISSIVE)     > 0) qDebug() << "aiTextureType_EMISSIVE";
//    if(material->GetTextureCount(aiTextureType_HEIGHT)       > 0) qDebug() << "aiTextureType_HEIGHT";
//    if(material->GetTextureCount(aiTextureType_NORMALS)      > 0) qDebug() << "aiTextureType_NORMALS";
//    if(material->GetTextureCount(aiTextureType_SHININESS)    > 0) qDebug() << "aiTextureType_SHININESS";
//    if(material->GetTextureCount(aiTextureType_OPACITY)      > 0) qDebug() << "aiTextureType_OPACITY";
//    if(material->GetTextureCount(aiTextureType_DISPLACEMENT) > 0) qDebug() << "aiTextureType_DISPLACEMENT";
//    if(material->GetTextureCount(aiTextureType_LIGHTMAP)     > 0) qDebug() << "aiTextureType_LIGHTMAP";
//    if(material->GetTextureCount(aiTextureType_REFLECTION)   > 0) qDebug() << "aiTextureType_REFLECTION";
//    if(material->GetTextureCount(aiTextureType_UNKNOWN)      > 0) qDebug() << "aiTextureType_UNKNOWN";

    if(material->GetTextureCount(aiTextureType_DIFFUSE) > 0)
    {
        if(material->GetTexture(aiTextureType_DIFFUSE, 0, &path) == AI_SUCCESS)
        {
            string texturePath = dir + "/" + path.data;
            data.filename = texturePath;
            data.hasTexture = true;
        }
    }
    else if(material->GetTextureCount(aiTextureType_OPACITY) > 0)
    {
        if(material->GetTexture(aiTextureType_OPACITY, 0, &path) == AI_SUCCESS)
        {
            string texturePath = dir + "/" + path.data;
            data.filename = texturePath;
            data.hasTexture = true;
        }
    }

    return data;
}
Ejemplo n.º 6
0
bool TextureResource::Load(RenderInterface* render_interface, ImageSource* image_source)
{
    Rocket::Core::Vector2i dimensions;
    TextureHandle handle = reinterpret_cast<TextureHandle>((void*)NULL);
    TextureDataMap::iterator iter = texture_data.find(render_interface);
    if (iter != texture_data.end())
    {
        handle = iter->second.first;
    }
    else
    {
        render_interface->LoadTexture(
            handle,
            dimensions,
            String("?image_source::") + image_source->GetImageSourceName()
        );
    }

    Rocket::Core::byte* data = NULL;
    image_source->GetImage(render_interface, handle, dimensions);
    texture_data[render_interface] = TextureData(handle, dimensions);
    return true;
}
Ejemplo n.º 7
0
Texture1D_D3D11 :: Texture1D_D3D11(IReferenceCounters *pRefCounters, 
                                   FixedBlockMemoryAllocator &TexViewObjAllocator, 
                                   RenderDeviceD3D11Impl *pDeviceD3D11, 
                                   ID3D11Texture1D *pd3d11Texture) : 
    TextureBaseD3D11(pRefCounters, TexViewObjAllocator, pDeviceD3D11, TexDescFromD3D11Texture1D(pd3d11Texture), TextureData())
{
    m_pd3d11Texture = pd3d11Texture;
}
Ejemplo n.º 8
0
    bool TextureManager::getTexture(const std::string& filename, Texture& texture, const sf::IntRect& rect)
    {
        // Look if we already had this image
        auto imageIt = m_ImageMap.find(filename);
        if (imageIt != m_ImageMap.end())
        {
            // Loop all our textures to find the one containing the image
            for (std::list<TextureData>::iterator it = imageIt->second.data.begin(); it != imageIt->second.data.end(); ++it)
            {
                // Only reuse the texture when the exact same part of the image is used
                if (it->rect == rect)
                {
                    // The texture is now used at multiple places
                    ++(it->users);

                    // We already have the texture, so pass the data
                    texture.data = &(*it);

                    // Set the texture in the sprite
                    texture.sprite.setTexture(it->texture, true);

                    return true;
                }
            }
        }
        else // The image doesn't exist yet
        {
            auto it = m_ImageMap.insert(std::make_pair(filename, ImageMapData()));
            imageIt = it.first;
        }

        // Add new data to the list
        imageIt->second.data.push_back(TextureData());
        texture.data = &imageIt->second.data.back();
        texture.data->image = &imageIt->second.image;
        texture.data->rect = rect;

        // load the image
        if (texture.data->image->loadFromFile(filename))
        {
            // Create a texture from the image
            bool success;
            if (rect == sf::IntRect(0, 0, 0, 0))
                success = texture.data->texture.loadFromImage(*texture.data->image);
            else
                success = texture.data->texture.loadFromImage(*texture.data->image, rect);

            if (success)
            {
                // Set the texture in the sprite
                texture.sprite.setTexture(texture.data->texture, true);

                // Set the other members of the data
                texture.data->filename = filename;
                texture.data->users = 1;
                return true;
            }
        }

        // The image couldn't be loaded
        m_ImageMap.erase(imageIt);
        texture.data = nullptr;
        return false;
    }
Ejemplo n.º 9
0
// Attempts to load the texture from the source.
bool TextureResource::Load(RenderInterface* render_interface) const
{
	// Check for special loader tokens.
	if (!source.Empty() &&
		source[0] == '?')
	{
		Vector2i dimensions;

		bool delete_data = false;
		const byte* data = NULL;

		// Find the generation protocol and generate the data accordingly.
		String protocol = source.Substring(1, source.Find("::") - 1);
		if (protocol == "font")
		{
			// The requested texture is a font layer.
			delete_data = true;

			StringList parameters;
			StringUtilities::ExpandString(parameters, source.Substring(source.Find("::") + 2), '/');
			if (parameters.size() == 3)
			{
				FontFaceHandle* handle = (FontFaceHandle*) strtol(parameters[0].CString(), NULL, 16);
				handle->GenerateLayerTexture(data,
											 dimensions,
											 strtol(parameters[1].CString(), NULL, 16),
											 atoi(parameters[2].CString()));
			}
		}

		// If texture data was generated, great! Otherwise, fallback to the LoadTexture() code and
		// hope the client knows what the hell to do with the question mark in their file name.
		if (data != NULL)
		{
			TextureHandle handle;
			bool success = render_interface->GenerateTexture(handle, data, dimensions);

			if (delete_data)
				delete[] data;

			if (success)
			{
				texture_data[render_interface] = TextureData(handle, dimensions);
				return true;
			}
			else
			{
				Log::Message(Log::LT_WARNING, "Failed to generate internal texture %s.", source.CString());
				texture_data[render_interface] = TextureData((TextureHandle)NULL, Vector2i(0, 0));

				return false;
			}
		}
	}

	TextureHandle handle;
	Vector2i dimensions;
	if (!render_interface->LoadTexture(handle, dimensions, source))
	{
		Log::Message(Log::LT_WARNING, "Failed to load texture from %s.", source.CString());
		texture_data[render_interface] = TextureData((TextureHandle)NULL, Vector2i(0, 0));

		return false;
	}

	texture_data[render_interface] = TextureData((TextureHandle)handle, dimensions);
	return true;
}
Ejemplo n.º 10
0
// Attempts to load the texture from the source.
bool TextureResource::Load(RenderInterface* render_interface) const
{
	// Check for special loader tokens.
	if (!source.Empty() &&
		source[0] == '?')
	{
		Vector2i dimensions;

		bool delete_data = false;
		const byte* data = NULL;

		// Find the generation protocol and generate the data accordingly.
		String protocol = source.Substring(1, source.Find("::") - 1);
		if (protocol == "font")
		{
			// The requested texture is a font layer.
			delete_data = true;
			
			FontFaceHandle* handle;
			FontEffect* layer_id;
			int texture_id;
			
			if (sscanf(source.CString(), "?font::%p/%p/%d", &handle, &layer_id, &texture_id) == 3)
			{
				handle->GenerateLayerTexture(data,
											 dimensions,
											 layer_id,
											 texture_id);
			}
		}

		// If texture data was generated, great! Otherwise, fallback to the LoadTexture() code and
		// hope the client knows what the hell to do with the question mark in their file name.
		if (data != NULL)
		{
			TextureHandle handle;
			bool success = render_interface->GenerateTexture(handle, data, dimensions);

			if (delete_data)
				delete[] data;

			if (success)
			{
				texture_data[render_interface] = TextureData(handle, dimensions);
				return true;
			}
			else
			{
				Log::Message(Log::LT_WARNING, "Failed to generate internal texture %s.", source.CString());
				texture_data[render_interface] = TextureData(NULL, Vector2i(0, 0));

				return false;
			}
		}
	}

	TextureHandle handle;
	Vector2i dimensions;
	if (!render_interface->LoadTexture(handle, dimensions, source))
	{
		Log::Message(Log::LT_WARNING, "Failed to load texture from %s.", source.CString());
		texture_data[render_interface] = TextureData(NULL, Vector2i(0, 0));

		return false;
	}

	texture_data[render_interface] = TextureData(handle, dimensions);
	return true;
}