Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Christian Butz
VTK
Commits
4b303225
Commit
4b303225
authored
Dec 21, 2005
by
Kenneth Moreland
Browse files
BUG: Unlike Cg, with GLSL you must attach each texture to a texture unit and
give the texture unit number.
parent
78907430
Changes
8
Hide whitespace changes
Inline
Side-by-side
Rendering/vtkCgShader.cxx
View file @
4b303225
...
...
@@ -151,7 +151,7 @@ public:
};
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro
(
vtkCgShader
,
"1.
4
"
);
vtkCxxRevisionMacro
(
vtkCgShader
,
"1.
5
"
);
vtkStandardNewMacro
(
vtkCgShader
);
//-----------------------------------------------------------------------------
...
...
@@ -445,7 +445,7 @@ void vtkCgShader::SetMatrixParameter(const char* name, const char* state_matrix_
}
//-----------------------------------------------------------------------------
void
vtkCgShader
::
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
)
void
vtkCgShader
::
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
,
int
)
{
CGparameter
param
=
this
->
Internals
->
GetUniformParameter
(
name
);
if
(
!
param
)
...
...
Rendering/vtkCgShader.h
View file @
4b303225
...
...
@@ -148,11 +148,8 @@ protected:
virtual
void
SetMatrixParameter
(
const
char
*
name
,
const
char
*
state_matix_type
,
const
char
*
transform_type
);
// Description:
// Equivalen to cgGLSetTexture(), GLSL merely does a glUniform1v().
// Subclass may have to cast the texture to vtkOpenGLTexture to obtain
// the GLunint for texture this texture.
virtual
void
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
);
virtual
void
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
,
int
=
0
);
private:
vtkCgShader
(
const
vtkCgShader
&
);
// Not Implemented
...
...
Rendering/vtkGLSLShader.cxx
View file @
4b303225
...
...
@@ -163,7 +163,7 @@ static void printAttributeInfo(GLuint program, const char* vtkNotUsed(filename))
//-----------------------------------------------------------------------------
vtkStandardNewMacro
(
vtkGLSLShader
);
vtkCxxRevisionMacro
(
vtkGLSLShader
,
"1.
5
"
);
vtkCxxRevisionMacro
(
vtkGLSLShader
,
"1.
6
"
);
//-----------------------------------------------------------------------------
vtkGLSLShader
::
vtkGLSLShader
()
...
...
@@ -446,18 +446,14 @@ void vtkGLSLShader::SetMatrixParameter(const char*, const char*, const char*)
}
//-----------------------------------------------------------------------------
void
vtkGLSLShader
::
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
)
void
vtkGLSLShader
::
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
,
int
textureIndex
)
{
if
(
!
this
->
IsShader
()
)
{
return
;
}
vtkOpenGLTexture
*
glTexture
=
vtkOpenGLTexture
::
SafeDownCast
(
texture
);
if
(
glTexture
)
{
int
id
=
static_cast
<
int
>
(
glTexture
->
GetIndex
());
this
->
SetUniformParameter
(
name
,
1
,
&
id
);
}
this
->
SetUniformParameter
(
name
,
1
,
&
textureIndex
);
}
//-----------------------------------------------------------------------------
...
...
Rendering/vtkGLSLShader.h
View file @
4b303225
...
...
@@ -139,11 +139,8 @@ protected:
virtual
void
SetMatrixParameter
(
const
char
*
name
,
const
char
*
state_matix_type
,
const
char
*
transform_type
);
// Description:
// Equivalent to cgGLSetTexture(), GLSL merely does a glUniform1v().
// Subclass may have to cast the texture to vtkOpenGLTexture to obtain
// the GLunint for texture this texture.
virtual
void
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
);
virtual
void
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
,
int
textureIndex
);
private:
vtkGLSLShader
(
const
vtkGLSLShader
&
);
// Not Implemented
void
operator
=
(
const
vtkGLSLShader
&
);
// Not Implemented
...
...
Rendering/vtkGLSLShaderProgram.cxx
View file @
4b303225
...
...
@@ -28,7 +28,9 @@
#include
"vtkCollectionIterator.h"
#include
"vtkGLSLShader.h"
#include
"vtkObjectFactory.h"
#include
"vtkProperty.h"
#include
"vtkRenderer.h"
#include
"vtkTexture.h"
#include
"vtkXMLDataElement.h"
#include
<vtkstd/vector>
...
...
@@ -59,7 +61,7 @@ int printOglError(char *vtkNotUsed(file), int vtkNotUsed(line))
#endif
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro
(
vtkGLSLShaderProgram
,
"1.
7
"
);
vtkCxxRevisionMacro
(
vtkGLSLShaderProgram
,
"1.
8
"
);
vtkStandardNewMacro
(
vtkGLSLShaderProgram
);
//-----------------------------------------------------------------------------
...
...
@@ -346,15 +348,49 @@ void vtkGLSLShaderProgram::Render(vtkActor *actor, vtkRenderer *renderer)
shader
->
SetProgram
(
this
->
Program
);
shader
->
PassShaderVariables
(
actor
,
renderer
);
}
// establish any textures the shader might use
vtkProperty
*
property
=
actor
->
GetProperty
();
vtkIdType
numTextures
=
property
->
GetNumberOfTextures
();
GLint
numSupportedTextures
;
glGetIntegerv
(
vtkgl
::
MAX_TEXTURE_UNITS
,
&
numSupportedTextures
);
if
(
numTextures
>=
numSupportedTextures
)
{
vtkErrorMacro
(
"Hardware does not support the number of textures defined."
);
}
for
(
vtkIdType
i
=
0
;
i
<
numTextures
;
i
++
)
{
vtkgl
::
ActiveTexture
(
vtkgl
::
TEXTURE0
+
i
);
property
->
GetTexture
(
i
)
->
Render
(
renderer
);
}
vtkgl
::
ActiveTexture
(
vtkgl
::
TEXTURE0
);
}
//-----------------------------------------------------------------------------
void
vtkGLSLShaderProgram
::
PostRender
(
vtkActor
*
,
vtkRenderer
*
)
void
vtkGLSLShaderProgram
::
PostRender
(
vtkActor
*
actor
,
vtkRenderer
*
)
{
if
(
this
->
IsProgram
())
{
// this unloads the shader program.
vtkgl
::
UseProgram
(
0
);
}
// Disable any textures that may have been enabled.
vtkProperty
*
property
=
actor
->
GetProperty
();
vtkIdType
numTextures
=
property
->
GetNumberOfTextures
();
for
(
vtkIdType
i
=
0
;
i
<
numTextures
;
i
++
)
{
vtkgl
::
ActiveTexture
(
vtkgl
::
TEXTURE0
+
i
);
// Disable any possible texture. Wouldn't having a PostRender on
// vtkTexture be better?
glDisable
(
GL_TEXTURE_1D
);
glDisable
(
GL_TEXTURE_2D
);
glDisable
(
vtkgl
::
TEXTURE_3D
);
glDisable
(
vtkgl
::
TEXTURE_RECTANGLE_ARB
);
glDisable
(
vtkgl
::
TEXTURE_CUBE_MAP
);
}
vtkgl
::
ActiveTexture
(
vtkgl
::
TEXTURE0
);
}
//-----------------------------------------------------------------------------
...
...
Rendering/vtkShader.cxx
View file @
4b303225
...
...
@@ -339,7 +339,7 @@ public:
};
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro
(
vtkShader
,
"1.1
7
"
)
vtkCxxRevisionMacro
(
vtkShader
,
"1.1
8
"
)
vtkCxxSetObjectMacro
(
vtkShader
,
XMLShader
,
vtkXMLShader
);
//-----------------------------------------------------------------------------
vtkShader
::
vtkShader
()
...
...
@@ -1122,7 +1122,7 @@ void vtkShader::SetSamplerParameter(vtkActor* act, vtkRenderer*,
return
;
}
this
->
SetSamplerParameter
(
name
,
texture
);
this
->
SetSamplerParameter
(
name
,
texture
,
texture_id
);
}
//-----------------------------------------------------------------------------
void
vtkShader
::
SetApplicationParameter
(
vtkXMLDataElement
*
elem
)
...
...
Rendering/vtkShader.h
View file @
4b303225
...
...
@@ -200,12 +200,15 @@ protected:
virtual
void
SetMatrixParameter
(
const
char
*
name
,
const
char
*
state_matix_type
,
const
char
*
transform_type
)
=
0
;
// Description:
// Equivalent to cgGLSetTexture(), GLSL merely does a glUniform1v().
// Subclass may have to cast the texture to vtkOpenGLTexture to obtain
// the GLunint for texture this texture.
// Subclasses must override these and perform GLSL or Cg calls.
virtual
void
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
)
=
0
;
// Establishes the given texture as the uniform sampler to perform lookups on.
// The textureIndex argument corresponds to the indices of the textures in a
// vtkProperty. Subclass may have to cast the texture to vtkOpenGLTexture to
// obtain the GLuint for texture this texture. Subclasses must override these
// and perform GLSL or Cg calls.
virtual
void
SetSamplerParameter
(
const
char
*
name
,
vtkTexture
*
texture
,
int
textureIndex
)
=
0
;
vtkTimeStamp
PassShaderVariablesTime
;
private:
...
...
Rendering/vtkShaderProgram.cxx
View file @
4b303225
...
...
@@ -45,7 +45,7 @@
#include
"vtkGLSLShaderProgram.h"
#endif
vtkCxxRevisionMacro
(
vtkShaderProgram
,
"1.
6
"
);
vtkCxxRevisionMacro
(
vtkShaderProgram
,
"1.
7
"
);
vtkCxxSetObjectMacro
(
vtkShaderProgram
,
Material
,
vtkXMLMaterial
);
...
...
@@ -180,9 +180,13 @@ void vtkShaderProgram::LoadExtensions( vtkRenderWindow* renWin )
vtkOpenGLExtensionManager
*
extensions
=
vtkOpenGLExtensionManager
::
New
();
// How can I get access to the vtkRenderWindow from here?
extensions
->
SetRenderWindow
(
renWin
);
if
(
extensions
->
ExtensionSupported
(
"GL_VERSION_2_0"
)
)
// Shouldn't this check be in the subclasses? GLSL requires GL 2.0, but
// Cg does not.
if
(
extensions
->
ExtensionSupported
(
"GL_VERSION_2_0"
)
&&
extensions
->
ExtensionSupported
(
"GL_VERSION_1_3"
)
)
{
extensions
->
LoadExtension
(
"GL_VERSION_2_0"
);
extensions
->
LoadExtension
(
"GL_VERSION_1_3"
);
this
->
SetGLExtensionsLoaded
(
1
);
}
else
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment