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 "vtkObject.h" 00056 00057 class vtkActor; 00058 class vtkCollection; 00059 class vtkCollectionIterator; 00060 class vtkRenderer; 00061 class vtkRenderWindow; 00062 class vtkShader; 00063 class vtkWindow; 00064 class vtkXMLMaterial; 00065 class vtkShaderDeviceAdapter; 00066 00067 // manages all shaders defined in the XML file 00068 // especially the part about sending things to the card 00069 class VTK_RENDERING_EXPORT vtkShaderProgram : public vtkObject 00070 { 00071 public: 00072 vtkTypeMacro(vtkShaderProgram, vtkObject); 00073 void PrintSelf(ostream &os, vtkIndent indent); 00074 00075 // .Description: 00076 // Accessors for the Material. 00077 vtkGetObjectMacro( Material, vtkXMLMaterial); 00078 virtual void SetMaterial( vtkXMLMaterial* ); 00079 00080 // .Description: 00081 // Add shaders. Returns the index of the shader. 00082 int AddShader(vtkShader* shader); 00083 00085 void RemoveShader(int index); 00086 00088 void RemoveShader(vtkShader* shader); 00089 00091 vtkCollectionIterator* NewShaderIterator(); 00092 00094 int GetNumberOfShaders(); 00095 00096 // .Description 00097 // This static function creates concrete shaders of a specific type. This is 00098 // used to create a shader of the langauge specified in the XML file. 00099 static vtkShaderProgram* CreateShaderProgram( int type ); 00100 00101 // .Description 00102 // Read the material file to get necessary shader info. Synchronize with 00103 // delegate shaders. 00104 virtual void ReadMaterial(); 00105 00106 // .Description 00107 // Load, compile, install and initialize shaders. These operations may 00108 // be delegated to the shaders themselves or handled in descendants of 00109 // this class. 00110 virtual void Render( vtkActor*, vtkRenderer* )=0; 00111 00113 00117 virtual void AddShaderVariable(const char* name, int numVars, int* x); 00118 virtual void AddShaderVariable(const char* name, int numVars, float* x); 00119 virtual void AddShaderVariable(const char* name, int numVars, double* x); 00121 00123 virtual void PostRender(vtkActor*, vtkRenderer*); 00124 00128 virtual void ReleaseGraphicsResources(vtkWindow *); 00129 00131 00133 vtkGetObjectMacro(ShaderDeviceAdapter, vtkShaderDeviceAdapter); 00135 00136 protected: 00137 vtkShaderProgram(); 00138 ~vtkShaderProgram(); 00139 00140 vtkXMLMaterial* Material; 00141 vtkCollection* ShaderCollection; 00142 vtkCollectionIterator* ShaderCollectionIterator; 00143 00144 vtkSetMacro(GLExtensionsLoaded, int); 00145 vtkGetMacro(GLExtensionsLoaded, int); 00146 int GLExtensionsLoaded; 00147 virtual void LoadExtensions(vtkRenderWindow*) {} 00148 00149 // Subclasses must set the shader device apater of the right type. 00150 void SetShaderDeviceAdapter(vtkShaderDeviceAdapter*); 00151 00153 00155 virtual vtkShader* NewShader() =0; 00156 private: 00157 vtkShaderProgram(const vtkShaderProgram&); // Not Implemented 00158 void operator=(const vtkShaderProgram&); // Not Implemented 00160 00161 vtkShaderDeviceAdapter* ShaderDeviceAdapter; 00162 }; 00163 #endif //__vtkShaderProgram_h