当前位置: 首页>>代码示例>>C++>>正文


C++ PixelBuffer::has_transparency方法代码示例

本文整理汇总了C++中PixelBuffer::has_transparency方法的典型用法代码示例。如果您正苦于以下问题:C++ PixelBuffer::has_transparency方法的具体用法?C++ PixelBuffer::has_transparency怎么用?C++ PixelBuffer::has_transparency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PixelBuffer的用法示例。


在下文中一共展示了PixelBuffer::has_transparency方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: state_tracker

void GL1TextureProvider::set_texture_image2d(
    GLuint target,
    PixelBuffer &image,
    int level)
{
    throw_if_disposed();
    GL1TextureStateTracker state_tracker(texture_type, handle);

    GLint gl_internal_format;
    GLenum gl_pixel_format;
    to_opengl_textureformat(image.get_format(), gl_internal_format, gl_pixel_format);


    /*
    	GL_UNPACK_SWAP_BYTES
    	GL_UNPACK_LSB_FIRST
    	GL_UNPACK_SKIP_ROWS
    	GL_UNPACK_SKIP_PIXELS

    	GL_UNPACK_ROW_LENGTH
    	GL_UNPACK_ALIGNMENT
    	GL_UNPACK_IMAGE_HEIGHT
    	GL_UNPACK_SKIP_IMAGES
    */

    // check out if the original texture needs or doesn't need an alpha channel
    bool needs_alpha = image.has_transparency();

    GLenum format;
    GLenum type;
    bool conv_needed = !to_opengl_pixelformat(image, format, type);

    // also check for the pitch (GL1 can only skip pixels, not bytes)
    if (!conv_needed)
    {
        const int bytesPerPixel = image.get_bytes_per_pixel();
        if (image.get_pitch() % bytesPerPixel != 0)
            conv_needed = true;
    }

    // no conversion needed
    if (!conv_needed)
    {
        // Upload to GL1:

        // change alignment
        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
        char *data = (char *) image.get_data();
        int image_width = image.get_width();
        int image_height = image.get_height();
        /*
        		int image_width = 1;
        		int image_height = 1;
        		while (image_width < image.get_width()) image_width *= 2;
        		while (image_height < image.get_height()) image_height *= 2;
        */
        glTexImage2D(
            target,                   // target
            level,                    // level
            gl_internal_format,           // internalformat
            image_width,              // width
            image_height,             // height
            0,						 // border
            format,                   // format
            type,                     // type
            data);                    // texels
    }
    // conversion needed
    else
    {
        bool big_endian = Endian::is_system_big();

        PixelBuffer buffer(
            image.get_width(), image.get_height(),
            needs_alpha ? tf_rgba8 : tf_rgb8);

        buffer.set_image(image);

        format = needs_alpha ? GL_RGBA : GL_RGB;

        // Upload to OpenGL:

        // change alignment
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        const int bytesPerPixel = buffer.get_bytes_per_pixel();
#ifndef __ANDROID__
        glPixelStorei(GL_UNPACK_ROW_LENGTH, buffer.get_pitch() / bytesPerPixel);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
        // upload
        glTexImage2D(
            target,                   // target
            level,                    // level
//.........这里部分代码省略.........
开发者ID:doughdemon,项目名称:ClanLib,代码行数:101,代码来源:gl1_texture_provider.cpp

示例2: Exception

void GL1TextureProvider::copy_from(GraphicContext &gc, int x, int y, int slice, int level, const PixelBuffer &ximage, const Rect &src_rect)
{
    OpenGL::set_active(gc);

    PixelBuffer image = ximage;

    if (src_rect.left < 0 || src_rect.top < 0 || src_rect.right > image.get_width() || src_rect.bottom > image.get_height())
        throw Exception("Rectangle out of bounds");

    throw_if_disposed();
    GL1TextureStateTracker state_tracker(texture_type, handle);

    // check out if the original texture needs or doesn't need an alpha channel
    bool needs_alpha = image.has_transparency();

    GLenum format;
    GLenum type;
    bool conv_needed = !to_opengl_pixelformat(image, format, type);

    // also check for the pitch (GL1 can only skip pixels, not bytes)
    if (!conv_needed)
    {
        const int bytesPerPixel = image.get_bytes_per_pixel();
        if (image.get_pitch() % bytesPerPixel != 0)
            conv_needed = true;
    }

    // no conversion needed
    if (!conv_needed)
    {
        // change alignment
        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, src_rect.left);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, src_rect.top);
#endif

    }
    // conversion needed
    else
    {
        bool big_endian = Endian::is_system_big();

        PixelBuffer buffer(
            src_rect.get_width(), src_rect.get_height(),
            needs_alpha ? tf_rgba8 : tf_rgb8);

        buffer.set_subimage(image, Point(0, 0), src_rect);

        format = needs_alpha ? GL_RGBA : GL_RGB;

        // Upload to GL1:
        glBindTexture(GL_TEXTURE_2D, handle);

        // change alignment
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        const int bytesPerPixel = buffer.get_bytes_per_pixel();
#ifndef __ANDROID__
        glPixelStorei(GL_UNPACK_ROW_LENGTH, buffer.get_pitch() / bytesPerPixel);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif

        type = GL_UNSIGNED_BYTE;
        image = buffer;
    }

    // upload
    glTexSubImage2D(
        GL_TEXTURE_2D,            // target
        level,                    // level
        x, y,                     // xoffset, yoffset
        src_rect.get_width(),        // width
        src_rect.get_height(),       // height
        format,					  // format
        type,					  // type
        image.get_data());        // texels

    if (!power_of_two_texture)
    {
        // TODO: This needs corrected.It should be optimised and currently it does not write to the lower right quadrant

        // Check extend the right edge
        int right_edge = x + image.get_width();
        if ( right_edge >= width )
        {
            char *edge_data = (char *) image.get_data();
            edge_data += image.get_bytes_per_pixel() * (width-1);

            for(int edge_cnt = right_edge; edge_cnt < pot_width; edge_cnt++)
            {
                glTexSubImage2D(
                    GL_TEXTURE_2D,		// target
                    level,				// level
                    edge_cnt, y,		// xoffset, yoffset
                    1,					// width
                    src_rect.get_height(),	// height
                    format,				// format
//.........这里部分代码省略.........
开发者ID:doughdemon,项目名称:ClanLib,代码行数:101,代码来源:gl1_texture_provider.cpp


注:本文中的PixelBuffer::has_transparency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。