Example #1
0
	void PNGLoader::create_image()
	{
		if (bit_depth <= 8)
			image = PixelBuffer(image_width, image_height, force_srgb ? tf_srgb8_alpha8 : tf_rgba8);
		else
			image = PixelBuffer(image_width, image_height, tf_rgba16);
	}
Example #2
0
PixelBuffer ImageProviderFactory::try_load(
	const std::string &filename,
	const std::string &type,
	const FileSystem &fs,
	std::string *out_failure_reason,
	bool srgb)
{
	try
	{
		return load(filename, fs, type, srgb);
	}
	catch (const Exception& e)
	{
		if (out_failure_reason)
			*out_failure_reason = e.message;
		return PixelBuffer();
	}
}
bool initTexture()
{
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glGenTextures(1, &TextureName);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, TextureName);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	// Set image
	gli::texture2D Texture(gli::loadStorageDDS(glf::DATA_DIRECTORY + TEXTURE_DIFFUSE));
	for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
	{
		glTexImage2D(
			GL_TEXTURE_2D, 
			GLint(Level), 
			GL_RGB8, 
			GLsizei(Texture[Level].dimensions().x), 
			GLsizei(Texture[Level].dimensions().y), 
			0,
			GL_BGR, 
			GL_UNSIGNED_BYTE, 
			NULL);
	}

	GLsizei TextureSize = GLsizei(Texture[0].dimensions().x) * GLsizei(Texture[0].dimensions().y) * 3;

	GLuint PixelBuffer(0);
	glGenBuffers(1, &PixelBuffer);
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, PixelBuffer);
	glBufferData(GL_PIXEL_UNPACK_BUFFER, TextureSize, NULL, GL_STREAM_DRAW);
	void* Pointer = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, TextureSize, GL_MAP_WRITE_BIT);
	memcpy(Pointer, Texture[0].data(), TextureSize);
	glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);

	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GLsizei(Texture.dimensions().x), GLsizei(Texture.dimensions().y), GL_BGR, GL_UNSIGNED_BYTE, NULL);
	glDeleteBuffers(1, &PixelBuffer);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

	return glf::checkError("initTexture");
}
LightsourceSimplePass::LightsourceSimplePass(GraphicContext &gc, const std::string &shader_path, ResourceContainer &inout)
{
	viewport = inout.get<Rect>("Viewport");
	field_of_view = inout.get<float>("FieldOfView");
	world_to_eye = inout.get<Mat4f>("WorldToEye");
	diffuse_color_gbuffer = inout.get<Texture2D>("DiffuseColorGBuffer");
	specular_color_gbuffer = inout.get<Texture2D>("SpecularColorGBuffer");
	specular_level_gbuffer = inout.get<Texture2D>("SpecularLevelGBuffer");
	self_illumination_gbuffer = inout.get<Texture2D>("SelfIlluminationGBuffer");
	normal_z_gbuffer = inout.get<Texture2D>("NormalZGBuffer");
	shadow_maps = inout.get<Texture2DArray>("ShadowMaps");
	zbuffer = inout.get<Texture2D>("ZBuffer");

	final_color = inout.get<Texture2D>("FinalColor");

	icosahedron_light_program = compile_and_link(gc, shader_path, "icosahedron");
	rect_light_program = compile_and_link(gc, shader_path, "rect");

	light_instance_texture = Texture1D(gc, max_lights * vectors_per_light, tf_rgba32f);
	light_instance_transfer = PixelBuffer(max_lights * vectors_per_light, 1, tf_rgba32f);

	icosahedron.reset(new Icosahedron(gc, true));
}
Example #5
0
void BoxStyle::set_background_image(const std::string &url)
{
    impl->background.image = PixelBuffer(url);
    if (impl->style_changed) impl->style_changed();
}
	PixelBuffer OpenGLWindowProvider::get_clipboard_image() const
	{
		return PixelBuffer();
	}
