Ejemplo n.º 1
0
void QVROSGViewer::render(QVRWindow* /* w */,
        const QVRRenderContext& context, int viewPass, unsigned int texture)
{
    // Set up framebuffer object to render into
    GLint width, height;
    glBindTexture(GL_TEXTURE_2D, texture);
    glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
    glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
    glBindTexture(GL_TEXTURE_2D, _fboDepthTex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height,
            0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
    glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0);

    // Set up OSG graphics window
    _graphicsWindow->resized(0, 0, width, height);

    // Set up OSG camera
    QMatrix4x4 P = context.frustum(viewPass).toMatrix4x4();
    _viewer.getCamera()->setProjectionMatrix(osg::Matrix(P.constData()));
    QMatrix4x4 V = context.viewMatrix(viewPass);
    _viewer.getCamera()->setViewMatrix(osg::Matrix(V.constData()));

    // Render
    _viewer.frame();
}
Ejemplo n.º 2
0
/*!
    Sets argument \a index for this kernel to \a value.

    The argument is assumed to have been declared with the
    type \c float16.
*/
void QCLKernel::setArg(int index, const QMatrix4x4 &value)
{
    if (sizeof(qreal) == sizeof(float)) {
        clSetKernelArg(m_kernelId, index, sizeof(float) * 16, value.constData());
    } else {
        float values[16];
        for (int posn = 0; posn < 16; ++posn)
            values[posn] = float(value.constData()[posn]);
        clSetKernelArg(m_kernelId, index, sizeof(values), values);
    }
}
Ejemplo n.º 3
0
static void setMatrix(GLenum type, const QMatrix4x4 &matrix)
{
    glMatrixMode(type);
    if (sizeof(qreal) == sizeof(GLfloat)) {
        glLoadMatrixf(reinterpret_cast<const GLfloat *>(matrix.constData()));
    } else {
        GLfloat mat[16];
        const qreal *m = matrix.constData();
        for (int index = 0; index < 16; ++index)
            mat[index] = m[index];
        glLoadMatrixf(mat);
    }
}
Ejemplo n.º 4
0
static inline void qMultMatrix( const QMatrix4x4 &mat )
{
    if (sizeof(qreal) == sizeof(GLfloat))
        glMultMatrixf( (GLfloat*) mat.constData() );
#ifndef QT_OPENGL_ES
    else if (sizeof(qreal) == sizeof(GLdouble))
        glMultMatrixd( (GLdouble*) mat.constData() );
#endif
    else {
        GLfloat fmat[16];
        qreal const *r = mat.constData();
        for (int i = 0; i < 16; ++i)
            fmat[i] = r[i];
        glMultMatrixf( fmat );
    }
}
void ProjectileNode::draw(std::stack<QMatrix4x4> &MVStack, QMatrix4x4 cameraMatrix, QMatrix4x4 projectionMatrix, QOpenGLShaderProgram *shader) {

	Shaders::bind(shader);
	MVStack.push(MVStack.top());

	MVStack.top().translate(this->translation);

	//Convert the quat to a matrix, may be a performance leak.
	QMatrix4x4 tempRot;
	tempRot.rotate(this->rotation.normalized());
	MVStack.top() *= tempRot;

	//If the node is a leaf, draw its contents
	if(leaf) {
		glUniformMatrix4fv(shader->uniformLocation("modelViewMatrix"), 1, GL_FALSE, MVStack.top().constData());
		glUniformMatrix4fv(shader->uniformLocation("perspectiveMatrix"), 1, GL_FALSE, projectionMatrix.constData());
		glUniformMatrix4fv(shader->uniformLocation("normalMatrix"), 1, GL_FALSE, MVStack.top().inverted().transposed().constData());
		int r = (id & 0x000000FF) >>  0;
		int g = (id & 0x0000FF00) >>  8;
		int b = (id & 0x00FF0000) >> 16;
		glUniform4f(shader->uniformLocation("id"), r/255.0f, g/255.0f, b/255.0f, 1.0f);

		glUniform4fv(shader->uniformLocation("color"), 1, color);

		this->primitive->draw();
	} else {
Ejemplo n.º 6
0
void GraphicsLayer13::setProjection(const QMatrix4x4& matrix)
{
	GLfloat projection[16];
	convertMatrix(matrix.constData(), projection);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(projection);
	glMatrixMode(GL_MODELVIEW);
}
Ejemplo n.º 7
0
QString Qgs3DUtils::matrix4x4toString( const QMatrix4x4 &m )
{
  const float *d = m.constData();
  QStringList elems;
  elems.reserve( 16 );
  for ( int i = 0; i < 16; ++i )
    elems << QString::number( d[i] );
  return elems.join( ' ' );
}
Ejemplo n.º 8
0
//! [2]
void Patch::draw() const
{
    glPushMatrix();
    glMultMatrixf(mat.constData());
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);

    const GLushort *indices = geom->faces.constData();
    glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices + start);
    glPopMatrix();
}
Ejemplo n.º 9
0
static void mulMatrix(QMatrix4x4 const& mat)
{
    double static_mat[16];
    qreal const* mat_data = mat.constData();
    for (int i = 0; i < 16; ++i)
    {
        static_mat[i] = mat_data[i];
    }

    glMultMatrixd(static_mat);
}
Ejemplo n.º 10
0
void GeometryEngine::drawNodeGeometry(Node* n)
{
    int m44size = 4 * sizeof(QVector4D);
    QMatrix4x4 m;

    m.setToIdentity();
    m.translate( n->m_position.x(), n->m_position.y(), 0 );
    m_modelsBuffer.write(((char*)m.constData()), m44size);
    m_numNodesToRender++;

}
Ejemplo n.º 11
0
void MyWindow::render()
{
    if(!isVisible() || !isExposed())
        return;

    if (!mContext->makeCurrent(this))
        return;

    static bool initialized = false;
    if (!initialized) {
        initialize();
        initialized = true;
    }

    if (mUpdateSize) {
        glViewport(0, 0, size().width(), size().height());
        mUpdateSize = false;
    }

    static float EvolvingVal = 0;
    EvolvingVal += 0.1f;

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    QMatrix4x4 RotationMatrix;

    RotationMatrix.rotate(EvolvingVal, QVector3D(0.0f, 0.0f, 0.1f));

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    mFuncs->glBindVertexBuffer(0, mPositionBufferHandle, 0, sizeof(GLfloat) * 3);
    mFuncs->glBindVertexBuffer(1, mColorBufferHandle,    0, sizeof(GLfloat) * 3);

    mFuncs->glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(0, 0);

    mFuncs->glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(1, 1);

    mProgram->bind();
    {
        glUniformMatrix4fv(mRotationMatrixLocation, 1, GL_FALSE, RotationMatrix.constData());
        glDrawArrays(GL_TRIANGLES, 0, 3);

        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
    }
    mProgram->release();

    mContext->swapBuffers(this);
}
Ejemplo n.º 12
0
void GameScene::renderWorld(const QMatrix4x4 &view,const QMatrix4x4 &rview)
{
    if(glActiveTexture){
        glActiveTexture(GL_TEXTURE0);
        blockTexture->bind();
    }

    glLineWidth(2.0f);
    lineProgram->bind();
    line->draw();                           //画十字准心
    lineProgram->release();

    glLoadMatrixf(rview.constData());
    glMultMatrixf(view.constData());


    blockProgram->bind();
    blockProgram->setUniformValue("tex",GLint(0));
    blockProgram->setUniformValue("view",view*rview);
    world->draw();
    blockProgram->release();

    QVector3D keyPosition=camera->getKeyPosition();
    if(keyPosition.y()>=0){
        lineQua->clear();
        for(int i=0;i<12;i++){
            lineQua->addLine(linePoints[i][0]+keyPosition,linePoints[i][1]+keyPosition);
        }
        lineProgram->bind();
        lineQua->draw();
        lineProgram->release();
    }

    if(glActiveTexture){
        glActiveTexture(GL_TEXTURE0);
        blockTexture->unbind();
    }
}
Ejemplo n.º 13
0
void Scene3D::paintGL()
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();         

  // glTranslatef(xTra, yTra, zTra);
   glScalef(nSca, nSca, nSca);
   
   /*glRotatef(xRot, 1, 0, 0);
   glRotatef(yRot, 0, 1, 0);
   glRotatef(zRot, 0, 0, 1);*/
   QMatrix4x4 m;
   m.rotate(trackball.rotation());
   glMultMatrixf(m.constData());

   drawAxis();
   drawFigure();
}
Ejemplo n.º 14
0
void SeaNode::draw(std::stack<QMatrix4x4> &MVStack, QMatrix4x4 cameraMatrix, QMatrix4x4 projectionMatrix, QOpenGLShaderProgram *shader) {
	QOpenGLShaderProgram *sh = Shaders::waterGeometryProgram;
	MVStack.push(MVStack.top());

	MVStack.top().translate(this->translation);

	//Convert the quat to a matrix, may be a performance leak.
	QMatrix4x4 tempRot;
	tempRot.rotate(this->rotation.normalized());
	MVStack.top() *= tempRot;

	//If the node is a leaf, draw its contents
	if(leaf) {
		Shaders::bind(sh);
		glUniformMatrix4fv(sh->uniformLocation("modelViewMatrix"), 1, GL_FALSE, MVStack.top().constData());
		glUniformMatrix4fv(sh->uniformLocation("cameraInverseMatrix"), 1, GL_FALSE, cameraMatrix.inverted().constData());
		glUniformMatrix4fv(sh->uniformLocation("perspectiveMatrix"), 1, GL_FALSE, projectionMatrix.constData());
		glUniformMatrix4fv(sh->uniformLocation("normalMatrix"), 1, GL_FALSE, MVStack.top().inverted().transposed().constData());
		int r = (id & 0x000000FF) >>  0;
		int g = (id & 0x0000FF00) >>  8;
		int b = (id & 0x00FF0000) >> 16;
		glUniform4f(sh->uniformLocation("id"), r/255.0f, g/255.0f, b/255.0f, 1.0f);

		glUniform4fv(sh->uniformLocation("color"), 1, color);

		struct timeval start;
		gettimeofday(&start, NULL);
		float seconds = ((start.tv_sec % (int) periodicity) + start.tv_usec / 1000000.0) / (periodicity / 4);

		glActiveTexture(GL_TEXTURE5);
		glBindTexture(GL_TEXTURE_3D, noiseTexture);
		//glUniform1i(sh->uniformLocation("noiseTexture"), 5);

		glUniform1i(sh->uniformLocation("seaWidth"), seaWidth);
		glUniform1i(sh->uniformLocation("seaHeight"), seaHeight);
		glUniform1f(sh->uniformLocation("time"), seconds);

		this->primitive->draw();
		Shaders::release(sh);
	} else {
Ejemplo n.º 15
0
void Visu3D::makeLandMark(QMatrix4x4 mTransformation){

    // repere
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd(mTransformation.constData());
    glLineWidth(2.5);
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_LINES);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(1, 0, 0);
    glEnd();

    glColor3f(0.0, 1.0, 0.0);
    glBegin(GL_LINES);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0, 1, 0);
    glEnd();

    glColor3f(0.0, 0.0, 1.0);
    glBegin(GL_LINES);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0, 0, 1);
    glEnd();
}
Ejemplo n.º 16
0
void GraphicsLayer13::setModelview(const QMatrix4x4& matrix)
{
	GLfloat modelview[16];
	convertMatrix(matrix.constData(), modelview);
	glLoadMatrixf(modelview);
}
Ejemplo n.º 17
0
void OculusRiftNode::render( qint64 pTimeStamp, QUuid pSourcePinId )
{
	Q_UNUSED( pSourcePinId )

#if !defined( OCULUS_PLUGIN_SUPPORTED )
	Q_UNUSED( pTimeStamp )
#else
	fugio::Performance	Perf( mNode, "drawGeometry", pTimeStamp );

	if( !mNode->isInitialised() )
	{
		return;
	}

	if( !mOculusRift->hmd() )
	{
		return;
	}

	// We need to keep a reference to ourselves here as ovr_SubmitFrame can
	// call the main app event loop, which can close the context and delete us!

	QSharedPointer<fugio::NodeControlInterface>	C = mNode->control();

	mOculusRift->drawStart();

	const float		NearPlane = variant( mPinNearPlane ).toFloat();
	const float		FarPlane  = variant( mPinFarPlane ).toFloat();

	//	float Yaw(3.141592f);
	//	Vector3f Pos2(0.0f,1.6f,-5.0f);
	//	Pos2.y = ovrHmd_GetFloat(mHMD, OVR_KEY_EYE_HEIGHT, Pos2.y);

	QMatrix4x4		MatEye = variant( mPinViewMatrix ).value<QMatrix4x4>();
	QVector3D		TrnEye = MatEye.column( 3 ).toVector3D();

	MatEye.setColumn( 3, QVector4D( 0, 0, 0, 1 ) );

	const Vector3f Pos2( TrnEye.x(), TrnEye.y(), TrnEye.z() );

	Matrix4f tempRollPitchYaw;

	memcpy( tempRollPitchYaw.M, MatEye.constData(), sizeof( float ) * 16 );

	const Matrix4f rollPitchYaw = tempRollPitchYaw;

	// Render Scene to Eye Buffers
	for (int eye = 0; eye < 2; eye++)
	{
		mOculusRift->drawEyeStart( eye );

		// Get view and projection matrices
		//Matrix4f rollPitchYaw = Matrix4f( MatEye.transposed().data() );
		Matrix4f finalRollPitchYaw = rollPitchYaw * Matrix4f( mOculusRift->eyeRenderPos( eye ).Orientation);
		Vector3f finalUp = finalRollPitchYaw.Transform(Vector3f(0, 1, 0));
		Vector3f finalForward = finalRollPitchYaw.Transform(Vector3f(0, 0, -1));
		Vector3f shiftedEyePos = Pos2 + rollPitchYaw.Transform( mOculusRift->eyeRenderPos( eye ).Position );

		Matrix4f view = Matrix4f::LookAtRH(shiftedEyePos, shiftedEyePos + finalForward, finalUp);
		Matrix4f proj = ovrMatrix4f_Projection( mOculusRift->defaultEyeFOV( eye ), NearPlane, FarPlane, ovrProjection_None );

		mProjection->setVariant( QMatrix4x4( &proj.M[ 0 ][ 0 ], 4, 4 ).transposed() );

		mView->setVariant( QMatrix4x4( &view.M[ 0 ][ 0 ], 4, 4 ).transposed() );

		fugio::OpenGLStateInterface		*CurrentState = 0;

		for( QSharedPointer<fugio::PinInterface> P : mNode->enumInputPins() )
		{
			if( !P->isConnected() )
			{
				continue;
			}

			if( P->connectedPin().isNull() )
			{
				continue;
			}

			if( P->connectedPin()->control().isNull() )
			{
				continue;
			}

			QObject					*O = P->connectedPin()->control()->qobject();

			if( !O )
			{
				continue;
			}

			if( true )
			{
				fugio::RenderInterface		*Geometry = qobject_cast<fugio::RenderInterface *>( O );

				if( Geometry )
				{
					Geometry->render( pTimeStamp );

					continue;
				}
			}

			if( true )
			{
				fugio::OpenGLStateInterface		*NextState = qobject_cast<fugio::OpenGLStateInterface *>( O );

				if( NextState != 0 )
				{
					if( CurrentState != 0 )
					{
						CurrentState->stateEnd();
					}

					CurrentState = NextState;

					CurrentState->stateBegin();

					continue;
				}
			}
		}

		if( CurrentState != 0 )
		{
			CurrentState->stateEnd();
		}

		mOculusRift->drawEyeEnd( eye );
	}

	mOculusRift->drawEnd();

	pinUpdated( mPinProjection );
	pinUpdated( mPinView );
#endif
}
Ejemplo n.º 18
0
void ShaderNode::updateUniforms( QList<ShaderBindData> &Bindings, qint64 pTimeStamp )
{
	bool		NumberOK;

	for( ShaderUniformMap::iterator it = mShaderUniformTypes.begin() ; it != mShaderUniformTypes.end() ; it++ )
	{
		ShaderUniformData				&UniformData = it.value();
		QSharedPointer<InterfacePin>	PIN = mNode->findPinByName( it.key() );

		if( PIN == 0 )
		{
			continue;
		}

		if( !PIN->isConnected() )
		{
			continue;
		}

		QSharedPointer<InterfacePinControl>		PinControl = PIN->connectedPin()->control();

		if( PinControl == 0 )
		{
			continue;
		}

		if( UniformData.mSampler && UniformData.mSize == 1 )
		{
			bindTexture( Bindings, PinControl, UniformData );

			continue;
		}

		//		if( mLastShaderLoad < pTimeStamp )//&& !PIN->isUpdated( pTimeStamp ) )
		//		{
		//			if( PIN->controlUuid() == PID_TRIGGER )
		//			{
		//				switch( UniformData.mType )
		//				{
		//					case GL_BOOL:
		//						glUniform1f( UniformData.mLocation, false );
		//						break;
		//				}
		//			}

		//			continue;
		//		}

		if( true )
		{
			InterfaceVariant		*PinVariant = qobject_cast<InterfaceVariant *>( PinControl->object() );

			if( PinVariant != 0 )
			{
				switch( UniformData.mType )
				{
					case GL_BOOL:
						{
							GLboolean		NewVal = PinVariant->variant().toBool();

							glUniform1ui( UniformData.mLocation, NewVal );
						}
						break;

					case GL_INT:
						{
							GLint		NewVal = PinVariant->variant().toInt( &NumberOK );

							if( NumberOK )
							{
								glUniform1i( UniformData.mLocation, NewVal );
							}
						}
						break;

					case GL_FLOAT:
						{
							GLfloat		NewVal = PinVariant->variant().toFloat( &NumberOK );

							if( NumberOK )
							{
								glUniform1f( UniformData.mLocation, NewVal );
							}
						}
						break;

					case GL_FLOAT_VEC2:
						{
							QVector2D		Vec2 = PinVariant->variant().value<QVector2D>();

							glUniform2f( UniformData.mLocation, Vec2.x(), Vec2.y() );
						}
						break;

					case GL_FLOAT_VEC3:
						{
							QVector3D		Vec3 = PinVariant->variant().value<QVector3D>();

							glUniform3f( UniformData.mLocation, Vec3.x(), Vec3.y(), Vec3.z() );
						}
						break;

					case GL_FLOAT_VEC4:
						{
							QVector4D		Vec4 = PinVariant->variant().value<QVector4D>();

							glUniform4f( UniformData.mLocation, Vec4.x(), Vec4.y(), Vec4.z(), Vec4.w() );
						}
						break;

					case GL_FLOAT_MAT2:
						{
							QMatrix4x4		Mat4 = PinVariant->variant().value<QMatrix4x4>();
							QMatrix2x2		Mat2 = Mat4.toGenericMatrix<2,2>();

							glUniformMatrix2fv( UniformData.mLocation, 1, GL_FALSE, Mat2.constData() );
						}
						break;

					case GL_FLOAT_MAT3:
						{
							QMatrix4x4		Mat4 = PinVariant->variant().value<QMatrix4x4>();
							QMatrix3x3		Mat3 = Mat4.toGenericMatrix<3,3>();

							//qDebug() << Mat4;
							//qDebug() << Mat3;

							glUniformMatrix3fv( UniformData.mLocation, 1, GL_FALSE, Mat3.constData() );
						}
						break;

					case GL_FLOAT_MAT4:
						{
							QMatrix4x4		NewVal = PinVariant->variant().value<QMatrix4x4>();

							glUniformMatrix4fv( UniformData.mLocation, 1, GL_FALSE, NewVal.constData() );
						}
						break;
				}

				OPENGL_PLUGIN_DEBUG;

				continue;
			}
		}

		if( true )
		{
			InterfaceColour		*PinColour = qobject_cast<InterfaceColour *>( PinControl->object() );

			if( PinColour != 0 )
			{
				switch( UniformData.mType )
				{
					case GL_FLOAT_VEC3:
						glUniform3f( UniformData.mLocation, PinColour->colour().redF(), PinColour->colour().greenF(), PinColour->colour().blueF() );
						break;

					case GL_FLOAT_VEC4:
						glUniform4f( UniformData.mLocation, PinColour->colour().redF(), PinColour->colour().greenF(), PinColour->colour().blueF(), PinColour->colour().alphaF() );
						break;
				}

				OPENGL_PLUGIN_DEBUG;

				continue;
			}
		}

		if( true )
		{
			if( PIN->controlUuid() == PID_TRIGGER )
			{
				switch( UniformData.mType )
				{
					case GL_BOOL:
						glUniform1f( UniformData.mLocation, true );
						break;
				}

				OPENGL_PLUGIN_DEBUG;

				continue;
			}
		}
	}
}
Ejemplo n.º 19
0
void ShaderNode::inputsUpdated( qint64 pTimeStamp )
{
	fugio::Performance	Perf( mNode, "inputsUpdated" );

	if( !mInitialised )
	{
		return;
	}

	OPENGL_PLUGIN_DEBUG;

	if( mPinShaderVertex->isUpdated( mLastShaderLoad ) || mPinShaderGeometry->isUpdated( mLastShaderLoad ) || mPinShaderFragment->isUpdated( mLastShaderLoad ) )
	{
		loadShader();

		mLastShaderLoad = pTimeStamp;
	}

	OPENGL_PLUGIN_DEBUG;

	if( !mProgramLinked )
	{
		return;
	}

	//-------------------------------------------------------------------------

	int		W, H, D;

	QList< QSharedPointer<InterfacePin> >	OutPinLst = mNode->enumOutputPins();
	QList< QSharedPointer<InterfacePin> >	InpPinLst = mNode->enumInputPins();

	//-------------------------------------------------------------------------

	glUseProgram( mProgramId );

	OPENGL_PLUGIN_DEBUG;

	QList<ShaderBindData>		Bindings;

	updateUniforms( Bindings, pTimeStamp );

	if( mPinOutputGeometry->isConnectedToActiveNode() )
	{
		mNode->context()->pinUpdated( mPinOutputGeometry );
	}

	if( activeBufferCount( OutPinLst ) == 0 )
	{
		glUseProgram( 0 );

		return;
	}

	//-------------------------------------------------------------------------
	// Bind all output buffers

	QVector<GLenum>		Buffers;

	bindOutputBuffers( Buffers, OutPinLst, W, H, D );

	if( mFrameBufferId != 0 )
	{
		glBindFramebuffer( GL_FRAMEBUFFER, mFrameBufferId );

		if( !Buffers.empty() )
		{
			glDrawBuffers( Buffers.size(), Buffers.data() );

			OPENGL_PLUGIN_DEBUG;
		}

		if( glCheckFramebufferStatus( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE )
		{
			qDebug() << "glCheckFramebufferStatus( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE";
		}
	}

	//-------------------------------------------------------------------------

	InterfaceOpenGLState		*State = 0;

	if( mPinState->isConnected() )
	{
		State = qobject_cast<InterfaceOpenGLState *>( mPinState->connectedPin()->control()->object() );
	}

	if( State != 0 )
	{
		State->stateBegin();
	}

	//-------------------------------------------------------------------------

	if( true )
	{
		glViewport( 0, 0, W, H );

		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

		QList<InterfaceGeometry*>		GeometryList;

		for( QList< QSharedPointer<InterfacePin> >::iterator it = InpPinLst.begin() ; it != InpPinLst.end() ; it++ )
		{
			QSharedPointer<InterfacePin>	InpPin = *it;

			if( !InpPin->isConnectedToActiveNode() )
			{
				continue;
			}

			QSharedPointer<InterfacePinControl>		 GeometryControl = InpPin->connectedPin()->control();

			InterfaceGeometry		*Geometry = ( GeometryControl.isNull() ? 0 : qobject_cast<InterfaceGeometry *>( GeometryControl->object() ) );

			if( Geometry != 0 )
			{
				GeometryList.append( Geometry );
			}
		}

		if( GeometryList.isEmpty() )
		{
			QMatrix4x4		pmvMatrix;

			pmvMatrix.setToIdentity();

			pmvMatrix.ortho( QRect( QPoint( 0, 0 ), QSize( W, H ) ) );

			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();

			glLoadMatrixf( pmvMatrix.constData() );

			//Initialize Modelview Matrix
			glMatrixMode( GL_MODELVIEW );
			glLoadIdentity();

			glColor4f( 1.0, 1.0, 1.0, 1.0 );

			//glEnable( GL_BLEND );

			//glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

			//glActiveTexture( GL_TEXTURE0 );

			OPENGL_PLUGIN_DEBUG;

			GLint		x0 = 0;
			GLint		x1 = W;
			GLint		y0 = 0;
			GLint		y1 = H;

			glBegin( GL_QUADS );
				glMultiTexCoord2i( GL_TEXTURE0, x0, y1 );	glMultiTexCoord2f( GL_TEXTURE1, 0, 1 );		glVertex2i( x0, y0 );
				glMultiTexCoord2i( GL_TEXTURE0, x1, y1 );	glMultiTexCoord2f( GL_TEXTURE1, 1, 1 );		glVertex2i( x1, y0 );
				glMultiTexCoord2i( GL_TEXTURE0, x1, y0 );	glMultiTexCoord2f( GL_TEXTURE1, 1, 0 );		glVertex2i( x1, y1 );
				glMultiTexCoord2i( GL_TEXTURE0, x0, y0 );	glMultiTexCoord2f( GL_TEXTURE1, 0, 0 );		glVertex2i( x0, y1 );
			glEnd();
		}
		else
		{
			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();

			//Initialize Modelview Matrix
			glMatrixMode( GL_MODELVIEW );
			glLoadIdentity();

			glColor4f( 1.0, 1.0, 1.0, 1.0 );

			//glEnable( GL_BLEND );

			//glBlendFunc( GL_ONE, GL_ONE );

			//glActiveTexture( GL_TEXTURE0 );

			OPENGL_PLUGIN_DEBUG;

			//glTranslatef( 0.0f, 0.0f, -5.0f );

			foreach( InterfaceGeometry *Geometry, GeometryList )
			{
				Geometry->drawGeometry();
			}
		}

		OPENGL_PLUGIN_DEBUG;
	}
Ejemplo n.º 20
0
void MyWindow::render()
{
    if(!isVisible() || !isExposed())
        return;

    if (!mContext->makeCurrent(this))
        return;

    static bool initialized = false;
    if (!initialized) {
        initialize();
        initialized = true;
    }

    if (mUpdateSize) {
        glViewport(0, 0, size().width(), size().height());
        mUpdateSize = false;
    }

    static float EvolvingVal = 0;
    EvolvingVal += 0.1f;

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    QMatrix4x4 RotationMatrix;

    RotationMatrix.rotate(EvolvingVal, QVector3D(0.0f, 0.0f, 0.1f));

    glBindBuffer(GL_ARRAY_BUFFER, mVBOCol);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    mFuncs->glBindVertexBuffer(0, mVBOCol, 0, sizeof(mVerticesCol[0]));
    mFuncs->glBindVertexBuffer(1, mVBOCol, 0, sizeof(mVerticesCol[0]));

    mFuncs->glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(0, 0);

    mFuncs->glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, sizeof(mVerticesCol[0].getPos())+ sizeof(mVerticesCol[0].getNormal()));
    mFuncs->glVertexAttribBinding(1, 1);

    mProgramCol->bind();
    {
        glUniformMatrix4fv(mRotationMatrixLocation, 1, GL_FALSE, RotationMatrix.constData());
        glDrawArrays(GL_TRIANGLES, 0, 3);

        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
    }
    mProgramCol->release();


    glBindBuffer(GL_ARRAY_BUFFER, mVBONorm);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    mFuncs->glBindVertexBuffer(0, mVBONorm, 0, sizeof(mVerticesNorm[0]));
    mFuncs->glBindVertexBuffer(1, mVBONorm, 0, sizeof(mVerticesNorm[0]));

    mFuncs->glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(0, 0);

    mFuncs->glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, sizeof(mVerticesNorm[0].getPos()));
    mFuncs->glVertexAttribBinding(1, 1);

    mProgramNorm->bind();
    {
        glUniformMatrix4fv(mRotationMatrixLocation, 1, GL_FALSE, RotationMatrix.constData());
        glDrawArrays(GL_TRIANGLES, 0, 3);

        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
    }
    mProgramNorm->release();


    glBindBuffer(GL_ARRAY_BUFFER, mVBOTex);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    mFuncs->glBindVertexBuffer(0, mVBOTex, 0, sizeof(mVerticesTex[0]));
    mFuncs->glBindVertexBuffer(1, mVBOTex, 0, sizeof(mVerticesTex[0]));

    mFuncs->glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
    mFuncs->glVertexAttribBinding(0, 0);

    mFuncs->glVertexAttribFormat(1, 2, GL_FLOAT, GL_FALSE, sizeof(mVerticesTex[0].getPos()) + sizeof(mVerticesTex[0].getNormal()));
    mFuncs->glVertexAttribBinding(1, 1);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, mTextureObject);
    glUniform1i(gSamplerLocation, 0);
    mProgramTex->bind();
    {
        glUniformMatrix4fv(mRotationMatrixLocation, 1, GL_FALSE, RotationMatrix.constData());
        glDrawArrays(GL_TRIANGLES, 0, 3);

        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
    }
    mProgramTex->release();


    mContext->swapBuffers(this);
}
void ParticleExplosionNode2::draw(std::stack<QMatrix4x4> &MVStack, QMatrix4x4 cameraMatrix, QMatrix4x4 projectionMatrix, QOpenGLShaderProgram *shader) {
    //If the node is a leaf, draw its contents
    if(leaf) {
        GBuffer::activeGBuffer()->drawToFinal();
        Shaders::bind(Shaders::particleProgram);
//    Scene::passLights(cameraMatrix, Shaders::phongProgram);
        MVStack.push(MVStack.top());

        MVStack.top().translate(this->translation);

        //Convert the quat to a matrix, may be a performance leak.
        QMatrix4x4 tempRot;
        tempRot.rotate(this->rotation.normalized());
        MVStack.top() *= tempRot;

		lastCameraRotation = Camera::M4toQuat(cameraMatrix);

        glUniformMatrix4fv(Shaders::particleProgram->uniformLocation("modelViewMatrix"), 1, GL_FALSE, MVStack.top().constData());
        glUniformMatrix4fv(Shaders::particleProgram->uniformLocation("perspectiveMatrix"), 1, GL_FALSE, projectionMatrix.constData());

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, sprite);
        glUniform1i(Shaders::particleProgram->uniformLocation("sprite"), 0);

        drawParticles();

        MVStack.pop();
        Shaders::release(Shaders::particleProgram);
        GBuffer::activeGBuffer()->bindGeometryPass();
    } else {
        //Else, recurse into its children
        std::for_each(children.begin(), children.end(), [&MVStack, cameraMatrix, projectionMatrix, shader](SceneGraph *s){s->draw(MVStack, cameraMatrix, projectionMatrix, shader);});
    }
}
Ejemplo n.º 22
0
inline void glMultMatrix( const QMatrix4x4 & m )	{ glMultMatrix( m.constData() ); }
Ejemplo n.º 23
0
inline void glLoadMatrix( const QMatrix4x4 & m )	{ glLoadMatrix( m.constData() ); }
Ejemplo n.º 24
0
void PointSpriteRenderer::render_impl(const QQuaternion & rotation,
                                      const QVector3D & scale,
                                      const QVector3D & translation,
                                      const QQuaternion & /* camera_rotation */,
                                      GLuint vbo_positions,
                                      GLuint vbo_colors,
                                      size_t part_cnt,
                                      const QVector3D & /* volume_size */)
{
  // render the particle system
  OGLF->glEnable(GL_DEPTH_TEST);

  m_vao.bind();

  GLuint shader_id = m_prog.programId();

  OGLF->glUseProgram(shader_id);

  // calculate scene transformation
  QMatrix4x4 mv;

  mv.translate(translation);
  mv.rotate(rotation);
  mv.scale(scale);

  //QMatrix4x4 mvp(m_proj * mv);

  // set transformation matrices
  OGLF->glUniformMatrix4fv(OGLF->glGetUniformLocation(shader_id, "proj"), 1, GL_FALSE, m_proj.constData());
  OGLF->glUniformMatrix4fv(OGLF->glGetUniformLocation(shader_id, "mv"), 1, GL_FALSE, mv.constData());
  //OGLF->glUniformMatrix4fv(OGLF->glGetUniformLocation(shader_id, "mvp"), 1, GL_FALSE, mvp.constData());
  OGLF->glUniform2f(OGLF->glGetUniformLocation(shader_id, "screen_size"), m_w, m_h);

  // set light parameters
  OGLF->glUniform3f(OGLF->glGetUniformLocation(shader_id, "light_pos"),
                    m_light_pos.x(), m_light_pos.y(), m_light_pos.z());
  OGLF->glUniform3f(OGLF->glGetUniformLocation(shader_id, "light_col_a"),
                    m_light_ambient_col.x(), m_light_ambient_col.y(), m_light_ambient_col.z());
  OGLF->glUniform3f(OGLF->glGetUniformLocation(shader_id, "light_col_d"),
                    m_light_diffuse_col.x(), m_light_diffuse_col.y(), m_light_diffuse_col.z());

  // set attributes
  if (m_use_uniform_color)
  {
    OGLF->glUniform1i(OGLF->glGetUniformLocation(shader_id, "use_uniform_color"), 1);
    OGLF->glUniform3f(OGLF->glGetUniformLocation(shader_id, "particle_uniform_color"),
                      m_particle_col.x(), m_particle_col.y(), m_particle_col.z());
    OGLF->glDisableVertexAttribArray(5);
  }
  else
  {
    OGLF->glUniform1i(OGLF->glGetUniformLocation(shader_id, "use_uniform_color"), 0);
    OGLF->glBindBuffer(GL_ARRAY_BUFFER, vbo_colors);
    OGLF->glEnableVertexAttribArray(5);
    OGLF->glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (void *) (0));
  }

  OGLF->glBindBuffer(GL_ARRAY_BUFFER, vbo_positions);
  OGLF->glEnableVertexAttribArray(4);
  OGLF->glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, 0, (void *) (0));

  // render points
  OGLF->glEnable(GL_POINT_SPRITE);
  //OGLF->glPointSize(particle_radius * 2.0f);
  OGLF->glEnable(GL_PROGRAM_POINT_SIZE);

  OGLF->glDrawArrays(GL_POINTS, 0, part_cnt);

  // clean up
  OGLF->glDisable(GL_PROGRAM_POINT_SIZE);
  OGLF->glDisable(GL_POINT_SPRITE);

  OGLF->glBindBuffer(GL_ARRAY_BUFFER, 0);

  OGLF->glUseProgram(0);

  m_vao.release();
}