void DeferredContainer::makeTarget() {
    if(Window::getInstance()->getSize() == gBuffer.getSize()) return;
    vec2ui size = Window::getInstance()->getSize();
    GBDepth = Texture2D(size, TextureFormat::DEPTH_COMPONENT32F);
    GBDepth.setFilter(GL_NEAREST, GL_NEAREST);
    GBColor0 = Texture2D(size, TextureFormat::RGBA16F);
    GBColor0.setFilter(GL_NEAREST, GL_NEAREST);
    GBColor1 = Texture2D(size, TextureFormat::RGBA16F);
    GBColor1.setFilter(GL_NEAREST, GL_NEAREST);
    gBuffer = RenderTarget(size.x, size.y);
    gBuffer.setTexture(RenderTargetBase::DEPTH, &GBDepth); //Z-BUFFER
    gBuffer.setTexture(RenderTargetBase::COLOR0, &GBColor0); //COLOR
    gBuffer.setTexture(RenderTargetBase::COLOR1, &GBColor1); //NORMAL, BRIGHTNESS, SPECULAR FACTOR
    if(sunTarget.getSize() == vec2ui(0)) { //invalid (this is the first makeTarget() )
        SDepth = Texture2DArray(vec3ui(4096,4096, NUM_SUN_CASCADES), TextureFormat::DEPTH_COMPONENT32F);
        SDepth.setFilter(GL_LINEAR, GL_LINEAR);
        SDepth.setComparison(GL_GREATER);
        sunTarget = RenderTargetLayered(4096, 4096, NUM_SUN_CASCADES);
        sunTarget.setTexture(RenderTargetBase::DEPTH, &SDepth); //Z-BUFFER

        SDepthTrans = Texture2DArray(vec3ui(4096,4096, NUM_SUN_CASCADES), TextureFormat::DEPTH_COMPONENT32F);
        SDepthTrans.setFilter(GL_LINEAR, GL_LINEAR);
        SDepthTrans.setComparison(GL_GREATER);
        sunTargetTrans = RenderTargetLayered(4096, 4096, NUM_SUN_CASCADES);
        sunTargetTrans.setTexture(RenderTargetBase::DEPTH, &SDepthTrans); //Z-BUFFER
    }
}
Esempio n. 2
0
GraphicStore::GraphicStore(GraphicContext &gc) : shader_color_geometry(gc)
{
    // Create a depth buffer
    framebuffer_depth = FrameBuffer(gc);
    texture_depth = Texture2D(gc, gc.get_size(), tf_depth_component32);
    texture_depth.set_wrap_mode(wrap_clamp_to_edge, wrap_clamp_to_edge);
    framebuffer_depth.attach_depth(texture_depth);

    // Load graphics
    texture_alpha = Texture2D(gc, "Resources/alpha_ball.png");
    texture_solid = Texture2D(gc, "Resources/alpha_ball2.png");
    texture_alpha.set_wrap_mode(wrap_clamp_to_edge, wrap_clamp_to_edge);
    texture_solid.set_wrap_mode(wrap_clamp_to_edge, wrap_clamp_to_edge);

}
Esempio n. 3
0
Texture2D::Texture2D(GraphicContext &context, const PixelBuffer &image, const Rect &src_rect, bool is_srgb)
{
	*this = Texture2D(context, src_rect.get_width(), src_rect.get_height(), is_srgb ? tf_srgb8_alpha8 : tf_rgba8);

	set_subimage(context, Point(0, 0), image, src_rect, 0);
	impl->provider->set_wrap_mode(impl->wrap_mode_s, impl->wrap_mode_t);
}
//----------------------------------------------------------------------------
void NonlocalBlowup::BuildSquareDomain ()
{
    // Create a texture representing the domain.  This will be used by the
    // shader for drawing the domain and graph of temperature.
    mDomainTexture = new0 Texture2D(Texture::TF_A8R8G8B8, DIMENSION,
        DIMENSION, 1);
    mDomainTexture->GenerateMipmaps();
    unsigned char* data = (unsigned char*)mDomainTexture->GetData(0);
    memset(data, 0, NUMSAMPLES*sizeof(unsigned char));

    // Create a domain mask that is 1 at interior samples of the square and 0
    // at boundary samples of the square.
    mDomain.ClearPixels();
    for (int y = 1; y < DIMENSION-1; ++y)
    {
        for (int x = 1; x < DIMENSION-1; ++x)
        {
            mDomain(x, y) = 255;
            data[4*(x + DIMENSION*y) + 0] = 255;
            data[4*(x + DIMENSION*y) + 1] = 255;
            data[4*(x + DIMENSION*y) + 2] = 255;
            data[4*(x + DIMENSION*y) + 3] = 255;
        }
    }
}
//----------------------------------------------------------------------------
void NonlocalBlowup::CreateInitialHeight ()
{
    mHeightTexture = new0 Texture2D(Texture::TF_R32F, DIMENSION,
        DIMENSION, 1);
    memcpy(mHeightTexture->GetData(0), mInitialData.GetPixels1D(),
        NUMSAMPLES*sizeof(float));
}
Esempio n. 6
0
	Texture2D::Texture2D(GraphicContext &context, const std::string &fullname, const ImageImportDescription &import_desc)
	{
		std::string path = PathHelp::get_fullpath(fullname, PathHelp::path_type_file);
		std::string filename = PathHelp::get_filename(fullname, PathHelp::path_type_file);
		FileSystem vfs(path);
		*this = Texture2D(context, filename, vfs, import_desc);
	}
