Commit 4cf18951 authored by Ken Martin's avatar Ken Martin

fix ios getpixeldata calls

ios has issues with GL_RGB and GL_BACK_LEFT
parent 94d03e0b
......@@ -365,6 +365,9 @@ protected:
int OffScreenInitialized;
int OnScreenInitialized;
// IOS seems to have issues with getting RGB data
virtual int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
private:
vtkIOSRenderWindow(const vtkIOSRenderWindow&) VTK_DELETE_FUNCTION;
void operator=(const vtkIOSRenderWindow&) VTK_DELETE_FUNCTION;
......
......@@ -40,6 +40,12 @@ vtkIOSRenderWindow::vtkIOSRenderWindow()
this->Capabilities = 0;
this->OnScreenInitialized = 0;
this->OffScreenInitialized = 0;
// it seems that LEFT/RIGHT cause issues on IOS so we just use
// generic BACK/FRONT
this->BackLeftBuffer = static_cast<unsigned int>(GL_BACK);
this->BackRightBuffer = static_cast<unsigned int>(GL_BACK);
this->FrontLeftBuffer = static_cast<unsigned int>(GL_FRONT);
this->FrontRightBuffer = static_cast<unsigned int>(GL_FRONT);
}
//----------------------------------------------------------------------------
......@@ -102,6 +108,93 @@ void vtkIOSRenderWindow::DestroyWindow()
this->SetRootWindow(NULL);
}
int vtkIOSRenderWindow::GetPixelData(int x1, int y1,
int x2, int y2,
int front, unsigned char* data)
{
int y_low, y_hi;
int x_low, x_hi;
// set the current window
this->MakeCurrent();
if (y1 < y2)
{
y_low = y1;
y_hi = y2;
}
else
{
y_low = y2;
y_hi = y1;
}
if (x1 < x2)
{
x_low = x1;
x_hi = x2;
}
else
{
x_low = x2;
x_hi = x1;
}
// Must clear previous errors first.
while(glGetError() != GL_NO_ERROR)
{
;
}
if (front)
{
glReadBuffer(static_cast<GLenum>(this->GetFrontLeftBuffer()));
}
else
{
glReadBuffer(static_cast<GLenum>(this->GetBackLeftBuffer()));
}
glDisable( GL_SCISSOR_TEST );
// Calling pack alignment ensures that we can grab the any size window
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
// iOS has issues with getting RGB so we get RGBA
int width = x_hi-x_low + 1;
int height = y_hi-y_low+1;
unsigned char *localData = new unsigned char[width*height*4];
glReadPixels(x_low, y_low, width, height, GL_RGBA,
GL_UNSIGNED_BYTE, localData);
unsigned char *dPtr = data;
unsigned char *lPtr = localData;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
*(dPtr++) = *(lPtr++);
*(dPtr++) = *(lPtr++);
*(dPtr++) = *(lPtr++);
lPtr++;
}
}
delete [] localData;
if (glGetError() != GL_NO_ERROR)
{
return VTK_ERROR;
}
else
{
return VTK_OK;
}
}
//----------------------------------------------------------------------------
void vtkIOSRenderWindow::SetWindowName( const char * _arg )
{
......
......@@ -398,7 +398,7 @@ protected:
std::map<const vtkTextureObject *, int> TextureResourceIds;
int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
virtual int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
int GetRGBAPixelData(int x, int y, int x2, int y2, int front, float* data);
int GetRGBACharPixelData(int x, int y, int x2, int y2, int front,
unsigned char* data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment