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