Esempio n. 7
0
Texture2D ShadowMapEntry::get_view() const
{
	if (impl->index != -1)
		return impl->shadow_maps->views[impl->index];
	else
		return Texture2D();
}
void GlobalIlluminationPass::InitDestinationTexture(D3DRenderer* renderer, int width, int height)
{
	NE_DELETE(mpDestinationTexture);

	mpDestinationTexture = NE_NEW Texture2D();
	mpDestinationTexture->Init(renderer, width, height, DXGI_FORMAT_R16G16B16A16_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS);
	mpDestinationTexture->setDebugName("Global Illumination RT");
}
Esempio n. 9
0
//-------------------------------------------------------------------------------------------------------
FakeLightNode::FakeLightNode( LightType type )
    :LightNode( type, LS_FAKE ),
     m_pTexture(NULL),
     m_pRendBuffer(NULL),
     m_pVertexBuffer(NULL),
     m_pIndicesBuffer(NULL)
{
    m_pTexture = NEW Texture2D();
}
Esempio n. 10
0
//----------------------------------------------------------------------------
void Smoke2D::CreateFluidUpdateEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.FluidUpdate2",
        1, 1, 3, 3, false);
    pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2,
        Shader::VS_TEXCOORD0);
    pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    pshader->SetConstant(0, "SpaceParam", 1);
    pshader->SetConstant(1, "TimeParam", 1);
    pshader->SetConstant(2, "ViscParam", 1);
    pshader->SetSampler(0, "StateSampler", Shader::ST_2D);
    pshader->SetSampler(1, "AdvectionSampler", Shader::ST_2D);
    pshader->SetSampler(2, "SourceSampler", Shader::ST_2D);
    pshader->SetFilter(1, Shader::SF_LINEAR);
    pshader->SetBaseRegisters(msFluidUpdatePRegisters);
    pshader->SetTextureUnits(msFluidUpdatePTextureUnits);
    pshader->SetPrograms(msFluidUpdatePPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    ShaderFloat* spaceParamConstant = new0 ShaderFloat(1);
    float* spaceParam = spaceParamConstant->GetData();
    spaceParam[0] = mDx;
    spaceParam[1] = mDy;
    spaceParam[2] = 1.0f/(float)mIMax;
    spaceParam[3] = 1.0f/(float)mJMax;
    instance->SetPixelConstant(0, "SpaceParam", spaceParamConstant);

    ShaderFloat* timeParamConstant = new0 ShaderFloat(1);
    float* timeParam = timeParamConstant->GetData();
    timeParam[0] = mDtDivDx;
    timeParam[1] = mDtDivDy;
    timeParam[2] = mDt;
    instance->SetPixelConstant(0, "TimeParam", timeParamConstant);

    ShaderFloat* viscParamConstant = new0 ShaderFloat(1);
    float* viscParam = viscParamConstant->GetData();
    viscParam[0] = mDenLambdaX;
    viscParam[1] = mDenLambdaY;
    viscParam[2] = mVelLambdaX;
    viscParam[3] = mVelLambdaY;
    instance->SetPixelConstant(0, "ViscParam", viscParamConstant);

    mSourceTexture = new0 Texture2D(Texture::TF_A32B32G32R32F, mIMaxP1,
        mJMaxP1, 1);
    ComputeSource();

    instance->SetPixelTexture(0, "StateSampler",
        mIP->GetTarget(1)->GetColorTexture(0));
    instance->SetPixelTexture(0, "AdvectionSampler",
        mIP->GetTarget(4)->GetColorTexture(0));
    instance->SetPixelTexture(0, "SourceSampler", mSourceTexture);

    mRenderer->Bind(mSourceTexture);
}
Esempio n. 11
0
Texture2D::Texture2D( GraphicContext &context, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc)
{
	PixelBuffer pb = ImageProviderFactory::load(filename, fs, std::string());
	pb = import_desc.process(pb);

	*this = Texture2D(context, pb.get_width(), pb.get_height(), import_desc.is_srgb() ? tf_srgb8_alpha8 : tf_rgba8);

	set_subimage(context, Point(0, 0), pb, Rect(pb.get_size()), 0);
	impl->provider->set_wrap_mode(impl->wrap_mode_s, impl->wrap_mode_t);
}
Esempio n. 12
0
	Resource<Texture> FileDisplayCache::get_texture(GraphicContext &gc, const std::string &id)
	{
		auto it = textures.find(id);
		if (it != textures.end())
			return it->second;

		Resource<Texture> texture = Texture2D(gc, id, doc.get_file_system());
		textures[id] = texture;
		return texture;
	}
