Commit 84ab1f85 authored by Ken Martin's avatar Ken Martin

More changes needed to get iceT working and cleanup

Change-Id: I620c5c4edea9aafbc74eec830ec798b4069e00f7
parent 5116308e
......@@ -725,6 +725,50 @@ void vtkOpenGLRenderWindow::RenderQuad(
}
}
// draw (and stretch as needed) the data to the current viewport
void vtkOpenGLRenderWindow::DrawPixels(
int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
{
glDisable( GL_SCISSOR_TEST );
if (!this->DrawPixelsTextureObject)
{
this->DrawPixelsTextureObject = vtkTextureObject::New();
}
this->DrawPixelsTextureObject->SetContext(this);
this->DrawPixelsTextureObject->Create2DFromRaw(srcWidth, srcHeight,
numComponents, dataType, data);
this->DrawPixelsTextureObject->CopyToFrameBuffer(NULL, NULL);
// This seems to be necessary for the image to show up
glFlush();
}
// very generic call to draw pixel data to a region of the window
void vtkOpenGLRenderWindow::DrawPixels(
int dstXmin, int dstYmin, int dstXmax, int dstYmax,
int srcXmin, int srcYmin, int srcXmax, int srcYmax,
int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
{
glDisable( GL_SCISSOR_TEST );
if (!this->DrawPixelsTextureObject)
{
this->DrawPixelsTextureObject = vtkTextureObject::New();
}
this->DrawPixelsTextureObject->SetContext(this);
this->DrawPixelsTextureObject->Create2DFromRaw(srcWidth, srcHeight,
numComponents, dataType, data);
this->DrawPixelsTextureObject->CopyToFrameBuffer(
srcXmin, srcYmin, srcXmax, srcYmax-1,
dstXmin, dstYmin, dstXmax, dstYmax,
this->GetSize()[0], this->GetSize()[1],
NULL, NULL);
// This seems to be necessary for the image to show up
glFlush();
}
// less generic verison, old API
void vtkOpenGLRenderWindow::DrawPixels(int x1, int y1, int x2, int y2, int numComponents, int dataType, void *data)
{
int y_low, y_hi;
......@@ -755,22 +799,9 @@ void vtkOpenGLRenderWindow::DrawPixels(int x1, int y1, int x2, int y2, int numCo
int width = x_hi-x_low+1;
int height = y_hi-y_low+1;
glDisable( GL_SCISSOR_TEST );
if (!this->DrawPixelsTextureObject)
{
this->DrawPixelsTextureObject = vtkTextureObject::New();
}
this->DrawPixelsTextureObject->SetContext(this);
this->DrawPixelsTextureObject->Create2DFromRaw(width, height,
numComponents, dataType, data);
this->DrawPixelsTextureObject->CopyToFrameBuffer(
0, 0, width-1, height-1,
x_low, y_low,
this->GetSize()[0], this->GetSize()[1],
NULL, NULL);
// This seems to be necessary for the image to show up
glFlush();
// call the more generic version
this->DrawPixels(x_low, y_low, x_hi, y_hi,
0, 0, width-1, height-1, width, height, numComponents, dataType, data);
}
int vtkOpenGLRenderWindow::SetPixelData(int x1, int y1, int x2, int y2,
......
......@@ -219,7 +219,22 @@ public:
// Description:
// Replacement for the old glDrawPixels function
virtual void DrawPixels(int x1, int y1, int x2, int y2, int numComponents, int dataType, void *data);
virtual void DrawPixels(int x1, int y1, int x2, int y2,
int numComponents, int dataType, void *data);
// Description:
// Replacement for the old glDrawPixels function, but it allows
// for scaling the data and using only part of the texture
virtual void DrawPixels(
int dstXmin, int dstYmin, int dstXmax, int dstYmax,
int srcXmin, int srcYmin, int srcXmax, int srcYmax,
int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
// Description:
// Replacement for the old glDrawPixels function. This simple version draws all
// the data to the entire current viewport scaling as needed.
virtual void DrawPixels(
int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
protected:
vtkOpenGLRenderWindow();
......
......@@ -1683,11 +1683,58 @@ bool vtkTextureObject::Create3D(unsigned int width, unsigned int height,
#endif
}
// ----------------------------------------------------------------------------
void vtkTextureObject::CopyToFrameBuffer(
vtkShaderProgram *program, vtkgl::VertexArrayObject *vao)
{
float minXTexCoord=static_cast<float>(
static_cast<double>(0.5)/this->Width);
float minYTexCoord=static_cast<float>(
static_cast<double>(0.5)/this->Height);
float maxXTexCoord=static_cast<float>(
static_cast<double>(this->Width-0.5)/this->Width);
float maxYTexCoord=static_cast<float>(
static_cast<double>(this->Height-0.5)/this->Height);
float tcoords[] = {
minXTexCoord, minYTexCoord,
maxXTexCoord, minYTexCoord,
maxXTexCoord, maxYTexCoord,
minXTexCoord, maxYTexCoord};
float verts[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f};
this->CopyToFrameBuffer(tcoords, verts, program, vao);
}
// ----------------------------------------------------------------------------
void vtkTextureObject::CopyToFrameBuffer(
int srcXmin, int srcYmin,
int srcXmax, int srcYmax,
int dstXmin, int dstYmin,
int dstSizeX, int dstSizeY,
vtkShaderProgram *program, vtkgl::VertexArrayObject *vao)
{
float dstXmax = static_cast<float>(dstXmin+srcXmax-srcXmin);
float dstYmax = static_cast<float>(dstYmin+srcYmax-srcYmin);
this->CopyToFrameBuffer(srcXmin, srcYmin, srcXmax, srcYmax,
dstXmin, dstYmin, dstXmax, dstYmax, dstSizeX, dstSizeY,
program, vao);
}
// ----------------------------------------------------------------------------
void vtkTextureObject::CopyToFrameBuffer(
int srcXmin, int srcYmin,
int srcXmax, int srcYmax,
int dstXmin, int dstYmin,
int dstXmax, int dstYmax,
int dstSizeX, int dstSizeY,
vtkShaderProgram *program, vtkgl::VertexArrayObject *vao)
{
......@@ -1702,8 +1749,6 @@ void vtkTextureObject::CopyToFrameBuffer(
assert("pre: positive_dstXmin" && dstXmin>=0);
assert("pre: positive_dstYmin" && dstYmin>=0);
vtkOpenGLClearErrorMacro();
float minXTexCoord=static_cast<float>(
static_cast<double>(srcXmin+0.5)/this->Width);
float minYTexCoord=static_cast<float>(
......@@ -1714,9 +1759,7 @@ void vtkTextureObject::CopyToFrameBuffer(
float maxYTexCoord=static_cast<float>(
static_cast<double>(srcYmax+0.5)/this->Height);
float dstXmax = static_cast<float>(dstXmin+srcXmax-srcXmin);
float dstYmax = static_cast<float>(dstYmin+srcYmax-srcYmin);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,dstSizeX,dstSizeY);
float tcoords[] = {
......@@ -1731,6 +1774,15 @@ void vtkTextureObject::CopyToFrameBuffer(
2.0f*(dstXmax+1.0f)/dstSizeX-1.0f, 2.0f*(dstYmax+1.0f)/dstSizeY-1.0f, 0.0f,
2.0f*dstXmin/dstSizeX-1.0f, 2.0f*(dstYmax+1.0f)/dstSizeY-1.0f, 0.0f};
this->CopyToFrameBuffer(tcoords, verts, program, vao);
glPopAttrib();
}
void vtkTextureObject::CopyToFrameBuffer(float *tcoords, float *verts,
vtkShaderProgram *program, vtkgl::VertexArrayObject *vao)
{
vtkOpenGLClearErrorMacro();
// if no program or VAO was provided, then use
// a simple pass through program and bind this
// texture to it
......
......@@ -459,24 +459,33 @@ public:
{ return vtkTextureObject::IsSupported(renWin, false, false, false); }
// Description:
// Copy a sub-part of the texture (src) in the current framebuffer
// at location (dstXmin,dstYmin). (dstXmin,dstYmin) is the location of the
// lower left corner of the rectangle.
// \pre positive_srcXmin: srcXmin>=0
// \pre max_srcXmax: srcXmax<this->GetWidth()
// \pre increasing_x: srcXmin<=srcXmax
// \pre positive_srcYmin: srcYmin>=0
// \pre max_srcYmax: srcYmax<this->GetHeight()
// \pre increasing_y: srcYmin<=srcYmax
// \pre positive_dstXmin: dstXmin>=0
// \pre positive_dstYmin: dstYmin>=0
// Copy the texture (src) in the current framebuffer. A variety of
// signatures based on what you want to do
// Copy the entire texture to the entire current viewport
void CopyToFrameBuffer(vtkShaderProgram *program,
vtkgl::VertexArrayObject *vao);
// part of a texture to part of a viewport, scaling as needed
void CopyToFrameBuffer(int srcXmin, int srcYmin,
int srcXmax, int srcYmax,
int dstXmin, int dstYmin,
int dstXmax, int dstYmax,
int dstSizeX, int dstSizeY,
vtkShaderProgram *program,
vtkgl::VertexArrayObject *vao
);
// copy part of a texure to part of a viewport, no scalaing
void CopyToFrameBuffer(int srcXmin, int srcYmin,
int srcXmax, int srcYmax,
int dstXmin, int dstYmin,
int dstSizeX, int dstSizeY,
vtkShaderProgram *program,
vtkgl::VertexArrayObject *vao
);
// copy a texture to a quad using the provided tcoords and verts
void CopyToFrameBuffer(float *tcoords, float *verts,
vtkShaderProgram *program,
vtkgl::VertexArrayObject *vao
);
// Description:
......
......@@ -654,7 +654,6 @@ bool vtkSynchronizedRenderers::vtkRawImage::PushToViewport(vtkRenderer* ren)
return false;
}
this->Renderer = ren;
double viewport[4];
ren->GetViewport(viewport);
const int* window_size = ren->GetVTKWindow()->GetActualSize();
......@@ -671,11 +670,11 @@ bool vtkSynchronizedRenderers::vtkRawImage::PushToViewport(vtkRenderer* ren)
static_cast<GLsizei>((viewport[2]-viewport[0])*window_size[0]),
static_cast<GLsizei>((viewport[3]-viewport[1])*window_size[1]));
ren->Clear();
return this->PushToFrameBuffer();
return this->PushToFrameBuffer(ren);
}
//----------------------------------------------------------------------------
bool vtkSynchronizedRenderers::vtkRawImage::PushToFrameBuffer()
bool vtkSynchronizedRenderers::vtkRawImage::PushToFrameBuffer(vtkRenderer *ren)
{
if (!this->IsValid())
{
......@@ -686,15 +685,9 @@ bool vtkSynchronizedRenderers::vtkRawImage::PushToFrameBuffer()
vtkOpenGLClearErrorMacro();
#ifdef VTKGL2
double viewport[4];
this->Renderer->GetViewport(viewport);
const int* window_size = this->Renderer->GetVTKWindow()->GetActualSize();
vtkOpenGLRenderWindow *renWin = vtkOpenGLRenderWindow::SafeDownCast(this->Renderer->GetVTKWindow());
// always draw the entire image on the entire viewport
renWin->DrawPixels(viewport[0]*window_size[0], viewport[1]*window_size[1],
viewport[2]*window_size[0]-1, viewport[3]*window_size[1]-1,
vtkOpenGLRenderWindow *renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetVTKWindow());
renWin->DrawPixels(this->GetWidth(), this->GetHeight(),
this->Data->GetNumberOfComponents(), VTK_UNSIGNED_CHAR,
this->GetRawPtr()->GetVoidPointer(0));
#else
......
......@@ -126,7 +126,6 @@ public:
this->Valid = false;
this->Size[0] = this->Size[1] = 0;
this->Data = vtkSmartPointer<vtkUnsignedCharArray>::New();
this->Renderer = 0;
}
void Resize(int dx, int dy, int numcomps)
......@@ -153,7 +152,8 @@ public:
// This is a raw version of PushToViewport() that assumes that the
// glViewport() has already been setup externally.
bool PushToFrameBuffer();
// the argument is optional for backwards compat with old OpenGL
bool PushToFrameBuffer(vtkRenderer *ren = NULL);
// Captures the image from the viewport.
// This doesn't trigger a render, just captures what's currently there in
......@@ -167,7 +167,6 @@ public:
bool Valid;
int Size[2];
vtkSmartPointer<vtkUnsignedCharArray> Data;
vtkRenderer *Renderer;
void Allocate(int dx, int dy, int numcomps);
};
......
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