Changeset 1074


Ignore:
Timestamp:
Nov 17, 2011, 4:42:44 PM (12 years ago)
Author:
gary
Message:

tutorial: create texture with the proper format and type on the PS3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/tutorial/tut03.cpp

    r1073 r1074  
    3131#endif
    3232
     33#ifdef __CELLOS_LV2__
     34static GLint const INTERNAL_FORMAT = GL_ARGB_SCE;
     35static GLenum const TEXTURE_FORMAT = GL_BGRA;
     36static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV;
     37#else
     38/* Seems efficient for little endian textures */
     39static GLint const INTERNAL_FORMAT = GL_RGBA;
     40static GLenum const TEXTURE_FORMAT = GL_BGRA;
     41static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV;
     42#endif
     43
    3344class Fractal : public WorldEntity
    3445{
     
    136147            double oldradius = m_radius;
    137148#ifdef __CELLOS_LV2__
    138             m_radius *= pow(2.0, -deltams * 0.0005);
     149            m_radius *= pow(2.0, -deltams * 0.00005);
    139150            m_center = f64cmplx(0.001643721971153, 0.822467633298876);
    140151#else
     
    178189        if (m_dirty[m_frame])
    179190        {
     191            double const maxsqlen = 1024;
     192            double const k1 = 1.0 / (1 << 10) / log2(maxsqlen);
     193
    180194            m_dirty[m_frame]--;
    181195
     
    183197            for (int i = m_frame % 2; i < m_size.x; i += 2)
    184198            {
    185                 double const maxsqlen = 1024;
    186199
    187200                f64cmplx z0 = m_center + TexelToWorldOffset(ivec2(i, j));
     
    207220                    union { double n; uint64_t x; } u = { n };
    208221                    double k = (u.x >> 42) - (((1 << 10) - 1) << 10);
    209                     k *= 1.0 / (1 << 10) / log2(maxsqlen);
     222                    k *= k1;
    210223
    211224                    /* Approximate log2(k) in [1,2]. */
     
    254267            glGenTextures(1, &m_texid);
    255268            glBindTexture(GL_TEXTURE_2D, m_texid);
    256             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.x / 2, m_size.y * 2,
    257                          0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, m_pixels);
     269            glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT,
     270                         m_size.x / 2, m_size.y * 2, 0,
     271                         TEXTURE_FORMAT, TEXTURE_TYPE, m_pixels);
     272#if !defined __CELLOS_LV2__
     273            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ALLOCATION_HINT_SCE,
     274                            GL_TEXTURE_TILED_GPU_SCE);
     275#endif
    258276            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    259277            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     
    412430            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_frame * m_size.y / 2,
    413431                            m_size.x / 2, m_size.y / 2,
    414                             GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
     432                            TEXTURE_FORMAT, TEXTURE_TYPE,
    415433                            m_pixels + m_size.x * m_size.y / 4 * m_frame);
    416434        }
     
    423441            glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i * m_size.y / 2,
    424442                            m_size.x / 2, m_size.y / 2,
    425                             GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
     443                            TEXTURE_FORMAT, TEXTURE_TYPE,
    426444                            m_pixels + m_size.x * m_size.y / 4 * m_frame);
    427445    }
Note: See TracChangeset for help on using the changeset viewer.