Esempio n. 13
0
    void FrameBuffer::AddAttachment(GLenum internalFormat, GLenum format, GLenum type)
    {
        mAttachments.push_back(Texture2D());
        Texture2D &attachement = mAttachments.back();
        attachement.Init(internalFormat, ivec2(mWidth, mHeight), format, type);

        Bind();
        glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttachments[mAttachments.size() - 1], GL_TEXTURE_2D, attachement.ID(), 0);
        UnBind();
    }
Esempio n. 14
0
//----------------------------------------------------------------------------
void Smoke2D::CreateDrawDensityEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.DrawDensity2",
        1, 1, 0, 3, false);
    pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2,
        Shader::VS_TEXCOORD0);
    pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    pshader->SetSampler(0, "StateSampler", Shader::ST_2D);
    pshader->SetSampler(1, "ColorTableSampler", Shader::ST_1D);
    pshader->SetSampler(2, "VortexSampler", Shader::ST_2D);
    pshader->SetFilter(1, Shader::SF_LINEAR);
    pshader->SetTextureUnits(msDrawDensityPTextureUnits);
    pshader->SetPrograms(msDrawDensityPPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    // For pseudocoloring density.
    mGrayTexture = new0 Texture1D(Texture::TF_A8R8G8B8, 8, 1);
    unsigned char* gray = (unsigned char*)mGrayTexture->GetData(0);
    gray[ 0] =   0;  gray[ 1] =   0;  gray[ 2] =   0;  gray[ 3] = 255;
    gray[ 4] =  32;  gray[ 5] =  32;  gray[ 6] =  32;  gray[ 7] = 255;
    gray[ 8] =  64;  gray[ 9] =  64;  gray[10] =  64;  gray[11] = 255;
    gray[12] =  96;  gray[13] =  96;  gray[14] =  96;  gray[15] = 255;
    gray[16] = 128;  gray[17] = 128;  gray[18] = 128;  gray[19] = 255;
    gray[20] = 160;  gray[21] = 160;  gray[22] = 160;  gray[23] = 255;
    gray[24] = 192;  gray[25] = 192;  gray[26] = 192;  gray[27] = 255;
    gray[28] = 255;  gray[29] = 255;  gray[30] = 255;  gray[31] = 255;

    mColorTexture = new0 Texture1D(Texture::TF_A8R8G8B8, 8, 1);
    unsigned char* color = (unsigned char*)mColorTexture->GetData(0);
    color[ 0] =   0;  color[ 1] =   0;  color[ 2] =   0;  color[ 3] = 255;
    color[ 4] = 255;  color[ 5] =   0;  color[ 6] = 128;  color[ 7] = 255;
    color[ 8] = 255;  color[ 9] =   0;  color[10] =   0;  color[11] = 255;
    color[12] =   0;  color[13] = 255;  color[14] =   0;  color[15] = 255;
    color[16] =   0;  color[17] = 255;  color[18] = 255;  color[19] = 255;
    color[20] =   0;  color[21] = 128;  color[22] = 255;  color[23] = 255;
    color[24] =   0;  color[25] =   0;  color[26] = 255;  color[27] = 255;
    color[28] = 255;  color[29] = 255;  color[30] = 255;  color[31] = 255;

    // For vortex-center overlay.
    mVortexTexture = new0 Texture2D(Texture::TF_A8R8G8B8, mIMaxP1,
        mJMaxP1, 1);
    memset(mVortexTexture->GetData(0), 0, 4*mNumPixels);

    instance->SetPixelTexture(0, "StateSampler",
        mIP->GetTarget(1)->GetColorTexture(0));
    instance->SetPixelTexture(0, "ColorTableSampler", mGrayTexture);
    instance->SetPixelTexture(0, "VortexSampler", mVortexTexture);

    mRenderer->Bind(mGrayTexture);
    mRenderer->Bind(mColorTexture);
    mRenderer->Bind(mVortexTexture);
}
Esempio n. 15
0
void LightsourceSimplePass::setup(GraphicContext &gc)
{
	Size viewport_size = viewport->get_size();
	if (fb.is_null() || !gc.is_frame_buffer_owner(fb) || final_color.updated() || zbuffer.updated() || diffuse_color_gbuffer.updated())
	{
		final_color.set(Texture2D(gc, viewport->get_width(), viewport->get_height(), tf_rgba16f));

		fb = FrameBuffer(gc);
		fb.attach_color(0, final_color.get());
		fb.attach_depth(zbuffer.get());

		BlendStateDescription blend_desc;
		blend_desc.enable_blending(true);
		blend_desc.set_blend_function(blend_one, blend_one, blend_one, blend_one);
		blend_state = BlendState(gc, blend_desc);

		DepthStencilStateDescription icosahedron_depth_stencil_desc;
		icosahedron_depth_stencil_desc.enable_depth_write(false);
		icosahedron_depth_stencil_desc.enable_depth_test(true);
		icosahedron_depth_stencil_desc.set_depth_compare_function(compare_lequal);
		icosahedron_depth_stencil_state = DepthStencilState(gc, icosahedron_depth_stencil_desc);

		RasterizerStateDescription icosahedron_rasterizer_desc;
		icosahedron_rasterizer_desc.set_culled(true);
		icosahedron_rasterizer_state = RasterizerState(gc, icosahedron_rasterizer_desc);

		DepthStencilStateDescription rect_depth_stencil_desc;
		rect_depth_stencil_desc.enable_depth_write(false);
		rect_depth_stencil_desc.enable_depth_test(false);
		rect_depth_stencil_state = DepthStencilState(gc, rect_depth_stencil_desc);

		RasterizerStateDescription rect_rasterizer_desc;
		rect_rasterizer_desc.set_culled(false);
		rect_rasterizer_state = RasterizerState(gc, rect_rasterizer_desc);

		uniforms = UniformVector<Uniforms>(gc, 1);

		icosahedron_prim_array = PrimitivesArray(gc);
		icosahedron_prim_array.set_attributes(0, icosahedron->vertices);

		Vec4f positions[6] =
		{
			Vec4f(-1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f, -1.0f, 1.0f, 1.0f),
			Vec4f(-1.0f,  1.0f, 1.0f, 1.0f),
			Vec4f( 1.0f,  1.0f, 1.0f, 1.0f)
		};
		rect_positions = VertexArrayVector<Vec4f>(gc, positions, 6);

		rect_prim_array  = PrimitivesArray(gc);
		rect_prim_array.set_attributes(0, rect_positions);
	}
}
	bool GL3FrameBufferProvider::attach_object(GLenum opengl_attachment, const Texture &texture, int level, int zoffset, GLuint texture_target)
	{
		int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment);

		// Check for object replacement
		bool is_replaced_object = false;
		if (!attached_renderbuffers[internal_attachment_offset].is_null())
		{
			is_replaced_object = true;
			attached_renderbuffers[internal_attachment_offset] = RenderBuffer();
		}
		if (!attached_textures[internal_attachment_offset].is_null())
		{
			is_replaced_object = true;
			attached_textures[internal_attachment_offset] = Texture2D();
		}

		// Store the texture
		attached_textures[internal_attachment_offset] = texture;

		// Bind the renderbuffer
		GL3TextureProvider *gl_texture_provider = dynamic_cast<GL3TextureProvider*>(texture.get_provider());
		if (!gl_texture_provider)
			throw Exception("Invalid texture");

		GLuint texture_type = gl_texture_provider->get_texture_type();
		GLuint texture_handle = gl_texture_provider->get_handle();

		GLenum target = GL_DRAW_FRAMEBUFFER;
		if (bind_target == framebuffer_read)
			target = GL_READ_FRAMEBUFFER;

		if (!texture_target)
			texture_target = texture_type;

		if (texture_type == GL_TEXTURE_1D)
		{
			glFramebufferTexture1D(target, opengl_attachment, texture_target, texture_handle, level);
		}
		else if (texture_type == GL_TEXTURE_2D)
		{
			glFramebufferTexture2D(target, opengl_attachment, texture_target, texture_handle, level);
		}
		else if (texture_type == GL_TEXTURE_3D)
		{
			glFramebufferTexture3D(target, opengl_attachment, texture_target, texture_handle, level, zoffset);
		}
		else if (texture_type == GL_TEXTURE_2D_ARRAY || texture_type == GL_TEXTURE_1D_ARRAY)
		{
			glFramebufferTextureLayer(target, opengl_attachment, texture_handle, level, zoffset);
		}
		return is_replaced_object;
	}
