我試圖在OpenGL ES中的2048x1024紋理上存儲1365x768圖像,但是一旦繪製出的圖像出現傾斜。如果我通過gluScaleImage()運行相同的1365x768圖像並將其貼裝到2048x1024紋理上,則在繪製時看起來很好,但此OpenGL調用速度較慢並且會損害性能。OpenGL問題繪製造成傾斜的大圖像紋理
我在安裝有256MB內存的Android設備(Motorola Milestone)上執行此操作。不知道是否內存是一個因素,但因爲它使用gluScaleImage()縮放時效果很好(它只是比較慢)。
將較小的紋理(例如854x480)映射到1024x512上時效果不錯。有誰知道這是爲什麼,併爲我能做些什麼的建議嗎?
更新
一些代碼片斷來幫助理解上下文...
// uiImage is loaded. The texture dimensions are determined from upsizing the image
// dimensions to a power of two size:
// uiImage->_width = 1365
// uiImage->_height = 768
// width = 2048
// height = 1024
// Once the image is loaded:
// INT retval = gluScaleImage(GL_RGBA, uiImage->_width, uiImage->_height, GL_UNSIGNED_BYTE, uiImage->_texels, width, height, GL_UNSIGNED_BYTE, data);
copyImage(GL_RGBA, uiImage->_width, uiImage->_height, GL_UNSIGNED_BYTE, uiImage->_texels, width, height, GL_UNSIGNED_BYTE, data);
if (pixelFormat == RGB565 || pixelFormat == RGBA4444)
{
unsigned char* tempData = NULL;
unsigned int* inPixel32;
unsigned short* outPixel16;
tempData = new unsigned char[height*width*2];
inPixel32 = (unsigned int*)data;
outPixel16 = (unsigned short*)tempData;
if(pixelFormat == RGB565)
{
// "RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" --> "RRRRRGGGGGGBBBBB"
for(unsigned int i = 0; i < numTexels; ++i, ++inPixel32)
{
*outPixel16++ = ((((*inPixel32 >> 0) & 0xFF) >> 3) << 11) |
((((*inPixel32 >> 8) & 0xFF) >> 2) << 5) |
((((*inPixel32 >> 16) & 0xFF) >> 3) << 0);
}
}
if(tempData != NULL)
{
delete [] data;
data = tempData;
}
}
// [snip..]
// Copy function (mostly)
static void copyImage(GLint widthin, GLint heightin, const unsigned int* datain, GLint widthout, GLint heightout, unsigned int* dataout)
{
unsigned int* p1 = const_cast<unsigned int*>(datain);
unsigned int* p2 = dataout;
int nui = widthin * sizeof(unsigned int);
for(int i = 0; i < heightin; i++)
{
memcpy(p2, p1, nui);
p1 += widthin;
p2 += widthout;
}
}
在渲染代碼,在不改變我的紋理使用gluScaleImage座標時,我看到正確的圖像()和copyImage()代碼的較小圖像(需要稍後的校正因子)。這是圖像很小時發生的情況(例如,854x480與copyImage()可以正常工作),但是當我使用1365x768圖像時,即出現偏斜時。
你應該發佈你的代碼,我只知道你真的在做什麼! – 2011-04-07 19:39:12
我發佈了一些關鍵代碼片段。 – 2011-04-07 20:50:15
這個「歪斜」看起來與此相似嗎? http://stackoverflow.com/q/25921458/2732991 – 2014-09-20 12:31:45