glc_pointsprite.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #include "glc_pointsprite.h"
00026 #include "../glc_openglexception.h"
00027 #include "../glc_state.h"
00028 #include "../glc_ext.h"
00029 #include "../shading/glc_selectionmaterial.h"
00030
00031
00032 float GLC_PointSprite::m_MaxSize= -1.0f;
00033
00034
00035 GLC_PointSprite::GLC_PointSprite(float size, GLC_Material* pMaterial)
00036 :GLC_Geometry("PointSprite", false)
00037 , m_Size(size)
00038 , m_DistanceAttenuation(3)
00039 , m_FadeThresoldSize(60.0f)
00040 {
00041 Q_ASSERT(pMaterial != NULL);
00042 Q_ASSERT(pMaterial->hasTexture());
00043 addMaterial(pMaterial);
00044
00045
00046 m_DistanceAttenuation[0]= 1.0f;
00047 m_DistanceAttenuation[1]= 0.0f;
00048 m_DistanceAttenuation[2]= 0.0f;
00049 }
00050
00051 GLC_PointSprite::~GLC_PointSprite()
00052 {
00053
00054 }
00055
00056
00057 const GLC_BoundingBox& GLC_PointSprite::boundingBox(void)
00058 {
00059
00060 if (NULL == m_pBoundingBox)
00061 {
00062 m_pBoundingBox= new GLC_BoundingBox();
00063 const double epsilon= 1e-2;
00064 GLC_Point3d lower( - epsilon,
00065 - epsilon,
00066 - epsilon);
00067 GLC_Point3d upper( epsilon,
00068 epsilon,
00069 epsilon);
00070 m_pBoundingBox->combine(lower);
00071 m_pBoundingBox->combine(upper);
00072 }
00073 return *m_pBoundingBox;
00074 }
00075
00076
00077 GLC_Geometry* GLC_PointSprite::clone() const
00078 {
00079 return new GLC_PointSprite(*this);
00080 }
00081
00082
00083 void GLC_PointSprite::setSize(float size)
00084 {
00085 m_GeometryIsValid= false;
00086 m_Size= size;
00087
00088 if(qFuzzyCompare(-1.0f, m_MaxSize) && (m_MaxSize < m_Size))
00089 {
00090 m_Size= m_MaxSize;
00091 }
00092 }
00093
00094
00095 void GLC_PointSprite::setPointDistanceAttenuation(QVector<float> parameters)
00096 {
00097 Q_ASSERT(3 == parameters.size());
00098 m_DistanceAttenuation= parameters;
00099 }
00100
00102
00104
00105 void GLC_PointSprite::render(const GLC_RenderProperties& renderProperties)
00106 {
00107
00108 if (!GLC_State::pointSpriteSupported()) return;
00109
00110 glPushAttrib(GL_ALL_ATTRIB_BITS);
00111
00112 if (!GLC_State::isInSelectionMode())
00113 {
00114 glEnable( GL_BLEND );
00115 glDepthMask(GL_FALSE);
00116 glEnable(GL_TEXTURE_2D);
00117 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00118 glDisable(GL_LIGHTING);
00119
00120 if(m_MaterialHash.size() == 1)
00121 {
00122
00123 if (renderProperties.isSelected())
00124 {
00125 GLC_SelectionMaterial::glExecute();
00126 }
00127 else
00128 {
00129 GLC_Material* pCurrentMaterial= m_MaterialHash.begin().value();
00130 const GLfloat red= pCurrentMaterial->diffuseColor().redF();
00131 const GLfloat green= pCurrentMaterial->diffuseColor().greenF();
00132 const GLfloat blue= pCurrentMaterial->diffuseColor().blueF();
00133 const GLfloat alpha= pCurrentMaterial->diffuseColor().alphaF();
00134
00135 glColor4f(red, green, blue, alpha);
00136 pCurrentMaterial->glExecute();
00137
00138 }
00139 }
00140 }
00141 else
00142 {
00143 glDisable(GL_BLEND);
00144 glDisable(GL_TEXTURE_2D);
00145 glDisable(GL_LIGHTING);
00146 }
00147
00148
00149
00150 if (qFuzzyCompare(-1.0f, m_MaxSize))
00151 {
00152
00153 glGetFloatv(GL_POINT_SIZE_MAX, &m_MaxSize);
00154
00155
00156 if(m_MaxSize < m_Size)
00157 m_Size= m_MaxSize;
00158 }
00159
00160
00161
00162 glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, m_DistanceAttenuation.data());
00163 glPointSize(m_Size);
00164
00165
00166
00167
00168
00169 glPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, m_FadeThresoldSize);
00170
00171 glPointParameterf(GL_POINT_SIZE_MIN, 1.0f);
00172 glPointParameterf(GL_POINT_SIZE_MAX, m_Size);
00173
00174
00175
00176 glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
00177
00178 glEnable(GL_POINT_SPRITE);
00179 glDraw(renderProperties);
00180
00181 glPopAttrib();
00182
00183 }
00184
00185 void GLC_PointSprite::glDraw(const GLC_RenderProperties&)
00186 {
00187
00188 glBegin(GL_POINTS);
00189 glVertex3f(0.0f,0.0f,0.0f);
00190 glEnd();
00191
00192
00193 GLenum error= glGetError();
00194 if (error != GL_NO_ERROR)
00195 {
00196 GLC_OpenGlException OpenGlException("GLC_PointSprite::GlDraw ", error);
00197 throw(OpenGlException);
00198 }
00199 }
00200