Esempio n. 17
0
void RenderBatchTriangle::flush(GraphicContext &gc)
{
	if (position > 0)
	{
		gc.set_program_object(program_sprite);

		int gpu_index;
		VertexArrayVector<SpriteVertex> gpu_vertices(batch_buffer->get_vertex_buffer(gc, gpu_index));

		if (prim_array[gpu_index].is_null())
		{
			prim_array[gpu_index] = PrimitivesArray(gc);
			prim_array[gpu_index].set_attributes(0, gpu_vertices, cl_offsetof(SpriteVertex, position));
			prim_array[gpu_index].set_attributes(1, gpu_vertices, cl_offsetof(SpriteVertex, color));
			prim_array[gpu_index].set_attributes(2, gpu_vertices, cl_offsetof(SpriteVertex, texcoord));
			prim_array[gpu_index].set_attributes(3, gpu_vertices, cl_offsetof(SpriteVertex, texindex));

			if (glyph_blend.is_null())
			{
				BlendStateDescription blend_desc;
				blend_desc.set_blend_function(blend_constant_color, blend_one_minus_src_color, blend_zero, blend_one);
				glyph_blend = BlendState(gc, blend_desc);
			}
		}

		gpu_vertices.upload_data(gc, 0, vertices, position);

		for (int i = 0; i < num_current_textures; i++)
			gc.set_texture(i, current_textures[i]);

		if (use_glyph_program)
		{
			gc.set_blend_state(glyph_blend, constant_color);
			gc.draw_primitives(type_triangles, position, prim_array[gpu_index]);
			gc.reset_blend_state();
		}
		else
		{
			gc.draw_primitives(type_triangles, position, prim_array[gpu_index]);
		}

		for (int i = 0; i < num_current_textures; i++)
			gc.reset_texture(i);

		gc.reset_program_object();

		position = 0;
		for (int i = 0; i < num_current_textures; i++)
			current_textures[i] = Texture2D();
		num_current_textures = 0;

	}
}
Esempio n. 18
0
void GameTerrain::set_area_colors(GraphicContext &gc, const std::vector<unsigned int> &colors)
{
	PixelBuffer buffer_colors(colors.size(), 1, tf_rgba8);
	unsigned int *col = reinterpret_cast<unsigned int *>(buffer_colors.get_data());
	for(unsigned int i=0;i<colors.size();++i)
		col[i] = colors[i];

	texture_colors = Texture2D(gc, area_count+1, 1);
	texture_colors.set_image(buffer_colors);
	texture_colors.set_wrap_mode(wrap_clamp_to_edge, wrap_clamp_to_edge);
	texture_colors.set_min_filter(filter_nearest);
	texture_colors.set_mag_filter(filter_nearest);
}
Esempio n. 19
0
void BloomPass::setup_bloom_extract(GraphicContext &gc)
{
    Size viewport_size = viewport->get_size();
    Size bloom_size = viewport_size / 2;
    if (bloom_contribution->is_null() || bloom_contribution->get_size() != bloom_size || !gc.is_frame_buffer_owner(fb_bloom_extract))
    {
        bloom_contribution.set(Texture2D(gc, bloom_size.width, bloom_size.height, tf_rgba8));

        fb_bloom_extract = FrameBuffer(gc);
        fb_bloom_extract.attach_color(0, bloom_contribution.get());

        bloom_blur.output.set(fb_bloom_extract);
    }
}
Esempio n. 20
0
	Texture2D RenderBatchBuffer::get_texture_r8(GraphicContext &gc)
	{
		current_r8_texture++;
		if (current_r8_texture == num_r8_buffers)
			current_r8_texture = 0;

		if (textures_r8[current_r8_texture].is_null())
		{
			textures_r8[current_r8_texture] = Texture2D(gc, r8_size, r8_size, tf_r8);
			textures_r8[current_r8_texture].set_min_filter(filter_nearest);
			textures_r8[current_r8_texture].set_mag_filter(filter_nearest);
		}
		return textures_r8[current_r8_texture];
	}
