Commit bcb647d9 authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot
Browse files

Merge topic 'cell_normals_non_float'

5174a15f

 modified the cell normal code to not require float textures
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Utkarsh Ayachit's avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !1868
parents 8cf19f54 5174a15f
Pipeline #24156 canceled with stage
......@@ -1225,12 +1225,27 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
"//VTK::Normal::Dec",
"uniform mat3 normalMatrix;\n"
"uniform samplerBuffer textureN;\n");
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"vec3 normalVCVSOutput = normalize(normalMatrix *\n"
" texelFetchBuffer(textureN, gl_PrimitiveID + PrimitiveIDOffset).xyz);\n"
" if (gl_FrontFacing == false) { normalVCVSOutput = -normalVCVSOutput; }\n"
);
if (this->CellNormalTexture->GetVTKDataType() == VTK_FLOAT)
{
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"vec3 normalVCVSOutput = \n"
" texelFetchBuffer(textureN, gl_PrimitiveID + PrimitiveIDOffset).xyz;\n"
"normalVCVSOutput = normalize(normalMatrix * normalVCVSOutput);\n"
" if (gl_FrontFacing == false) { normalVCVSOutput = -normalVCVSOutput; }\n"
);
}
else
{
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"vec3 normalVCVSOutput = \n"
" texelFetchBuffer(textureN, gl_PrimitiveID + PrimitiveIDOffset).xyz;\n"
"normalVCVSOutput = normalVCVSOutput * 255.0/127.0 - 1.0;\n"
"normalVCVSOutput = normalize(normalMatrix * normalVCVSOutput);\n"
" if (gl_FrontFacing == false) { normalVCVSOutput = -normalVCVSOutput; }\n"
);
}
}
else
{
......@@ -2872,7 +2887,7 @@ void vtkOpenGLPolyDataMapper::AppendCellTextures(
newNorms.push_back(norms[0]);
newNorms.push_back(norms[1]);
newNorms.push_back(norms[2]);
newNorms.push_back(1.0);
newNorms.push_back(0);
}
}
}
......@@ -2920,12 +2935,37 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
}
this->CellNormalTexture->SetContext(
static_cast<vtkOpenGLRenderWindow*>(ren->GetVTKWindow()));
this->CellNormalBuffer->Upload(newNorms,
vtkOpenGLBufferObject::TextureBuffer);
this->CellNormalTexture->CreateTextureBuffer(
static_cast<unsigned int>(newNorms.size()/4),
4, VTK_FLOAT,
this->CellNormalBuffer);
// do we have float texture support ?
int ftex =
static_cast<vtkOpenGLRenderWindow *>(ren->GetRenderWindow())->
GetDefaultTextureInternalFormat(VTK_FLOAT, 4, false, true);
if (ftex)
{
this->CellNormalBuffer->Upload(newNorms,
vtkOpenGLBufferObject::TextureBuffer);
this->CellNormalTexture->CreateTextureBuffer(
static_cast<unsigned int>(newNorms.size()/4),
4, VTK_FLOAT,
this->CellNormalBuffer);
}
else
{
// have to convert to unsigned char if no float support
std::vector<unsigned char> ucNewNorms;
ucNewNorms.resize(newNorms.size());
for (size_t i = 0; i < newNorms.size(); i++)
{
ucNewNorms[i] = 127.0*(newNorms[i] + 1.0);
}
this->CellNormalBuffer->Upload(ucNewNorms,
vtkOpenGLBufferObject::TextureBuffer);
this->CellNormalTexture->CreateTextureBuffer(
static_cast<unsigned int>(newNorms.size()/4),
4, VTK_UNSIGNED_CHAR,
this->CellNormalBuffer);
}
}
}
......
......@@ -549,6 +549,24 @@ void vtkOpenGLRenderWindow::InitializeTextureInternalFormats()
#endif
}
// on mesa we may not have float textures even though we think we do
// this is due to Mesa being iompacted by a patent issue with SGI
if (haveFloatTextures)
{
const char *glVersion =
reinterpret_cast<const char *>(glGetString(GL_VERSION));
if (glVersion && strstr(glVersion,"Mesa") != NULL &&
!GLEW_ARB_texture_float)
{
haveFloatTextures = false;
// mesa without float support cannot even use
// uchar textures with underlying float data
// so pretty much anything with float data
// is out of luck so return
return;
}
}
if (haveFloatTextures)
{
#ifdef GL_R32F
......
......@@ -520,7 +520,10 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
int tempPixelFormat = ChoosePixelFormat(tempDC, &tempPfd);
SetPixelFormat(tempDC, tempPixelFormat, &tempPfd);
HGLRC tempContext = wglCreateContext(tempDC);
wglMakeCurrent(tempDC, tempContext);
if (!wglMakeCurrent(tempDC, tempContext))
{
vtkErrorMacro("failed to create temporary windows OpenGL context with errror: " << GetLastError());
}
// make sure glew is initialized with fake window
this->OpenGLInit();
......
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