VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkShaderProgram.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 /* 00016 * Copyright 2004 Sandia Corporation. 00017 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00018 * license for use of this work by or on behalf of the 00019 * U.S. Government. Redistribution and use in source and binary forms, with 00020 * or without modification, are permitted provided that this Notice and any 00021 * statement of authorship are reproduced on all copies. 00022 */ 00023 00052 #ifndef __vtkShaderProgram_h 00053 #define __vtkShaderProgram_h 00054 00055 #include "vtkRenderingCoreModule.h" // For export macro 00056 #include "vtkObject.h" 00057 00058 class vtkActor; 00059 class vtkCollection; 00060 class vtkCollectionIterator; 00061 class vtkRenderer; 00062 class vtkRenderWindow; 00063 class vtkShader; 00064 class vtkWindow; 00065 class vtkXMLMaterial; 00066 class vtkShaderDeviceAdapter; 00067 00068 // manages all shaders defined in the XML file 00069 // especially the part about sending things to the card 00070 class VTKRENDERINGCORE_EXPORT vtkShaderProgram : public vtkObject 00071 { 00072 public: 00073 vtkTypeMacro(vtkShaderProgram, vtkObject); 00074 void PrintSelf(ostream &os, vtkIndent indent); 00075 00076 // .Description: 00077 // Accessors for the Material. 00078 vtkGetObjectMacro( Material, vtkXMLMaterial); 00079 virtual void SetMaterial( vtkXMLMaterial* ); 00080 00081 // .Description: 00082 // Add shaders. Returns the index of the shader. 00083 int AddShader(vtkShader* shader); 00084 00086 void RemoveShader(int index); 00087 00089 void RemoveShader(vtkShader* shader); 00090 00092 vtkCollectionIterator* NewShaderIterator(); 00093 00095 int GetNumberOfShaders(); 00096 00097 // .Description 00098 // This static function creates concrete shaders of a specific type. This is 00099 // used to create a shader of the langauge specified in the XML file. 00100 static vtkShaderProgram* CreateShaderProgram( int type ); 00101 00102 // .Description 00103 // Read the material file to get necessary shader info. Synchronize with 00104 // delegate shaders. 00105 virtual void ReadMaterial(); 00106 00107 // .Description 00108 // Load, compile, install and initialize shaders. These operations may 00109 // be delegated to the shaders themselves or handled in descendants of 00110 // this class. 00111 virtual void Render( vtkActor*, vtkRenderer* )=0; 00112 00114 00118 virtual void AddShaderVariable(const char* name, int numVars, int* x); 00119 virtual void AddShaderVariable(const char* name, int numVars, float* x); 00120 virtual void AddShaderVariable(const char* name, int numVars, double* x); 00122 00124 virtual void PostRender(vtkActor*, vtkRenderer*); 00125 00129 virtual void ReleaseGraphicsResources(vtkWindow *); 00130 00132 00134 vtkGetObjectMacro(ShaderDeviceAdapter, vtkShaderDeviceAdapter); 00136 00137 protected: 00138 vtkShaderProgram(); 00139 ~vtkShaderProgram(); 00140 00141 vtkXMLMaterial* Material; 00142 vtkCollection* ShaderCollection; 00143 vtkCollectionIterator* ShaderCollectionIterator; 00144 00145 vtkSetMacro(GLExtensionsLoaded, int); 00146 vtkGetMacro(GLExtensionsLoaded, int); 00147 int GLExtensionsLoaded; 00148 virtual void LoadExtensions(vtkRenderWindow*) {} 00149 00150 // Subclasses must set the shader device apater of the right type. 00151 void SetShaderDeviceAdapter(vtkShaderDeviceAdapter*); 00152 00154 00156 virtual vtkShader* NewShader() =0; 00157 private: 00158 vtkShaderProgram(const vtkShaderProgram&); // Not Implemented 00159 void operator=(const vtkShaderProgram&); // Not Implemented 00161 00162 vtkShaderDeviceAdapter* ShaderDeviceAdapter; 00163 }; 00164 #endif //__vtkShaderProgram_h