Esempio n. 21
0
void CUDARenderer::windowResize(int width, int height) 
{
	skipStep = true;
	h_info.setWidthHeight(width, height);
	camera.width = h_info.width;
	camera.height = h_info.height;
	setImageInfo(h_info);
	dimBlock = dim3(THREAD_DIM, THREAD_DIM, 1);
	dimGrid = dim3(h_info.width / dimBlock.x + (h_info.width % dimBlock.x > 0), h_info.height / dimBlock.y + (h_info.height % dimBlock.y > 0), 1);

	deleteTexture();
	OGLtexture = Texture2D(GL_TEXTURE_2D);
	initTexture();
}
Esempio n. 22
0
	Texture2D RenderBatchBuffer::get_texture_rgba32f(GraphicContext &gc)
	{
		current_rgba32f_texture++;
		if (current_rgba32f_texture == num_r8_buffers)
			current_rgba32f_texture = 0;

		if (textures_rgba32f[current_rgba32f_texture].is_null())
		{
			textures_rgba32f[current_rgba32f_texture] = Texture2D(gc, rgba32f_width, rgba32f_height, tf_rgba32f);
			textures_rgba32f[current_rgba32f_texture].set_min_filter(filter_nearest);
			textures_rgba32f[current_rgba32f_texture].set_mag_filter(filter_nearest);

		}

		return textures_rgba32f[current_rgba32f_texture];
	}
