void AppearanceNode::setGLState(GLRenderState& renderState) const
	{
	if(material.getValue()!=0)
		material.getValue()->setGLState(renderState);
	else
		{
		renderState.disableMaterials();
		renderState.emissiveColor=GLRenderState::Color(0.0f,0.0f,0.0f);
		}
	
	if(texture.getValue()!=0)
		{
		texture.getValue()->setGLState(renderState);
		if(textureTransform.getValue()!=0)
			{
			/* Set the texture transformation: */
			glMatrixMode(GL_TEXTURE);
			glPushMatrix();
			glMultMatrix(textureTransform.getValue()->getTransform());
			glMatrixMode(GL_MODELVIEW);
			}
		}
	else
		renderState.disableTextures();
	}
void VariableManager::endRenderPass(GLRenderState& renderState) const
	{
	/* Restore the OpenGL texture matrix: */
	renderState.setMatrixMode(2);
	glPopMatrix();
	renderState.updateMatrix();
	}
Beispiel #3
0
void TransformNode::glRenderAction(GLRenderState& renderState) const
	{
	/* Push the transformation onto the matrix stack: */
	OGTransform previousTransform=renderState.pushTransform(transform);
	
	/* Call the render actions of all children in order: */
	for(MFGraphNode::ValueList::const_iterator chIt=children.getValues().begin();chIt!=children.getValues().end();++chIt)
		(*chIt)->glRenderAction(renderState);
		
	/* Pop the transformation off the matrix stack: */
	renderState.popTransform(previousTransform);
	}
void VariableManager::beginRenderPass(GLRenderState& renderState) const
	{
	/* Get the context data item: */
	DataItem* dataItem=renderState.getContextData().retrieveDataItem<DataItem>(this);
	
	/* Initialize the scalar variable tracker: */
	dataItem->lastBoundScalarVariableIndex=-1;
	
	/* Save the OpenGL texture matrix: */
	renderState.setMatrixMode(2);
	glPushMatrix();
	dataItem->textureMatrixVersion=renderState.getMatrixVersion();
	}
Beispiel #5
0
void LODSphereNode::glRenderAction(GLRenderState& renderState) const
{
  Scalar current_ratio = Geometry::sqrDist(renderState.getViewerPos(), Point::origin) / radius.getValue();
  renderState.enableCulling(GL_BACK);
  if (detail.getNumValues() == 1) {
    spheres.front()->glRenderAction(renderState.contextData);
  } else {
    std::vector<LODSphereNodeDisplayList*>::const_reverse_iterator sphere = spheres.rbegin();
    MFFloat::ValueList::const_reverse_iterator ratio = lodRatio.getValues().rbegin();
    while (sphere != spheres.rend() && ratio != lodRatio.getValues().rend()) {
      if (current_ratio < *ratio) break;
      ++sphere; ++ratio;
    }
    (*sphere)->glRenderAction(renderState.contextData);
  }
}
Beispiel #6
0
void ConeNode::glRenderAction(GLRenderState& renderState) const
	{
	/* Set up OpenGL state: */
	renderState.enableCulling(GL_BACK);
	
	/* Render the display list: */
	DisplayList::glRenderAction(renderState.contextData);
	}
Beispiel #7
0
void QuadSetNode::glRenderAction(GLRenderState& renderState) const
	{
	/* Bail out if there are less than 4 points: */
	if(coord.getValue()==0||coord.getValue()->point.getNumValues()<4)
		return;
	
	/* Set up OpenGL state: */
	renderState.enableCulling(GL_BACK);
	
	/* Render the quad set: */
	size_t numPoints=coord.getValue()->point.getNumValues();
	glBegin(GL_QUADS);
	std::vector<Vector>::const_iterator qnIt=quadNormals.begin();
	for(size_t q=0;q+4<=numPoints;q+=4,++qnIt)
		{
		/* Get the quad's four corner points in counter-clockwise order: */
		Point ps[4];
		if(ccw.getValue())
			{
			for(size_t i=0;i<4;++i)
				ps[i]=coord.getValue()->point.getValue(q+i);
			}
		else
			{
			for(size_t i=0;i<4;++i)
				ps[i]=coord.getValue()->point.getValue(q+3-i);
			}
		
		if(pointTransform.getValue()!=0)
			{
			/* Transform the quad's corner points: */
			for(int i=0;i<4;++i)
				ps[i]=pointTransform.getValue()->transformPoint(ps[i]);
			}
		
		/* Draw the quad's front: */
		glNormal(*qnIt);
		for(int i=0;i<4;++i)
			{
			glTexCoord(quadTexCoords[i]);
			glVertex(ps[i]);
			}
		
		if(!solid.getValue())
			{
			/* Draw the quad's back: */
			glNormal(-*qnIt);
			for(int i=3;i>=0;--i)
				{
				glTexCoord(quadTexCoords[i]);
				glVertex(ps[i]);
				}
			}
		}
	glEnd();
	}
Beispiel #8
0
void MaterialNode::setGLState(GLRenderState& renderState) const
	{
	/* Enable material rendering: */
	renderState.enableMaterials();
	
	/* Set the material properties: */
	glMaterial(GLMaterialEnums::FRONT_AND_BACK,material);
	renderState.emissiveColor=material.emission;
	glColor(material.diffuse);
	}
