blob: 79773e394e841f8ab915ffdbfbcf0a6b9e16edd4 [file] [log] [blame]
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00001//
2// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
daniel@transgaming.com31b13e12012-11-28 19:34:30 +00007// Image.cpp: Implements the rx::Image class, which acts as the interface to
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00008// the actual underlying surfaces of a Texture.
9
10#include "libGLESv2/renderer/Image.h"
11
12#include "libEGL/Display.h"
13
14#include "libGLESv2/main.h"
15#include "libGLESv2/mathutil.h"
16#include "libGLESv2/utilities.h"
17#include "libGLESv2/Texture.h"
daniel@transgaming.com3cef5392012-10-31 19:52:15 +000018#include "libGLESv2/Framebuffer.h"
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000019
daniel@transgaming.comd8e36562012-10-31 19:52:19 +000020#include "libGLESv2/renderer/renderer9_utils.h"
21
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000022namespace rx
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +000023{
daniel@transgaming.com0ad830b2012-10-31 19:52:12 +000024
25namespace
26{
27struct L8
28{
29 unsigned char L;
30
31 static void average(L8 *dst, const L8 *src1, const L8 *src2)
32 {
33 dst->L = ((src1->L ^ src2->L) >> 1) + (src1->L & src2->L);
34 }
35};
36
37struct A8L8
38{
39 unsigned char L;
40 unsigned char A;
41
42 static void average(A8L8 *dst, const A8L8 *src1, const A8L8 *src2)
43 {
44 *(unsigned short*)dst = (((*(unsigned short*)src1 ^ *(unsigned short*)src2) & 0xFEFE) >> 1) + (*(unsigned short*)src1 & *(unsigned short*)src2);
45 }
46};
47
48struct A8R8G8B8
49{
50 unsigned char B;
51 unsigned char G;
52 unsigned char R;
53 unsigned char A;
54
55 static void average(A8R8G8B8 *dst, const A8R8G8B8 *src1, const A8R8G8B8 *src2)
56 {
57 *(unsigned int*)dst = (((*(unsigned int*)src1 ^ *(unsigned int*)src2) & 0xFEFEFEFE) >> 1) + (*(unsigned int*)src1 & *(unsigned int*)src2);
58 }
59};
60
61struct A16B16G16R16F
62{
63 unsigned short R;
64 unsigned short G;
65 unsigned short B;
66 unsigned short A;
67
68 static void average(A16B16G16R16F *dst, const A16B16G16R16F *src1, const A16B16G16R16F *src2)
69 {
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000070 dst->R = gl::float32ToFloat16((gl::float16ToFloat32(src1->R) + gl::float16ToFloat32(src2->R)) * 0.5f);
71 dst->G = gl::float32ToFloat16((gl::float16ToFloat32(src1->G) + gl::float16ToFloat32(src2->G)) * 0.5f);
72 dst->B = gl::float32ToFloat16((gl::float16ToFloat32(src1->B) + gl::float16ToFloat32(src2->B)) * 0.5f);
73 dst->A = gl::float32ToFloat16((gl::float16ToFloat32(src1->A) + gl::float16ToFloat32(src2->A)) * 0.5f);
daniel@transgaming.com0ad830b2012-10-31 19:52:12 +000074 }
75};
76
77struct A32B32G32R32F
78{
79 float R;
80 float G;
81 float B;
82 float A;
83
84 static void average(A32B32G32R32F *dst, const A32B32G32R32F *src1, const A32B32G32R32F *src2)
85 {
86 dst->R = (src1->R + src2->R) * 0.5f;
87 dst->G = (src1->G + src2->G) * 0.5f;
88 dst->B = (src1->B + src2->B) * 0.5f;
89 dst->A = (src1->A + src2->A) * 0.5f;
90 }
91};
92
93template <typename T>
94void GenerateMip(unsigned int sourceWidth, unsigned int sourceHeight,
95 const unsigned char *sourceData, int sourcePitch,
96 unsigned char *destData, int destPitch)
97{
98 unsigned int mipWidth = std::max(1U, sourceWidth >> 1);
99 unsigned int mipHeight = std::max(1U, sourceHeight >> 1);
100
101 if (sourceHeight == 1)
102 {
103 ASSERT(sourceWidth != 1);
104
105 const T *src = (const T*)sourceData;
106 T *dst = (T*)destData;
107
108 for (unsigned int x = 0; x < mipWidth; x++)
109 {
110 T::average(&dst[x], &src[x * 2], &src[x * 2 + 1]);
111 }
112 }
113 else if (sourceWidth == 1)
114 {
115 ASSERT(sourceHeight != 1);
116
117 for (unsigned int y = 0; y < mipHeight; y++)
118 {
119 const T *src0 = (const T*)(sourceData + y * 2 * sourcePitch);
120 const T *src1 = (const T*)(sourceData + y * 2 * sourcePitch + sourcePitch);
121 T *dst = (T*)(destData + y * destPitch);
122
123 T::average(dst, src0, src1);
124 }
125 }
126 else
127 {
128 for (unsigned int y = 0; y < mipHeight; y++)
129 {
130 const T *src0 = (const T*)(sourceData + y * 2 * sourcePitch);
131 const T *src1 = (const T*)(sourceData + y * 2 * sourcePitch + sourcePitch);
132 T *dst = (T*)(destData + y * destPitch);
133
134 for (unsigned int x = 0; x < mipWidth; x++)
135 {
136 T tmp0;
137 T tmp1;
138
139 T::average(&tmp0, &src0[x * 2], &src0[x * 2 + 1]);
140 T::average(&tmp1, &src1[x * 2], &src1[x * 2 + 1]);
141 T::average(&dst[x], &tmp0, &tmp1);
142 }
143 }
144 }
145}
146
147void GenerateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface)
148{
149 D3DSURFACE_DESC destDesc;
150 HRESULT result = destSurface->GetDesc(&destDesc);
151 ASSERT(SUCCEEDED(result));
152
153 D3DSURFACE_DESC sourceDesc;
154 result = sourceSurface->GetDesc(&sourceDesc);
155 ASSERT(SUCCEEDED(result));
156
157 ASSERT(sourceDesc.Format == destDesc.Format);
158 ASSERT(sourceDesc.Width == 1 || sourceDesc.Width / 2 == destDesc.Width);
159 ASSERT(sourceDesc.Height == 1 || sourceDesc.Height / 2 == destDesc.Height);
160
161 D3DLOCKED_RECT sourceLocked = {0};
162 result = sourceSurface->LockRect(&sourceLocked, NULL, D3DLOCK_READONLY);
163 ASSERT(SUCCEEDED(result));
164
165 D3DLOCKED_RECT destLocked = {0};
166 result = destSurface->LockRect(&destLocked, NULL, 0);
167 ASSERT(SUCCEEDED(result));
168
169 const unsigned char *sourceData = reinterpret_cast<const unsigned char*>(sourceLocked.pBits);
170 unsigned char *destData = reinterpret_cast<unsigned char*>(destLocked.pBits);
171
172 if (sourceData && destData)
173 {
174 switch (sourceDesc.Format)
175 {
176 case D3DFMT_L8:
177 GenerateMip<L8>(sourceDesc.Width, sourceDesc.Height, sourceData, sourceLocked.Pitch, destData, destLocked.Pitch);
178 break;
179 case D3DFMT_A8L8:
180 GenerateMip<A8L8>(sourceDesc.Width, sourceDesc.Height, sourceData, sourceLocked.Pitch, destData, destLocked.Pitch);
181 break;
182 case D3DFMT_A8R8G8B8:
183 case D3DFMT_X8R8G8B8:
184 GenerateMip<A8R8G8B8>(sourceDesc.Width, sourceDesc.Height, sourceData, sourceLocked.Pitch, destData, destLocked.Pitch);
185 break;
186 case D3DFMT_A16B16G16R16F:
187 GenerateMip<A16B16G16R16F>(sourceDesc.Width, sourceDesc.Height, sourceData, sourceLocked.Pitch, destData, destLocked.Pitch);
188 break;
189 case D3DFMT_A32B32G32R32F:
190 GenerateMip<A32B32G32R32F>(sourceDesc.Width, sourceDesc.Height, sourceData, sourceLocked.Pitch, destData, destLocked.Pitch);
191 break;
192 default:
193 UNREACHABLE();
194 break;
195 }
196
197 destSurface->UnlockRect();
198 sourceSurface->UnlockRect();
199 }
200}
201}
202
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000203Image::Image()
204{
205 mWidth = 0;
206 mHeight = 0;
207 mInternalFormat = GL_NONE;
208
209 mSurface = NULL;
210
211 mDirty = false;
212
daniel@transgaming.comea32d482012-11-28 19:33:18 +0000213 mRenderer = NULL;
214
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000215 mD3DPool = D3DPOOL_SYSTEMMEM;
216 mD3DFormat = D3DFMT_UNKNOWN;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000217 mActualFormat = GL_NONE;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000218}
219
220Image::~Image()
221{
222 if (mSurface)
223 {
224 mSurface->Release();
225 }
226}
227
daniel@transgaming.com0ad830b2012-10-31 19:52:12 +0000228void Image::GenerateMipmap(Image *dest, Image *source)
229{
230 IDirect3DSurface9 *sourceSurface = source->getSurface();
231 if (sourceSurface == NULL)
232 return error(GL_OUT_OF_MEMORY);
233
234 IDirect3DSurface9 *destSurface = dest->getSurface();
235 GenerateMip(destSurface, sourceSurface);
236
237 source->markDirty();
238}
239
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000240void Image::CopyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source)
241{
242 D3DLOCKED_RECT sourceLock = {0};
243 D3DLOCKED_RECT destLock = {0};
244
245 source->LockRect(&sourceLock, NULL, 0);
246 dest->LockRect(&destLock, NULL, 0);
247
248 if (sourceLock.pBits && destLock.pBits)
249 {
250 D3DSURFACE_DESC desc;
251 source->GetDesc(&desc);
252
253 int rows = dx::IsCompressedFormat(desc.Format) ? desc.Height / 4 : desc.Height;
254 int bytes = dx::ComputeRowSize(desc.Format, desc.Width);
255 ASSERT(bytes <= sourceLock.Pitch && bytes <= destLock.Pitch);
256
257 for(int i = 0; i < rows; i++)
258 {
259 memcpy((char*)destLock.pBits + destLock.Pitch * i, (char*)sourceLock.pBits + sourceLock.Pitch * i, bytes);
260 }
261
262 source->UnlockRect();
263 dest->UnlockRect();
264 }
265 else UNREACHABLE();
266}
267
daniel@transgaming.coma9571682012-11-28 19:33:08 +0000268bool Image::redefine(rx::Renderer9 *renderer, GLint internalformat, GLsizei width, GLsizei height, bool forceRelease)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000269{
270 if (mWidth != width ||
271 mHeight != height ||
272 mInternalFormat != internalformat ||
273 forceRelease)
274 {
275 mWidth = width;
276 mHeight = height;
277 mInternalFormat = internalformat;
278 // compute the d3d format that will be used
daniel@transgaming.coma9571682012-11-28 19:33:08 +0000279 mD3DFormat = renderer->ConvertTextureInternalFormat(internalformat);
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000280 mActualFormat = dx2es::GetEquivalentFormat(mD3DFormat);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000281
daniel@transgaming.comea32d482012-11-28 19:33:18 +0000282 ASSERT(dynamic_cast<rx::Renderer9*>(renderer) != NULL); // D3D9_REPLACE
283 mRenderer = static_cast<rx::Renderer9*>(renderer); // D3D9_REPLACE
284
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000285 if (mSurface)
286 {
287 mSurface->Release();
288 mSurface = NULL;
289 }
290
291 return true;
292 }
293
294 return false;
295}
296
297void Image::createSurface()
298{
299 if(mSurface)
300 {
301 return;
302 }
303
304 IDirect3DTexture9 *newTexture = NULL;
305 IDirect3DSurface9 *newSurface = NULL;
306 const D3DPOOL poolToUse = D3DPOOL_SYSTEMMEM;
307 const D3DFORMAT d3dFormat = getD3DFormat();
308 ASSERT(d3dFormat != D3DFMT_INTZ); // We should never get here for depth textures
309
310 if (mWidth != 0 && mHeight != 0)
311 {
312 int levelToFetch = 0;
313 GLsizei requestWidth = mWidth;
314 GLsizei requestHeight = mHeight;
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000315 gl::MakeValidSize(true, gl::IsCompressed(mInternalFormat), &requestWidth, &requestHeight, &levelToFetch);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000316
daniel@transgaming.comea32d482012-11-28 19:33:18 +0000317 IDirect3DDevice9 *device = mRenderer->getDevice(); // D3D9_REPLACE
318
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000319 HRESULT result = device->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, d3dFormat,
320 poolToUse, &newTexture, NULL);
321
322 if (FAILED(result))
323 {
324 ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
325 ERR("Creating image surface failed.");
326 return error(GL_OUT_OF_MEMORY);
327 }
328
329 newTexture->GetSurfaceLevel(levelToFetch, &newSurface);
330 newTexture->Release();
331 }
332
333 mSurface = newSurface;
334 mDirty = false;
335 mD3DPool = poolToUse;
336}
337
338HRESULT Image::lock(D3DLOCKED_RECT *lockedRect, const RECT *rect)
339{
340 createSurface();
341
342 HRESULT result = D3DERR_INVALIDCALL;
343
344 if (mSurface)
345 {
346 result = mSurface->LockRect(lockedRect, rect, 0);
347 ASSERT(SUCCEEDED(result));
348
349 mDirty = true;
350 }
351
352 return result;
353}
354
355void Image::unlock()
356{
357 if (mSurface)
358 {
359 HRESULT result = mSurface->UnlockRect();
360 ASSERT(SUCCEEDED(result));
361 }
362}
363
364bool Image::isRenderableFormat() const
365{
daniel@transgaming.comdf14c762012-10-31 19:51:48 +0000366 return TextureStorage::IsTextureFormatRenderable(getD3DFormat());
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000367}
368
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000369GLenum Image::getActualFormat() const
370{
371 return mActualFormat;
372}
373
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000374D3DFORMAT Image::getD3DFormat() const
375{
376 // this should only happen if the image hasn't been redefined first
377 // which would be a bug by the caller
378 ASSERT(mD3DFormat != D3DFMT_UNKNOWN);
379
380 return mD3DFormat;
381}
382
383IDirect3DSurface9 *Image::getSurface()
384{
385 createSurface();
386
387 return mSurface;
388}
389
daniel@transgaming.com0f195ad2012-10-31 19:51:59 +0000390void Image::setManagedSurface(TextureStorage2D *storage, int level)
391{
392 setManagedSurface(storage->getSurfaceLevel(level, false));
393}
394
395void Image::setManagedSurface(TextureStorageCubeMap *storage, int face, int level)
396{
397 setManagedSurface(storage->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, false));
398}
399
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000400void Image::setManagedSurface(IDirect3DSurface9 *surface)
401{
402 D3DSURFACE_DESC desc;
403 surface->GetDesc(&desc);
404 ASSERT(desc.Pool == D3DPOOL_MANAGED);
405
406 if ((GLsizei)desc.Width == mWidth && (GLsizei)desc.Height == mHeight)
407 {
408 if (mSurface)
409 {
410 CopyLockableSurfaces(surface, mSurface);
411 mSurface->Release();
412 }
413
414 mSurface = surface;
415 mD3DPool = desc.Pool;
416 }
417}
418
daniel@transgaming.com0f195ad2012-10-31 19:51:59 +0000419bool Image::updateSurface(TextureStorage2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000420{
daniel@transgaming.com0f195ad2012-10-31 19:51:59 +0000421 return updateSurface(storage->getSurfaceLevel(level, true), xoffset, yoffset, width, height);
422}
423
424bool Image::updateSurface(TextureStorageCubeMap *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
425{
426 return updateSurface(storage->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, true), xoffset, yoffset, width, height);
427}
428
429bool Image::updateSurface(IDirect3DSurface9 *destSurface, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
430{
431 if (!destSurface)
432 return false;
433
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000434 IDirect3DSurface9 *sourceSurface = getSurface();
435
436 if (sourceSurface && sourceSurface != destSurface)
437 {
438 RECT rect;
439 rect.left = xoffset;
440 rect.top = yoffset;
441 rect.right = xoffset + width;
442 rect.bottom = yoffset + height;
443
444 POINT point = {rect.left, rect.top};
daniel@transgaming.comea32d482012-11-28 19:33:18 +0000445
446 IDirect3DDevice9 *device = mRenderer->getDevice(); // D3D9_REPLACE
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000447
448 if (mD3DPool == D3DPOOL_MANAGED)
449 {
450 D3DSURFACE_DESC desc;
451 sourceSurface->GetDesc(&desc);
452
453 IDirect3DSurface9 *surf = 0;
454 HRESULT result = device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surf, NULL);
455
456 if (SUCCEEDED(result))
457 {
458 CopyLockableSurfaces(surf, sourceSurface);
459 result = device->UpdateSurface(surf, &rect, destSurface, &point);
460 ASSERT(SUCCEEDED(result));
461 surf->Release();
462 }
463 }
464 else
465 {
466 // UpdateSurface: source must be SYSTEMMEM, dest must be DEFAULT pools
467 HRESULT result = device->UpdateSurface(sourceSurface, &rect, destSurface, &point);
468 ASSERT(SUCCEEDED(result));
469 }
470 }
daniel@transgaming.com0f195ad2012-10-31 19:51:59 +0000471
472 destSurface->Release();
473 return true;
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000474}
475
476// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input
477// into the target pixel rectangle.
478void Image::loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
479 GLint unpackAlignment, const void *input)
480{
481 RECT lockRect =
482 {
483 xoffset, yoffset,
484 xoffset + width, yoffset + height
485 };
486
487 D3DLOCKED_RECT locked;
488 HRESULT result = lock(&locked, &lockRect);
489 if (FAILED(result))
490 {
491 return;
492 }
493
494
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000495 GLsizei inputPitch = gl::ComputePitch(width, mInternalFormat, unpackAlignment);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000496
497 switch (mInternalFormat)
498 {
499 case GL_ALPHA8_EXT:
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000500 if (gl::supportsSSE2())
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000501 {
502 loadAlphaDataSSE2(width, height, inputPitch, input, locked.Pitch, locked.pBits);
503 }
504 else
505 {
506 loadAlphaData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
507 }
508 break;
509 case GL_LUMINANCE8_EXT:
510 loadLuminanceData(width, height, inputPitch, input, locked.Pitch, locked.pBits, getD3DFormat() == D3DFMT_L8);
511 break;
512 case GL_ALPHA32F_EXT:
513 loadAlphaFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
514 break;
515 case GL_LUMINANCE32F_EXT:
516 loadLuminanceFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
517 break;
518 case GL_ALPHA16F_EXT:
519 loadAlphaHalfFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
520 break;
521 case GL_LUMINANCE16F_EXT:
522 loadLuminanceHalfFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
523 break;
524 case GL_LUMINANCE8_ALPHA8_EXT:
525 loadLuminanceAlphaData(width, height, inputPitch, input, locked.Pitch, locked.pBits, getD3DFormat() == D3DFMT_A8L8);
526 break;
527 case GL_LUMINANCE_ALPHA32F_EXT:
528 loadLuminanceAlphaFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
529 break;
530 case GL_LUMINANCE_ALPHA16F_EXT:
531 loadLuminanceAlphaHalfFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
532 break;
533 case GL_RGB8_OES:
534 loadRGBUByteData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
535 break;
536 case GL_RGB565:
537 loadRGB565Data(width, height, inputPitch, input, locked.Pitch, locked.pBits);
538 break;
539 case GL_RGBA8_OES:
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000540 if (gl::supportsSSE2())
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000541 {
542 loadRGBAUByteDataSSE2(width, height, inputPitch, input, locked.Pitch, locked.pBits);
543 }
544 else
545 {
546 loadRGBAUByteData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
547 }
548 break;
549 case GL_RGBA4:
550 loadRGBA4444Data(width, height, inputPitch, input, locked.Pitch, locked.pBits);
551 break;
552 case GL_RGB5_A1:
553 loadRGBA5551Data(width, height, inputPitch, input, locked.Pitch, locked.pBits);
554 break;
555 case GL_BGRA8_EXT:
556 loadBGRAData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
557 break;
558 // float textures are converted to RGBA, not BGRA, as they're stored that way in D3D
559 case GL_RGB32F_EXT:
560 loadRGBFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
561 break;
562 case GL_RGB16F_EXT:
563 loadRGBHalfFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
564 break;
565 case GL_RGBA32F_EXT:
566 loadRGBAFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
567 break;
568 case GL_RGBA16F_EXT:
569 loadRGBAHalfFloatData(width, height, inputPitch, input, locked.Pitch, locked.pBits);
570 break;
571 default: UNREACHABLE();
572 }
573
574 unlock();
575}
576
577void Image::loadAlphaData(GLsizei width, GLsizei height,
578 int inputPitch, const void *input, size_t outputPitch, void *output) const
579{
580 const unsigned char *source = NULL;
581 unsigned char *dest = NULL;
582
583 for (int y = 0; y < height; y++)
584 {
585 source = static_cast<const unsigned char*>(input) + y * inputPitch;
586 dest = static_cast<unsigned char*>(output) + y * outputPitch;
587 for (int x = 0; x < width; x++)
588 {
589 dest[4 * x + 0] = 0;
590 dest[4 * x + 1] = 0;
591 dest[4 * x + 2] = 0;
592 dest[4 * x + 3] = source[x];
593 }
594 }
595}
596
597void Image::loadAlphaFloatData(GLsizei width, GLsizei height,
598 int inputPitch, const void *input, size_t outputPitch, void *output) const
599{
600 const float *source = NULL;
601 float *dest = NULL;
602
603 for (int y = 0; y < height; y++)
604 {
605 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
606 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch);
607 for (int x = 0; x < width; x++)
608 {
609 dest[4 * x + 0] = 0;
610 dest[4 * x + 1] = 0;
611 dest[4 * x + 2] = 0;
612 dest[4 * x + 3] = source[x];
613 }
614 }
615}
616
617void Image::loadAlphaHalfFloatData(GLsizei width, GLsizei height,
618 int inputPitch, const void *input, size_t outputPitch, void *output) const
619{
620 const unsigned short *source = NULL;
621 unsigned short *dest = NULL;
622
623 for (int y = 0; y < height; y++)
624 {
625 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
626 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch);
627 for (int x = 0; x < width; x++)
628 {
629 dest[4 * x + 0] = 0;
630 dest[4 * x + 1] = 0;
631 dest[4 * x + 2] = 0;
632 dest[4 * x + 3] = source[x];
633 }
634 }
635}
636
637void Image::loadLuminanceData(GLsizei width, GLsizei height,
638 int inputPitch, const void *input, size_t outputPitch, void *output, bool native) const
639{
640 const unsigned char *source = NULL;
641 unsigned char *dest = NULL;
642
643 for (int y = 0; y < height; y++)
644 {
645 source = static_cast<const unsigned char*>(input) + y * inputPitch;
646 dest = static_cast<unsigned char*>(output) + y * outputPitch;
647
648 if (!native) // BGRA8 destination format
649 {
650 for (int x = 0; x < width; x++)
651 {
652 dest[4 * x + 0] = source[x];
653 dest[4 * x + 1] = source[x];
654 dest[4 * x + 2] = source[x];
655 dest[4 * x + 3] = 0xFF;
656 }
657 }
658 else // L8 destination format
659 {
660 memcpy(dest, source, width);
661 }
662 }
663}
664
665void Image::loadLuminanceFloatData(GLsizei width, GLsizei height,
666 int inputPitch, const void *input, size_t outputPitch, void *output) const
667{
668 const float *source = NULL;
669 float *dest = NULL;
670
671 for (int y = 0; y < height; y++)
672 {
673 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
674 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch);
675 for (int x = 0; x < width; x++)
676 {
677 dest[4 * x + 0] = source[x];
678 dest[4 * x + 1] = source[x];
679 dest[4 * x + 2] = source[x];
680 dest[4 * x + 3] = 1.0f;
681 }
682 }
683}
684
685void Image::loadLuminanceHalfFloatData(GLsizei width, GLsizei height,
686 int inputPitch, const void *input, size_t outputPitch, void *output) const
687{
688 const unsigned short *source = NULL;
689 unsigned short *dest = NULL;
690
691 for (int y = 0; y < height; y++)
692 {
693 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
694 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch);
695 for (int x = 0; x < width; x++)
696 {
697 dest[4 * x + 0] = source[x];
698 dest[4 * x + 1] = source[x];
699 dest[4 * x + 2] = source[x];
700 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
701 }
702 }
703}
704
705void Image::loadLuminanceAlphaData(GLsizei width, GLsizei height,
706 int inputPitch, const void *input, size_t outputPitch, void *output, bool native) const
707{
708 const unsigned char *source = NULL;
709 unsigned char *dest = NULL;
710
711 for (int y = 0; y < height; y++)
712 {
713 source = static_cast<const unsigned char*>(input) + y * inputPitch;
714 dest = static_cast<unsigned char*>(output) + y * outputPitch;
715
716 if (!native) // BGRA8 destination format
717 {
718 for (int x = 0; x < width; x++)
719 {
720 dest[4 * x + 0] = source[2*x+0];
721 dest[4 * x + 1] = source[2*x+0];
722 dest[4 * x + 2] = source[2*x+0];
723 dest[4 * x + 3] = source[2*x+1];
724 }
725 }
726 else
727 {
728 memcpy(dest, source, width * 2);
729 }
730 }
731}
732
733void Image::loadLuminanceAlphaFloatData(GLsizei width, GLsizei height,
734 int inputPitch, const void *input, size_t outputPitch, void *output) const
735{
736 const float *source = NULL;
737 float *dest = NULL;
738
739 for (int y = 0; y < height; y++)
740 {
741 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
742 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch);
743 for (int x = 0; x < width; x++)
744 {
745 dest[4 * x + 0] = source[2*x+0];
746 dest[4 * x + 1] = source[2*x+0];
747 dest[4 * x + 2] = source[2*x+0];
748 dest[4 * x + 3] = source[2*x+1];
749 }
750 }
751}
752
753void Image::loadLuminanceAlphaHalfFloatData(GLsizei width, GLsizei height,
754 int inputPitch, const void *input, size_t outputPitch, void *output) const
755{
756 const unsigned short *source = NULL;
757 unsigned short *dest = NULL;
758
759 for (int y = 0; y < height; y++)
760 {
761 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
762 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch);
763 for (int x = 0; x < width; x++)
764 {
765 dest[4 * x + 0] = source[2*x+0];
766 dest[4 * x + 1] = source[2*x+0];
767 dest[4 * x + 2] = source[2*x+0];
768 dest[4 * x + 3] = source[2*x+1];
769 }
770 }
771}
772
773void Image::loadRGBUByteData(GLsizei width, GLsizei height,
774 int inputPitch, const void *input, size_t outputPitch, void *output) const
775{
776 const unsigned char *source = NULL;
777 unsigned char *dest = NULL;
778
779 for (int y = 0; y < height; y++)
780 {
781 source = static_cast<const unsigned char*>(input) + y * inputPitch;
782 dest = static_cast<unsigned char*>(output) + y * outputPitch;
783 for (int x = 0; x < width; x++)
784 {
785 dest[4 * x + 0] = source[x * 3 + 2];
786 dest[4 * x + 1] = source[x * 3 + 1];
787 dest[4 * x + 2] = source[x * 3 + 0];
788 dest[4 * x + 3] = 0xFF;
789 }
790 }
791}
792
793void Image::loadRGB565Data(GLsizei width, GLsizei height,
794 int inputPitch, const void *input, size_t outputPitch, void *output) const
795{
796 const unsigned short *source = NULL;
797 unsigned char *dest = NULL;
798
799 for (int y = 0; y < height; y++)
800 {
801 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
802 dest = static_cast<unsigned char*>(output) + y * outputPitch;
803 for (int x = 0; x < width; x++)
804 {
805 unsigned short rgba = source[x];
806 dest[4 * x + 0] = ((rgba & 0x001F) << 3) | ((rgba & 0x001F) >> 2);
807 dest[4 * x + 1] = ((rgba & 0x07E0) >> 3) | ((rgba & 0x07E0) >> 9);
808 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
809 dest[4 * x + 3] = 0xFF;
810 }
811 }
812}
813
814void Image::loadRGBFloatData(GLsizei width, GLsizei height,
815 int inputPitch, const void *input, size_t outputPitch, void *output) const
816{
817 const float *source = NULL;
818 float *dest = NULL;
819
820 for (int y = 0; y < height; y++)
821 {
822 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
823 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch);
824 for (int x = 0; x < width; x++)
825 {
826 dest[4 * x + 0] = source[x * 3 + 0];
827 dest[4 * x + 1] = source[x * 3 + 1];
828 dest[4 * x + 2] = source[x * 3 + 2];
829 dest[4 * x + 3] = 1.0f;
830 }
831 }
832}
833
834void Image::loadRGBHalfFloatData(GLsizei width, GLsizei height,
835 int inputPitch, const void *input, size_t outputPitch, void *output) const
836{
837 const unsigned short *source = NULL;
838 unsigned short *dest = NULL;
839
840 for (int y = 0; y < height; y++)
841 {
842 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
843 dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(output) + y * outputPitch);
844 for (int x = 0; x < width; x++)
845 {
846 dest[4 * x + 0] = source[x * 3 + 0];
847 dest[4 * x + 1] = source[x * 3 + 1];
848 dest[4 * x + 2] = source[x * 3 + 2];
849 dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
850 }
851 }
852}
853
854void Image::loadRGBAUByteData(GLsizei width, GLsizei height,
855 int inputPitch, const void *input, size_t outputPitch, void *output) const
856{
857 const unsigned int *source = NULL;
858 unsigned int *dest = NULL;
859 for (int y = 0; y < height; y++)
860 {
861 source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch);
862 dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch);
863
864 for (int x = 0; x < width; x++)
865 {
866 unsigned int rgba = source[x];
867 dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
868 }
869 }
870}
871
872void Image::loadRGBA4444Data(GLsizei width, GLsizei height,
873 int inputPitch, const void *input, size_t outputPitch, void *output) const
874{
875 const unsigned short *source = NULL;
876 unsigned char *dest = NULL;
877
878 for (int y = 0; y < height; y++)
879 {
880 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
881 dest = static_cast<unsigned char*>(output) + y * outputPitch;
882 for (int x = 0; x < width; x++)
883 {
884 unsigned short rgba = source[x];
885 dest[4 * x + 0] = ((rgba & 0x00F0) << 0) | ((rgba & 0x00F0) >> 4);
886 dest[4 * x + 1] = ((rgba & 0x0F00) >> 4) | ((rgba & 0x0F00) >> 8);
887 dest[4 * x + 2] = ((rgba & 0xF000) >> 8) | ((rgba & 0xF000) >> 12);
888 dest[4 * x + 3] = ((rgba & 0x000F) << 4) | ((rgba & 0x000F) >> 0);
889 }
890 }
891}
892
893void Image::loadRGBA5551Data(GLsizei width, GLsizei height,
894 int inputPitch, const void *input, size_t outputPitch, void *output) const
895{
896 const unsigned short *source = NULL;
897 unsigned char *dest = NULL;
898
899 for (int y = 0; y < height; y++)
900 {
901 source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
902 dest = static_cast<unsigned char*>(output) + y * outputPitch;
903 for (int x = 0; x < width; x++)
904 {
905 unsigned short rgba = source[x];
906 dest[4 * x + 0] = ((rgba & 0x003E) << 2) | ((rgba & 0x003E) >> 3);
907 dest[4 * x + 1] = ((rgba & 0x07C0) >> 3) | ((rgba & 0x07C0) >> 8);
908 dest[4 * x + 2] = ((rgba & 0xF800) >> 8) | ((rgba & 0xF800) >> 13);
909 dest[4 * x + 3] = (rgba & 0x0001) ? 0xFF : 0;
910 }
911 }
912}
913
914void Image::loadRGBAFloatData(GLsizei width, GLsizei height,
915 int inputPitch, const void *input, size_t outputPitch, void *output) const
916{
917 const float *source = NULL;
918 float *dest = NULL;
919
920 for (int y = 0; y < height; y++)
921 {
922 source = reinterpret_cast<const float*>(static_cast<const unsigned char*>(input) + y * inputPitch);
923 dest = reinterpret_cast<float*>(static_cast<unsigned char*>(output) + y * outputPitch);
924 memcpy(dest, source, width * 16);
925 }
926}
927
928void Image::loadRGBAHalfFloatData(GLsizei width, GLsizei height,
929 int inputPitch, const void *input, size_t outputPitch, void *output) const
930{
931 const unsigned char *source = NULL;
932 unsigned char *dest = NULL;
933
934 for (int y = 0; y < height; y++)
935 {
936 source = static_cast<const unsigned char*>(input) + y * inputPitch;
937 dest = static_cast<unsigned char*>(output) + y * outputPitch;
938 memcpy(dest, source, width * 8);
939 }
940}
941
942void Image::loadBGRAData(GLsizei width, GLsizei height,
943 int inputPitch, const void *input, size_t outputPitch, void *output) const
944{
945 const unsigned char *source = NULL;
946 unsigned char *dest = NULL;
947
948 for (int y = 0; y < height; y++)
949 {
950 source = static_cast<const unsigned char*>(input) + y * inputPitch;
951 dest = static_cast<unsigned char*>(output) + y * outputPitch;
952 memcpy(dest, source, width*4);
953 }
954}
955
956void Image::loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
957 const void *input) {
958 ASSERT(xoffset % 4 == 0);
959 ASSERT(yoffset % 4 == 0);
960
961 RECT lockRect = {
962 xoffset, yoffset,
963 xoffset + width, yoffset + height
964 };
965
966 D3DLOCKED_RECT locked;
967 HRESULT result = lock(&locked, &lockRect);
968 if (FAILED(result))
969 {
970 return;
971 }
972
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000973 GLsizei inputSize = gl::ComputeCompressedSize(width, height, mInternalFormat);
974 GLsizei inputPitch = gl::ComputeCompressedPitch(width, mInternalFormat);
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000975 int rows = inputSize / inputPitch;
976 for (int i = 0; i < rows; ++i)
977 {
978 memcpy((void*)((BYTE*)locked.pBits + i * locked.Pitch), (void*)((BYTE*)input + i * inputPitch), inputPitch);
979 }
980
981 unlock();
982}
983
984// This implements glCopyTex[Sub]Image2D for non-renderable internal texture formats and incomplete textures
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000985void Image::copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000986{
daniel@transgaming.com3cef5392012-10-31 19:52:15 +0000987 IDirect3DSurface9 *renderTarget = source->getRenderTarget();
988
989 if (!renderTarget)
990 {
991 ERR("Failed to retrieve the render target.");
992 return error(GL_OUT_OF_MEMORY);
993 }
994
daniel@transgaming.comea32d482012-11-28 19:33:18 +0000995 IDirect3DDevice9 *device = mRenderer->getDevice(); // D3D9_REPLACE
996
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +0000997 IDirect3DSurface9 *renderTargetData = NULL;
998 D3DSURFACE_DESC description;
999 renderTarget->GetDesc(&description);
1000
1001 HRESULT result = device->CreateOffscreenPlainSurface(description.Width, description.Height, description.Format, D3DPOOL_SYSTEMMEM, &renderTargetData, NULL);
1002
1003 if (FAILED(result))
1004 {
1005 ERR("Could not create matching destination surface.");
daniel@transgaming.com3cef5392012-10-31 19:52:15 +00001006 renderTarget->Release();
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00001007 return error(GL_OUT_OF_MEMORY);
1008 }
1009
1010 result = device->GetRenderTargetData(renderTarget, renderTargetData);
1011
1012 if (FAILED(result))
1013 {
1014 ERR("GetRenderTargetData unexpectedly failed.");
1015 renderTargetData->Release();
daniel@transgaming.com3cef5392012-10-31 19:52:15 +00001016 renderTarget->Release();
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00001017 return error(GL_OUT_OF_MEMORY);
1018 }
1019
1020 RECT sourceRect = {x, y, x + width, y + height};
1021 RECT destRect = {xoffset, yoffset, xoffset + width, yoffset + height};
1022
1023 D3DLOCKED_RECT sourceLock = {0};
1024 result = renderTargetData->LockRect(&sourceLock, &sourceRect, 0);
1025
1026 if (FAILED(result))
1027 {
1028 ERR("Failed to lock the source surface (rectangle might be invalid).");
1029 renderTargetData->Release();
daniel@transgaming.com3cef5392012-10-31 19:52:15 +00001030 renderTarget->Release();
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00001031 return error(GL_OUT_OF_MEMORY);
1032 }
1033
1034 D3DLOCKED_RECT destLock = {0};
1035 result = lock(&destLock, &destRect);
1036
1037 if (FAILED(result))
1038 {
1039 ERR("Failed to lock the destination surface (rectangle might be invalid).");
1040 renderTargetData->UnlockRect();
1041 renderTargetData->Release();
daniel@transgaming.com3cef5392012-10-31 19:52:15 +00001042 renderTarget->Release();
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00001043 return error(GL_OUT_OF_MEMORY);
1044 }
1045
1046 if (destLock.pBits && sourceLock.pBits)
1047 {
1048 unsigned char *source = (unsigned char*)sourceLock.pBits;
1049 unsigned char *dest = (unsigned char*)destLock.pBits;
1050
1051 switch (description.Format)
1052 {
1053 case D3DFMT_X8R8G8B8:
1054 case D3DFMT_A8R8G8B8:
1055 switch(getD3DFormat())
1056 {
1057 case D3DFMT_X8R8G8B8:
1058 case D3DFMT_A8R8G8B8:
1059 for(int y = 0; y < height; y++)
1060 {
1061 memcpy(dest, source, 4 * width);
1062
1063 source += sourceLock.Pitch;
1064 dest += destLock.Pitch;
1065 }
1066 break;
1067 case D3DFMT_L8:
1068 for(int y = 0; y < height; y++)
1069 {
1070 for(int x = 0; x < width; x++)
1071 {
1072 dest[x] = source[x * 4 + 2];
1073 }
1074
1075 source += sourceLock.Pitch;
1076 dest += destLock.Pitch;
1077 }
1078 break;
1079 case D3DFMT_A8L8:
1080 for(int y = 0; y < height; y++)
1081 {
1082 for(int x = 0; x < width; x++)
1083 {
1084 dest[x * 2 + 0] = source[x * 4 + 2];
1085 dest[x * 2 + 1] = source[x * 4 + 3];
1086 }
1087
1088 source += sourceLock.Pitch;
1089 dest += destLock.Pitch;
1090 }
1091 break;
1092 default:
1093 UNREACHABLE();
1094 }
1095 break;
1096 case D3DFMT_R5G6B5:
1097 switch(getD3DFormat())
1098 {
1099 case D3DFMT_X8R8G8B8:
1100 for(int y = 0; y < height; y++)
1101 {
1102 for(int x = 0; x < width; x++)
1103 {
1104 unsigned short rgb = ((unsigned short*)source)[x];
1105 unsigned char red = (rgb & 0xF800) >> 8;
1106 unsigned char green = (rgb & 0x07E0) >> 3;
1107 unsigned char blue = (rgb & 0x001F) << 3;
1108 dest[x + 0] = blue | (blue >> 5);
1109 dest[x + 1] = green | (green >> 6);
1110 dest[x + 2] = red | (red >> 5);
1111 dest[x + 3] = 0xFF;
1112 }
1113
1114 source += sourceLock.Pitch;
1115 dest += destLock.Pitch;
1116 }
1117 break;
1118 case D3DFMT_L8:
1119 for(int y = 0; y < height; y++)
1120 {
1121 for(int x = 0; x < width; x++)
1122 {
1123 unsigned char red = source[x * 2 + 1] & 0xF8;
1124 dest[x] = red | (red >> 5);
1125 }
1126
1127 source += sourceLock.Pitch;
1128 dest += destLock.Pitch;
1129 }
1130 break;
1131 default:
1132 UNREACHABLE();
1133 }
1134 break;
1135 case D3DFMT_A1R5G5B5:
1136 switch(getD3DFormat())
1137 {
1138 case D3DFMT_X8R8G8B8:
1139 for(int y = 0; y < height; y++)
1140 {
1141 for(int x = 0; x < width; x++)
1142 {
1143 unsigned short argb = ((unsigned short*)source)[x];
1144 unsigned char red = (argb & 0x7C00) >> 7;
1145 unsigned char green = (argb & 0x03E0) >> 2;
1146 unsigned char blue = (argb & 0x001F) << 3;
1147 dest[x + 0] = blue | (blue >> 5);
1148 dest[x + 1] = green | (green >> 5);
1149 dest[x + 2] = red | (red >> 5);
1150 dest[x + 3] = 0xFF;
1151 }
1152
1153 source += sourceLock.Pitch;
1154 dest += destLock.Pitch;
1155 }
1156 break;
1157 case D3DFMT_A8R8G8B8:
1158 for(int y = 0; y < height; y++)
1159 {
1160 for(int x = 0; x < width; x++)
1161 {
1162 unsigned short argb = ((unsigned short*)source)[x];
1163 unsigned char red = (argb & 0x7C00) >> 7;
1164 unsigned char green = (argb & 0x03E0) >> 2;
1165 unsigned char blue = (argb & 0x001F) << 3;
1166 unsigned char alpha = (signed short)argb >> 15;
1167 dest[x + 0] = blue | (blue >> 5);
1168 dest[x + 1] = green | (green >> 5);
1169 dest[x + 2] = red | (red >> 5);
1170 dest[x + 3] = alpha;
1171 }
1172
1173 source += sourceLock.Pitch;
1174 dest += destLock.Pitch;
1175 }
1176 break;
1177 case D3DFMT_L8:
1178 for(int y = 0; y < height; y++)
1179 {
1180 for(int x = 0; x < width; x++)
1181 {
1182 unsigned char red = source[x * 2 + 1] & 0x7C;
1183 dest[x] = (red << 1) | (red >> 4);
1184 }
1185
1186 source += sourceLock.Pitch;
1187 dest += destLock.Pitch;
1188 }
1189 break;
1190 case D3DFMT_A8L8:
1191 for(int y = 0; y < height; y++)
1192 {
1193 for(int x = 0; x < width; x++)
1194 {
1195 unsigned char red = source[x * 2 + 1] & 0x7C;
1196 dest[x * 2 + 0] = (red << 1) | (red >> 4);
1197 dest[x * 2 + 1] = (signed char)source[x * 2 + 1] >> 7;
1198 }
1199
1200 source += sourceLock.Pitch;
1201 dest += destLock.Pitch;
1202 }
1203 break;
1204 default:
1205 UNREACHABLE();
1206 }
1207 break;
1208 default:
1209 UNREACHABLE();
1210 }
1211 }
1212
1213 unlock();
1214 renderTargetData->UnlockRect();
1215
1216 renderTargetData->Release();
daniel@transgaming.com3cef5392012-10-31 19:52:15 +00001217 renderTarget->Release();
daniel@transgaming.comb9d7e6f2012-10-31 19:08:32 +00001218
1219 mDirty = true;
1220}
1221
1222}