Esempio n. 23
0
	Texture2D * TexManager::add(GLenum textureTarget, const std::string & name, const std::string & filename, GLboolean alpha)
	{
		for (Texture2D* texture : m_Textures)
		{
			if (texture->getName() == name)
			{
				std::string err = "[TexManager]. Texture " + name + " already exists.";
				XTEN_WARN(err);
				return nullptr;
			}
		}

		Texture2D* texture = XNEW Texture2D(textureTarget, name);

		if (alpha)
		{
			texture->m_Internal_Format = GL_RGBA;
			texture->m_Image_Format = GL_RGBA;
		}

		GLsizei width, height;
		GLuint bits;
		//unsigned char* image = SOIL_load_image(filename.c_str(), &width, &height, 0, texture->m_Image_Format == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB);
		//bits = 32;
		BYTE* image = load_image(filename.c_str(), &width, &height, &bits);


		//texture->m_TID = SOIL_load_OGL_texture(filename.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
		if (!image)
		{
			std::string err = "[TexManager]. SOIL loading image error: " + filename + SOIL_last_result();
			XTEN_ERROR(err);
			XDEL(texture);
			return nullptr;
		}

		texture->generate(width, height, bits, image);

		m_Textures.push_back(texture);

		std::string info = "[TexManager]. Added new texture:" + name + " (" + filename + ")";
		XTEN_INFO(info);

		XDEL_ARRAY(image);

		return texture;
	}