Beispiel #9
0
void ShapeNode::glRenderAction(GLRenderState& renderState) const
{
    /* Set the attribute node's OpenGL state: */
    if(appearance.getValue()!=0)
        appearance.getValue()->setGLState(renderState);
    else
    {
        /* Turn off all appearance aspects: */
        renderState.disableMaterials();
        renderState.emissiveColor=GLRenderState::Color(1.0f,1.0f,1.0f);
        renderState.disableTextures();
    }

    /* Render the geometry node: */
    if(geometry.getValue()!=0)
        geometry.getValue()->glRenderAction(renderState);

    /* Reset the attribute node's OpenGL state: */
    if(appearance.getValue()!=0)
        appearance.getValue()->resetGLState(renderState);
}
void VariableManager::bindColorMap(int scalarVariableIndex,GLRenderState& renderState) const
	{
	/* Get the context data item: */
	DataItem* dataItem=renderState.getContextData().retrieveDataItem<DataItem>(this);
	
	/* Set up 1D texture mapping: */
	renderState.setTextureLevel(1);
	
	/* Bind the color texture object: */
	renderState.bindTexture(dataItem->colorMapTextureIds[scalarVariableIndex]);
	
	/* Check if the texture object is outdated: */
	const ScalarVariable& sv=scalarVariables[scalarVariableIndex];
	if(dataItem->colorMapVersions[scalarVariableIndex]!=sv.colorMapVersion)
		{
		/* Set the texture object's parameters: */
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_BASE_LEVEL,0);
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAX_LEVEL,0);
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		
		/* Upload the changed color map into the texture object: */
		glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
		glPixelStorei(GL_UNPACK_ALIGNMENT,1);
		glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA8,256,0,GL_RGBA,GL_FLOAT,sv.colorMap->getColors());
		
		/* Mark the texture object as up-to-date: */
		dataItem->colorMapVersions[scalarVariableIndex]=sv.colorMapVersion;
		}
	
	/* Set up the texture matrix to convert scalar variable values to color map indices: */
	renderState.setMatrixMode(2);
	if(dataItem->lastBoundScalarVariableIndex!=scalarVariableIndex||dataItem->textureMatrixVersion!=renderState.getMatrixVersion())
		{
		glLoadIdentity();
		double mapMin=double(sv.colorMapRange.first);
		double mapRange=double(sv.colorMapRange.second)-mapMin;
		glScaled(1.0/mapRange,1.0,1.0);
		glTranslated(-mapMin,0.0,0.0);
		renderState.updateMatrix();
		
		/* Mark the texture matrix as up to date: */
		dataItem->lastBoundScalarVariableIndex=scalarVariableIndex;
		dataItem->textureMatrixVersion=renderState.getMatrixVersion();
		}
	}
void VectorEvaluationLocator::highlightLocator(GLRenderState& renderState) const
	{
	/* Call the base class method: */
	EvaluationLocator::highlightLocator(renderState);
	
	/* Render the evaluated vector value if valid: */
	if(valueValid)
		{
		/* Set up OpenGL state for arrow rendering: */
		renderState.enableCulling(GL_BACK);
		renderState.setLighting(true);
		renderState.setTwoSidedLighting(false);
		glColor((*colorMap)(currentScalarValue));
		renderState.enableColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
		renderState.setTextureLevel(0);
		renderState.setSeparateSpecularColor(false);
		
		/* Render an arrow glyph: */
		Scalar arrowShaftRadius=Scalar((Vrui::Scalar(0.5)*Vrui::getUiSize())/Vrui::getNavigationTransformation().getScaling());
		Visualization::Wrappers::renderArrow(point,currentValue*arrowLengthScale,arrowShaftRadius,arrowShaftRadius*Scalar(3),arrowShaftRadius*Scalar(6),16);
		}
	}
Beispiel #12
0
void QuadSetNode::glRenderAction(GLRenderState& renderState) const
	{
	/* Bail out if there are no complete quads: */
	if(numQuads==0)
		return;
	
	/* Set up OpenGL state: */
	if(solid.getValue())
		renderState.enableCulling(GL_BACK);
	else
		renderState.disableCulling();
	
	/* Get the context data item: */
	DataItem* dataItem=renderState.contextData.retrieveDataItem<DataItem>(this);
	
	if(dataItem->vertexBufferObjectId!=0&&dataItem->indexBufferObjectId!=0)
		{
		typedef GLGeometry::Vertex<Scalar,2,void,0,Scalar,Scalar,3> Vertex; // Type for vertices
		typedef GLuint Index; // Type for vertex indices
		
		/* Bind the quad set's vertex and index buffer objects: */
		glBindBufferARB(GL_ARRAY_BUFFER_ARB,dataItem->vertexBufferObjectId);
		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,dataItem->indexBufferObjectId);
		
		/* Check if the vertex or index buffers are outdated: */
		if(dataItem->version!=version)
			{
			/* Upload the quad set's new vertices: */
			uploadQuads(dataItem);
			dataItem->version=version;
			}
		
		/* Set up the vertex arrays: */
		GLVertexArrayParts::enable(Vertex::getPartsMask());
		glVertexPointer(static_cast<Vertex*>(0));
		
		/* Render the quad set: */
		if(subdivideX.getValue()>1||subdivideY.getValue()>1)
			{
			/* Draw a set of quad strips: */
			const Index* indexPtr=0;
			for(unsigned int strip=0;strip<numQuads*subdivideY.getValue();++strip,indexPtr+=(subdivideX.getValue()+1)*2)
				glDrawElements(GL_QUAD_STRIP,(subdivideX.getValue()+1)*2,GL_UNSIGNED_INT,indexPtr);
			}
		else
			{
			/* Draw all quads in one go: */
			glDrawArrays(GL_QUADS,0,numQuads*4);
			}
		
		/* Reset the vertex arrays: */
		GLVertexArrayParts::disable(Vertex::getPartsMask());
		
		/* Protect the buffers: */
		glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
		}
	else
		{
		/* If your OpenGL can't do vertex buffers, you're f****d anyway. */
		}
	}