FlowVis 1.0
|
00001 00002 #include "LayerRenderable.h" 00003 #include <QGLWidget> 00004 00005 LayerRenderable::LayerRenderable(void) 00006 { 00007 ltype = -1; //nicht ausgewählt 00008 lchannel = -1; //nicht ausgewählt 00009 00010 glGenTextures(1,&transferTexture); //textur für transferfunktion 00011 } 00012 00013 void LayerRenderable::setTransferFunction(const QImage& image) 00014 { 00015 QImage transferImage = QGLWidget::convertToGLFormat(image); 00016 glBindTexture(GL_TEXTURE_1D,transferTexture); 00017 00018 glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 00019 glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 00020 00021 glTexImage1D(GL_TEXTURE_1D,0,4,transferImage.width(),0,GL_RGBA, GL_UNSIGNED_BYTE,transferImage.bits()); 00022 } 00023 00024 void LayerRenderable::draw(GLuint* textures, QVector<Shader*> shaders, GLuint* dispLists, 00025 float aspect, bool glyph, bool texture) 00026 { 00027 if(ltype == -1 || lchannel == -1) 00028 return; 00029 00030 float w = (aspect > 1.f) ? 1.f : aspect; 00031 float h = (aspect > 1.f) ? 1.f/aspect : 1.f; 00032 00033 00034 switch(ltype) 00035 { 00036 case TYPE_TEXTURE: //Texture 00037 shaders[SHADER_TEXTURE]->bind(); 00038 00039 glActiveTexture(GL_TEXTURE0); 00040 glBindTexture(GL_TEXTURE_2D,textures[lchannel]); 00041 00042 glActiveTexture(GL_TEXTURE3); 00043 glBindTexture(GL_TEXTURE_1D,transferTexture); 00044 00045 glActiveTexture(GL_TEXTURE0); 00046 glColor4f(1.f,1.f,1.f,1.f); 00047 glBegin(GL_QUADS); 00048 glTexCoord2f(0.0, 0.0f); glVertex2f(-w, -h); 00049 glTexCoord2f(1.0f, 0.0f); glVertex2f(w, -h); 00050 glTexCoord2f(1.0f, 1.0f); glVertex2f(w, h); 00051 glTexCoord2f(0.0f, 1.0f); glVertex2f(-w, h); 00052 glEnd(); 00053 00054 shaders[SHADER_TEXTURE]->unbind(); 00055 break; 00056 00057 case TYPE_ARROWS: //Arrows 00058 00059 shaders[SHADER_ARROWS]->bind(); 00060 00061 glActiveTexture(GL_TEXTURE0); 00062 glBindTexture(GL_TEXTURE_2D, textures[lchannel]); 00063 00064 glActiveTexture(GL_TEXTURE1); 00065 glBindTexture(GL_TEXTURE_2D, textures[CHANNEL_X]); 00066 00067 glActiveTexture(GL_TEXTURE2); 00068 glBindTexture(GL_TEXTURE_2D, textures[CHANNEL_Y]); 00069 00070 glActiveTexture(GL_TEXTURE3); 00071 glBindTexture(GL_TEXTURE_1D, transferTexture); 00072 00073 glCallList(dispLists[0]); 00074 00075 glActiveTexture(GL_TEXTURE0); 00076 00077 shaders[SHADER_ARROWS]->unbind(); 00078 break; 00079 00080 case TYPE_STREAMLINES: 00081 if (glyph) { 00082 shaders[SHADER_ARROWS]->bind(); 00083 00084 glActiveTexture(GL_TEXTURE0); 00085 glBindTexture(GL_TEXTURE_2D, textures[lchannel]); 00086 00087 glActiveTexture(GL_TEXTURE1); 00088 glBindTexture(GL_TEXTURE_2D, textures[CHANNEL_X]); 00089 00090 glActiveTexture(GL_TEXTURE2); 00091 glBindTexture(GL_TEXTURE_2D, textures[CHANNEL_Y]); 00092 00093 glActiveTexture(GL_TEXTURE3); 00094 glBindTexture(GL_TEXTURE_1D, transferTexture); 00095 00096 glCallList(dispLists[1]); 00097 00098 glActiveTexture(GL_TEXTURE0); 00099 00100 shaders[SHADER_ARROWS]->unbind(); 00101 } else if (texture) { 00102 shaders[SHADER_STREAMLINE_TEXTURE]->bind(); 00103 00104 glActiveTexture(GL_TEXTURE3); 00105 glBindTexture(GL_TEXTURE_1D, transferTexture); 00106 00107 glCallList(dispLists[1]); 00108 00109 glActiveTexture(GL_TEXTURE0); 00110 00111 shaders[SHADER_STREAMLINE_TEXTURE]->unbind(); 00112 } else { 00113 shaders[SHADER_STREAMLINES]->bind(); 00114 00115 glActiveTexture(GL_TEXTURE0); 00116 glBindTexture(GL_TEXTURE_2D, textures[lchannel]); 00117 00118 glActiveTexture(GL_TEXTURE3); 00119 glBindTexture(GL_TEXTURE_1D, transferTexture); 00120 00121 glCallList(dispLists[1]); 00122 00123 glActiveTexture(GL_TEXTURE0); 00124 00125 shaders[SHADER_STREAMLINES]->unbind(); 00126 } 00127 break; 00128 } 00129 } 00130 LayerRenderable::~LayerRenderable(void) 00131 { 00132 glDeleteTextures(1,&transferTexture); //Textur wieder löschen 00133 }