Esempio n. 24
0
//----------------------------------------------------------------------------
void Smoke2D::CreateCopyStateEffect (VisualEffect*& effect,
    VisualEffectInstance*& instance)
{
    PixelShader* pshader = new0 PixelShader("Wm5.CopyState2",
        1, 1, 0, 1, false);
    pshader->SetInput(0, "vertexTCoord", Shader::VT_FLOAT2,
        Shader::VS_TEXCOORD0);
    pshader->SetOutput(0, "pixelColor", Shader::VT_FLOAT4,
        Shader::VS_COLOR0);
    pshader->SetSampler(0, "StateSampler", Shader::ST_2D);
    pshader->SetTextureUnits(msCopyStatePTextureUnits);
    pshader->SetPrograms(msCopyStatePPrograms);

    mIP->CreateEffect(pshader, effect, instance);

    mInitialTexture = new0 Texture2D(Texture::TF_A32B32G32R32F, mIMaxP1,
        mJMaxP1, 1);

    if (PixelShader::GetProfile() == PixelShader::PP_ARBFP1)
    {
        float* data = (float*)mInitialTexture->GetData(0);
        for (int j = 0; j <= mJMax; ++j)
        {
            for (int i = 0; i <= mIMax; ++i)
            {
                *data++ = 0.0f;  // velocity.x
                *data++ = 0.0f;  // velocity.y
                *data++ = 0.0f;  // empty
                *data++ = Mathf::UnitRandom();
            }
        }
    }
    else
    {
        Float4* data = (Float4*)mInitialTexture->GetData(0);
        for (int j = 0; j <= mJMax; ++j)
        {
            for (int i = 0; i <= mIMax; ++i)
            {
                data[i + mIMaxP1*(mJMax-j)] = Float4(0.0f, 0.0f, 0.0f,
                    Mathf::UnitRandom());
            }
        }
    }

    mRenderer->Bind(mInitialTexture);
}
Esempio n. 25
0
int run()
{
    int Error(0);

    gli::texture Texture(gli::TARGET_1D, gli::FORMAT_RGBA8_UNORM, gli::texture::texelcoord_type(1), 1, 1, 1);
    gli::texture1D Texture1D(Texture);
    gli::texture1DArray Texture1DArray(Texture);
    gli::texture2D Texture2D(Texture);
    gli::texture2DArray Texture2DArray(Texture);
    gli::texture3D Texture3D(Texture);
    gli::textureCube TextureCube(Texture);
    gli::textureCubeArray TextureCubeArray(Texture);

    Error += Texture == Texture1D ? 0 : 1;
    Error += Texture != Texture1DArray ? 0 : 1;
    Error += Texture != Texture2D ? 0 : 1;
    Error += Texture != Texture2DArray ? 0 : 1;
    Error += Texture != Texture3D ? 0 : 1;
    Error += Texture != TextureCube ? 0 : 1;
    Error += Texture != TextureCubeArray ? 0 : 1;

    gli::texture Texture1D_B(Texture1D);
    gli::texture Texture1DArray_B(Texture1DArray);
    gli::texture Texture2D_B(Texture2D);
    gli::texture Texture2DArray_B(Texture2DArray);
    gli::texture Texture3D_B(Texture3D);
    gli::texture TextureCube_B(TextureCube);
    gli::texture TextureCubeArray_B(TextureCubeArray);

    Error += Texture == Texture1D_B ? 0 : 1;
    Error += Texture != Texture1DArray_B ? 0 : 1;
    Error += Texture != Texture2D_B ? 0 : 1;
    Error += Texture != Texture2DArray_B ? 0 : 1;
    Error += Texture != Texture3D_B ? 0 : 1;
    Error += Texture != TextureCube_B ? 0 : 1;
    Error += Texture != TextureCubeArray_B ? 0 : 1;

    Error += Texture1D == Texture1D_B ? 0 : 1;
    Error += Texture1DArray == Texture1DArray_B ? 0 : 1;
    Error += Texture2D == Texture2D_B ? 0 : 1;
    Error += Texture2DArray == Texture2DArray_B ? 0 : 1;
    Error += Texture3D == Texture3D_B ? 0 : 1;
    Error += TextureCube == TextureCube_B ? 0 : 1;
    Error += TextureCubeArray == TextureCubeArray_B ? 0 : 1;

    return Error;
}
Esempio n. 26
0
	int run()
	{
		int Error(0);

		gli::texture Texture(gli::TARGET_1D, gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture::extent_type(1), 1, 1, 1);
		gli::texture1d Texture1D(Texture);
		gli::texture1d_array Texture1DArray(Texture);
		gli::texture2d Texture2D(Texture);
		gli::texture2d_array Texture2DArray(Texture);
		gli::texture3d Texture3D(Texture);
		gli::texture_cube TextureCube(Texture);
		gli::texture_cube_array TextureCubeArray(Texture);

		Error += Texture == Texture1D ? 0 : 1;
		Error += Texture != Texture1DArray ? 0 : 1;
		Error += Texture != Texture2D ? 0 : 1;
		Error += Texture != Texture2DArray ? 0 : 1;
		Error += Texture != Texture3D ? 0 : 1;
		Error += Texture != TextureCube ? 0 : 1;
		Error += Texture != TextureCubeArray ? 0 : 1;

		gli::texture Texture1D_B(Texture1D);
		gli::texture Texture1DArray_B(Texture1DArray);
		gli::texture Texture2D_B(Texture2D);
		gli::texture Texture2DArray_B(Texture2DArray);
		gli::texture Texture3D_B(Texture3D);
		gli::texture TextureCube_B(TextureCube);
		gli::texture TextureCubeArray_B(TextureCubeArray);

		Error += Texture == Texture1D_B ? 0 : 1;
		Error += Texture != Texture1DArray_B ? 0 : 1;
		Error += Texture != Texture2D_B ? 0 : 1;
		Error += Texture != Texture2DArray_B ? 0 : 1;
		Error += Texture != Texture3D_B ? 0 : 1;
		Error += Texture != TextureCube_B ? 0 : 1;
		Error += Texture != TextureCubeArray_B ? 0 : 1;

		Error += Texture1D == Texture1D_B ? 0 : 1;
		Error += Texture1DArray == Texture1DArray_B ? 0 : 1;
		Error += Texture2D == Texture2D_B ? 0 : 1;
		Error += Texture2DArray == Texture2DArray_B ? 0 : 1;
		Error += Texture3D == Texture3D_B ? 0 : 1;
		Error += TextureCube == TextureCube_B ? 0 : 1;
		Error += TextureCubeArray == TextureCubeArray_B ? 0 : 1;

		return Error;
	}
	void GL3FrameBufferProvider::on_dispose()
	{
		if (handle)
		{
			OpenGL::set_active(gc_provider);
			glDeleteFramebuffers(1, &handle);
			handle = 0;
		}

		// Detach all textures and renderbuffers
		for (int cnt = 0; cnt < num_attachment_offsets; cnt++)
		{
			if (!attached_textures[cnt].is_null())
				attached_textures[cnt] = Texture2D();

			if (!attached_renderbuffers[cnt].is_null())
				attached_renderbuffers[cnt] = RenderBuffer();
		}
		gc_provider->remove_disposable(this);
	}
	//-------------------------------------------------------------------------------------------------------
	SSAOPostEffect::SSAOPostEffect(void)
		:IPostEffect( 300 )
	{
		Engine::Instance().GetPipeline()->NeedNoramlBuffer();
		m_JitterTex = NEW Texture2D();
		m_JitterTex->LoadTexture( Device::PF_R8G8B8, FILEPATH.TextureFolder() + "Jitter.tga");
		m_JitterTex->SetWarp( Device::TW_REPEAT, Device::TW_REPEAT );
		vector2d size = Engine::Instance().GetDevice()->GetResolutionSize();
		m_pDownSimple_1 = NEW RenderTarget(size / 4, Device::FBO_TCOLOR);
		m_pDownSimple_2 = NEW RenderTarget(size / 4, Device::FBO_TCOLOR);

		{//初始化数值
			GaussSpread = 2;
			GaussRho = 1.1;
			AOIntensity = 2.5f;
			AOEdgeFinder = 0.01f;
			JitterAmount = 0.05f;
			GaussWeight.resize(4);
			_MakeupGuassParam();
		}
		//engine::Instance().GetActionManage()->OnKeyDownEvent( MEMBER_FUNC_PTR( &SSAOPostEffect::OnKeyDown ) );
	}
