Commit 5174a15f authored by Ken Martin's avatar Ken Martin
Browse files

modified the cell normal code to not require float textures

Cell normals should work now on systems that lack floating
point texture support. Previously normal values less than zero
would be clamped to zero.
parent fc5780e3
Pipeline #23990 passed with stage
......@@ -1148,12 +1148,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
{
......@@ -2796,7 +2811,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);
}
}
}
......@@ -2844,12 +2859,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