- Timestamp:
- Feb 1, 2013, 3:49:03 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gpu/texture.cpp
r2216 r2312 54 54 GLenum m_gl_format, m_gl_type; 55 55 #endif 56 int m_bytes_per_elem; 56 57 }; 57 58 … … 72 73 73 74 #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[] = 75 81 { 76 82 /* Unknown */ 77 D3DFMT_UNKNOWN,83 { D3DFMT_UNKNOWN, 0 }, 78 84 79 85 /* R8G8B8 */ 80 86 # if defined USE_D3D9 81 D3DFMT_R8G8B8,82 # else 83 D3DFMT_UNKNOWN,87 { D3DFMT_R8G8B8, 3 }, 88 # else 89 { D3DFMT_UNKNOWN, 0 }, 84 90 # endif 85 91 86 92 /* A8R8G8B8 */ 87 93 # if defined USE_D3D9 88 D3DFMT_A8R8G8B8,94 { D3DFMT_A8R8G8B8, 4 }, 89 95 # else 90 96 /* 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 }, 92 106 # endif 93 107 }; 94 108 95 D3DFORMAT d3d_format = GET_CLAMPED(d3d_formats, format) ;109 D3DFORMAT d3d_format = GET_CLAMPED(d3d_formats, format).format; 96 110 # if defined USE_D3D9 97 111 int d3d_usage = D3DUSAGE_DYNAMIC; … … 103 117 d3d_usage, d3d_format, 104 118 D3DPOOL_DEFAULT, &m_data->m_texture, NULL); 119 m_data->m_bytes_per_elem = GET_CLAMPED(d3d_formats, format).bytes; 105 120 #else 106 121 static struct … … 108 123 GLint internal_format; 109 124 GLenum format, type; 125 int bytes; 110 126 } 111 127 const gl_formats[] = 112 128 { 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 120 132 #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 }, 122 136 #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 }, 133 138 /* FIXME: if GL_RGBA is not available, we should advertise 134 139 * 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 }, 136 142 #else 137 143 /* 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 */ 139 147 #endif 140 148 }; … … 143 151 m_data->m_gl_format = GET_CLAMPED(gl_formats, format).format; 144 152 m_data->m_gl_type = GET_CLAMPED(gl_formats, format).type; 153 m_data->m_bytes_per_elem = GET_CLAMPED(gl_formats, format).bytes; 145 154 146 155 glGenTextures(1, &m_data->m_texture); … … 208 217 m_data->m_texture->LockRect(0, &rect, NULL, 0); 209 218 219 int stride = size.x * m_data->m_bytes_per_elem; 210 220 for (int j = 0; j < size.y; j++) 211 221 { 212 222 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); 216 225 } 217 226 -
trunk/src/gpu/texture.h
r2216 r2312 26 26 { 27 27 Unknown = 0, 28 R8G8B8, 29 A8R8G8B8, 30 A8B8G8R8, 28 RGB_8, 29 ARGB_8, 30 ABGR_8, 31 Y_8, 31 32 } 32 33 m_value; -
trunk/src/tileset.cpp
r2216 r2312 124 124 { 125 125 case Image::FORMAT_RGB: 126 format = PixelFormat::R 8G8B8;126 format = PixelFormat::RGB_8; 127 127 planes = 3; 128 128 break; 129 129 case Image::FORMAT_RGBA: 130 130 default: 131 format = PixelFormat::A 8R8G8B8;131 format = PixelFormat::ARGB_8; 132 132 planes = 4; 133 133 break; -
trunk/tutorial/04_texture.cpp
r2277 r2312 37 37 m_vertices << vec2( 1.0, 1.0); 38 38 39 m_heightmap = new uint8_t[ 4 *TEXTURE_WIDTH * 1];39 m_heightmap = new uint8_t[TEXTURE_WIDTH * 1]; 40 40 } 41 41 … … 51 51 /* Generate a new heightmap at the beginning */ 52 52 if (m_frames == 0) 53 memset(m_heightmap, 255, 4 *TEXTURE_WIDTH);53 memset(m_heightmap, 255, TEXTURE_WIDTH); 54 54 55 55 /* Scroll left */ 56 56 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]; 58 58 59 int height = m_heightmap[ 4 * (TEXTURE_WIDTH - 1)];59 int height = m_heightmap[TEXTURE_WIDTH - 1]; 60 60 height = (height + 127 + 40 * lol::sin(m_frames * 0.03) + rand() % 97 - 38) / 2; 61 61 height = std::max(15, std::min(height, 240)); 62 m_heightmap[ 4 * (TEXTURE_WIDTH - 1)] = height;62 m_heightmap[TEXTURE_WIDTH - 1] = height; 63 63 64 64 /* Update frame counter */ … … 73 73 if (!m_ready) 74 74 { 75 m_texture = new Texture(ivec2(TEXTURE_WIDTH, 1), PixelFormat:: A8R8G8B8);75 m_texture = new Texture(ivec2(TEXTURE_WIDTH, 1), PixelFormat::Y_8); 76 76 77 77 m_shader = Shader::Create(LOLFX_RESOURCE_NAME(04_texture)); … … 118 118 System::Init(argc, argv); 119 119 120 Application app("Tutorial 4: Texture", ivec2( 640, 480), 60.0f);120 Application app("Tutorial 4: Texture", ivec2(1280, 720), 60.0f); 121 121 122 122 new TextureDemo(); -
trunk/tutorial/11_fractal.cpp
r2277 r2312 443 443 * so that we can upload four different subimages each frame. */ 444 444 m_texture = new Texture(ivec2(m_size.x / 2, m_size.y * 2), 445 PixelFormat::A 8B8G8R8);445 PixelFormat::ABGR_8); 446 446 447 447 /* Ensure the texture data is complete at least once, otherwise
Note: See TracChangeset
for help on using the changeset viewer.