Esempio n. 29
0
    void SceneGPUData::Init(const Scene *scene)
    {
        mScene = scene;

        // Load mesh to memory
        for(const TriangleMesh &mesh : scene->mTriMeshes)
        {
            mVertexArrays.push_back(VertexArray(GL_STATIC_DRAW));
            VertexArray &VA = mVertexArrays.back();
            VA.Init(&mesh);
        }
        LOG(INFO) << "[SceneGPUData::Init] Loaded meshes to GPU.";
        // Load textures to memory
        for(const Material &mat : scene->mMaterials) {
            for(const Material::TextureInfo &texInfo : mat.mTextureMaps) {
                if(mNameToTex.find(texInfo.name) == mNameToTex.end()) {
                    mNameToTex[texInfo.name] = Texture2D(texInfo.name.c_str(), true);
                }
            }
        }
        LOG(INFO) << "[SceneGPUData::Init] Loaded textures to GPU.";
    }
Esempio n. 30
0
//-------------------------------------------------------------------------------------------------------
BString::BString(StringManager* father, const wstring& wstr, int height, const vector2f& screensize, const vector2d& orgiSize, const Color& clr, RendBuffer* buffer, const vector2d& texSize, const byte* pBuffer )
    :m_String(wstr),
     m_Father( father ),
     m_MaxHeight(height),
     m_isManaged(true),
     m_isShow(true),
     m_fScale(1,1),
     m_StringTextureSize(orgiSize),
     m_ScreenFontSize( screensize ),
     m_eAlign(Center)
{
    m_pTex = NEW Texture2D();
    m_pTex->MakeTexture( Device::PF_A8, 1, texSize, pBuffer );

    const vector2d& resolution = Engine::Instance().GetDevice()->GetResolutionSize();
    m_Size = vector2f(
                 static_cast<float>(orgiSize.m_x) / static_cast<float>(resolution.m_x),
                 static_cast<float>(orgiSize.m_y) / static_cast<float>(resolution.m_y)
             );
    m_Size *= 2.0f;//转换到屏幕级别
    vector2f scrrenPos = m_Size;// * 2.0f;


    vector2f coord;
    coord.m_x = static_cast<float>(orgiSize.m_x) / texSize.m_x;
    coord.m_y = static_cast<float>(orgiSize.m_y) / texSize.m_y;

    m_pVertex = NEW VertexTextureColor[COUNT_OF_VERTEX];
    m_pVertex[0] = VertexTextureColor(vector4f(0,0,0), vector2f(0,0), clr);
    m_pVertex[1] = VertexTextureColor(vector4f(0,-scrrenPos.m_y,0), vector2f(0,coord.m_y), clr);
    m_pVertex[2] = VertexTextureColor(vector4f(scrrenPos.m_x,0,0), vector2f(coord.m_x,0), clr);
    m_pVertex[3] = VertexTextureColor(vector4f(scrrenPos.m_x,-scrrenPos.m_y,0), vector2f(coord.m_x,coord.m_y), clr);

    ASSERT( NULL != buffer );
    m_pRendBuffer = buffer;
    m_pRendBuffer->GetVertexBuffer()->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertex );
}