Changeset 2312


Ignore:
Timestamp:
Feb 1, 2013, 3:49:03 PM (6 years ago)
Author:
sam
Message:

gpu: support 1-component (luminance) textures.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/texture.cpp

    r2216 r2312  
    5454    GLenum m_gl_format, m_gl_type;
    5555#endif
     56    int m_bytes_per_elem;
    5657};
    5758
     
    7273
    7374#if defined USE_D3D9 || defined _XBOX
    74     static D3DFORMAT const d3d_formats[] =
     75    static struct
     76    {
     77        D3DFORMAT format;
     78        int bytes;
     79    }
     80    const d3d_formats[] =
    7581    {
    7682        /* Unknown */
    77         D3DFMT_UNKNOWN,
     83        { D3DFMT_UNKNOWN, 0 },
    7884
    7985        /* R8G8B8 */
    8086#   if defined USE_D3D9
    81         D3DFMT_R8G8B8,
    82 #   else
    83         D3DFMT_UNKNOWN,
     87        { D3DFMT_R8G8B8, 3 },
     88#   else
     89        { D3DFMT_UNKNOWN, 0 },
    8490#   endif
    8591
    8692        /* A8R8G8B8 */
    8793#   if defined USE_D3D9
    88         D3DFMT_A8R8G8B8,
     94        { D3DFMT_A8R8G8B8, 4 },
    8995#   else
    9096        /* By default the X360 will swizzle the texture. Ask for linear. */
    91         D3DFMT_LIN_A8R8G8B8,
     97        { D3DFMT_LIN_A8R8G8B8, 4 },
     98#   endif
     99
     100        /* Y8 */
     101#   if defined USE_D3D9
     102        { D3DFMT_L8, 1 },
     103#   else
     104        /* By default the X360 will swizzle the texture. Ask for linear. */
     105        { D3DFMT_LIN_L8, 1 },
    92106#   endif
    93107    };
    94108
    95     D3DFORMAT d3d_format = GET_CLAMPED(d3d_formats, format);
     109    D3DFORMAT d3d_format = GET_CLAMPED(d3d_formats, format).format;
    96110#   if defined USE_D3D9
    97111    int d3d_usage = D3DUSAGE_DYNAMIC;
     
    103117                               d3d_usage, d3d_format,
    104118                               D3DPOOL_DEFAULT, &m_data->m_texture, NULL);
     119    m_data->m_bytes_per_elem = GET_CLAMPED(d3d_formats, format).bytes;
    105120#else
    106121    static struct
     
    108123        GLint internal_format;
    109124        GLenum format, type;
     125        int bytes;
    110126    }
    111127    const gl_formats[] =
    112128    {
    113         /* Unknown */
    114         { 0, 0, 0 },
    115 
    116         /* R8G8B8 */
    117         { GL_RGB, GL_RGB, GL_UNSIGNED_BYTE },
    118 
    119         /* A8R8G8B8 */
     129        { 0, 0, 0, 0 }, /* Unknown */
     130        { GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, 3 }, /* RGB_8 */
     131
    120132#if __CELLOS_LV2__
    121         { GL_ARGB_SCE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV },
     133        { GL_ARGB_SCE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 4 },
     134        { GL_ARGB_SCE, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 4 },
     135        { GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 },
    122136#elif defined __native_client__ || defined HAVE_GLES_2X
    123         { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE },
    124 #else
    125         /* Seems efficient for little endian textures */
    126         { GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV },
    127 #endif
    128 
    129         /* A8B8G8R8 */
    130 #if __CELLOS_LV2__
    131         { GL_ARGB_SCE, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV },
    132 #elif defined __native_client__ || defined HAVE_GLES_2X
     137        { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 4 },
    133138        /* FIXME: if GL_RGBA is not available, we should advertise
    134139         * this format as "not available" on this platform. */
    135         { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE },
     140        { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, 4 },
     141        { GL_R8, GL_R8, GL_UNSIGNED_BYTE, 1 },
    136142#else
    137143        /* Seems efficient for little endian textures */
    138         { GL_RGBA, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV },
     144        { GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ARGB_8 */
     145        { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ABGR_8 */
     146        { GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1 }, /* A8 */
    139147#endif
    140148    };
     
    143151    m_data->m_gl_format = GET_CLAMPED(gl_formats, format).format;
    144152    m_data->m_gl_type = GET_CLAMPED(gl_formats, format).type;
     153    m_data->m_bytes_per_elem = GET_CLAMPED(gl_formats, format).bytes;
    145154
    146155    glGenTextures(1, &m_data->m_texture);
     
    208217    m_data->m_texture->LockRect(0, &rect, NULL, 0);
    209218
     219    int stride = size.x * m_data->m_bytes_per_elem;
    210220    for (int j = 0; j < size.y; j++)
    211221    {
    212222        uint8_t *dst = (uint8_t *)rect.pBits + (origin.y + j) * rect.Pitch;
    213         /* FIXME: the source or destination pitch isn't necessarily 4! */
    214         uint8_t *src = (uint8_t *)data + j * size.x * 4;
    215         memcpy(dst, src, size.x * 4);
     223        uint8_t *src = (uint8_t *)data + j * stride;
     224        memcpy(dst, src, stride);
    216225    }
    217226
  • trunk/src/gpu/texture.h

    r2216 r2312  
    2626    {
    2727        Unknown = 0,
    28         R8G8B8,
    29         A8R8G8B8,
    30         A8B8G8R8,
     28        RGB_8,
     29        ARGB_8,
     30        ABGR_8,
     31        Y_8,
    3132    }
    3233    m_value;
  • trunk/src/tileset.cpp

    r2216 r2312  
    124124        {
    125125        case Image::FORMAT_RGB:
    126             format = PixelFormat::R8G8B8;
     126            format = PixelFormat::RGB_8;
    127127            planes = 3;
    128128            break;
    129129        case Image::FORMAT_RGBA:
    130130        default:
    131             format = PixelFormat::A8R8G8B8;
     131            format = PixelFormat::ARGB_8;
    132132            planes = 4;
    133133            break;
  • trunk/tutorial/04_texture.cpp

    r2277 r2312  
    3737        m_vertices << vec2( 1.0,  1.0);
    3838
    39         m_heightmap = new uint8_t[4 * TEXTURE_WIDTH * 1];
     39        m_heightmap = new uint8_t[TEXTURE_WIDTH * 1];
    4040    }
    4141
     
    5151        /* Generate a new heightmap at the beginning */
    5252        if (m_frames == 0)
    53             memset(m_heightmap, 255, 4 * TEXTURE_WIDTH);
     53            memset(m_heightmap, 255, TEXTURE_WIDTH);
    5454
    5555        /* Scroll left */
    5656        for (int i = 0; i < TEXTURE_WIDTH - 1; i++)
    57             m_heightmap[4 * i] = m_heightmap[4 * i + 4];
     57            m_heightmap[i] = m_heightmap[i + 1];
    5858
    59         int height = m_heightmap[4 * (TEXTURE_WIDTH - 1)];
     59        int height = m_heightmap[TEXTURE_WIDTH - 1];
    6060        height = (height + 127 + 40 * lol::sin(m_frames * 0.03) + rand() % 97 - 38) / 2;
    6161        height = std::max(15, std::min(height, 240));
    62         m_heightmap[4 * (TEXTURE_WIDTH - 1)] = height;
     62        m_heightmap[TEXTURE_WIDTH - 1] = height;
    6363
    6464        /* Update frame counter */
     
    7373        if (!m_ready)
    7474        {
    75             m_texture = new Texture(ivec2(TEXTURE_WIDTH, 1), PixelFormat::A8R8G8B8);
     75            m_texture = new Texture(ivec2(TEXTURE_WIDTH, 1), PixelFormat::Y_8);
    7676
    7777            m_shader = Shader::Create(LOLFX_RESOURCE_NAME(04_texture));
     
    118118    System::Init(argc, argv);
    119119
    120     Application app("Tutorial 4: Texture", ivec2(640, 480), 60.0f);
     120    Application app("Tutorial 4: Texture", ivec2(1280, 720), 60.0f);
    121121
    122122    new TextureDemo();
  • trunk/tutorial/11_fractal.cpp

    r2277 r2312  
    443443             * so that we can upload four different subimages each frame. */
    444444            m_texture = new Texture(ivec2(m_size.x / 2, m_size.y * 2),
    445                                     PixelFormat::A8B8G8R8);
     445                                    PixelFormat::ABGR_8);
    446446
    447447            /* Ensure the texture data is complete at least once, otherwise
Note: See TracChangeset for help on using the changeset viewer.