void GL1TextureProvider::create(int new_width, int new_height, int new_depth, int array_size, TextureFormat texture_format, int levels)
{
    throw_if_disposed();

    GLint gl_internal_format;
    GLenum gl_pixel_format;
    to_opengl_textureformat(texture_format, gl_internal_format, gl_pixel_format);

    if ( (new_width > 32768) || (new_width < 1) )
    {
        throw Exception("Invalid texture width in the GL1 target");
    }

    if ( (texture_type == GL_TEXTURE_2D) || (texture_type == GL_TEXTURE_3D) )
    {
        if ( (new_height > 32768) || (new_height < 1) )
        {
            throw Exception("Invalid texture height in the GL1 target");
        }
    }

    if ( texture_type == GL_TEXTURE_3D )
    {
        if ( (new_depth > 32768) || (new_depth < 1) )
        {
            throw Exception("Invalid texture depth in the GL1 target");
        }
    }

    width = new_width;
    height = new_height;
    depth = new_depth;
    GL1TextureStateTracker state_tracker(texture_type, handle);

#ifndef __ANDROID__
    if (texture_type == GL_TEXTURE_1D)
    {
        pot_width = get_next_power_of_two(new_width);
        if (pot_width == new_width)
        {
            power_of_two_texture=true;
        }
        else
        {
            power_of_two_texture=false;
        }

        pot_ratio_width = (float) width / pot_width;
        glTexImage1D(
            GL_TEXTURE_1D,			// target
            0,						// level
            gl_internal_format,		// internalformat
            pot_width,				// width
            0,						// border
            gl_pixel_format,		// format
            GL_UNSIGNED_BYTE,		// type (it really doesn't matter since nothing is uploaded)
            nullptr);						// texels (0 to avoid uploading)
    }
#endif
    if (texture_type == GL_TEXTURE_2D)
    {
        pot_width = get_next_power_of_two(new_width);
        pot_height = get_next_power_of_two(new_height);
        if ( (pot_width == new_width) && (pot_height == new_height))
        {
            power_of_two_texture=true;
        }
        else
        {
            power_of_two_texture=false;
        }
        pot_ratio_width = (float) width / pot_width;
        pot_ratio_height = (float) height / pot_height;

        glTexImage2D(
            GL_TEXTURE_2D,			// target
            0,						// level
            gl_internal_format,		// internalformat
            pot_width,				// width
            pot_height,				// height
            0,						// border
            gl_pixel_format,		// format
            GL_UNSIGNED_BYTE,		// type (it really doesn't matter since nothing is uploaded)
            nullptr);						// texels (0 to avoid uploading)

        // Clear the whole texture if it is npot
        if (!power_of_two_texture)
        {
            PixelBuffer image = PixelBuffer(pot_width, pot_height, tf_rgba8);
            void *data = image.get_data();
            memset(data, 0, pot_width * pot_height * 4);

            GLenum format;
            GLenum type;
            to_opengl_pixelformat(image, format, type);

            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
            const int bytesPerPixel = image.get_bytes_per_pixel();
#ifndef __ANDROID__
            glPixelStorei(GL_UNPACK_ROW_LENGTH, image.get_pitch() / bytesPerPixel);
            glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
            glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
            glTexImage2D(
                GL_TEXTURE_2D,		// target
                0,					// level
                gl_internal_format,	// internalformat
                pot_width,			// width
                pot_height,			// height
                0,					// border
                format,				// format
                type,				// type
                data);				// texels

        }
    }
    else
    {
        pot_width = get_next_power_of_two(new_width);
        pot_height = get_next_power_of_two(new_height);
        pot_depth = get_next_power_of_two(new_depth);
        pot_ratio_width = (float) width / pot_width;
        pot_ratio_height = (float) height / pot_height;
        pot_ratio_depth = (float) depth / pot_depth;
        if ( (pot_width == new_width) && (pot_height == new_height) && (pot_depth == new_depth))
        {
            power_of_two_texture=true;
        }
        else
        {
            power_of_two_texture=false;
        }

        glTexImage3D(
            GL_TEXTURE_3D,			// target
            0,						// level
            gl_internal_format,		// internalformat
            pot_width,				// width
            pot_height,				// height
            pot_depth,				// depth
            0,						// border
            gl_pixel_format,		// format
            GL_UNSIGNED_BYTE,		// type (it really doesn't matter since nothing is uploaded)
            nullptr);						// texels (0 to avoid uploading)
    }
}