Пример #1
0
bool Viewport::isContainedInFrustum(const Renderable& r) const {
	AABB bb = r.getObject().transformAABB(r.getMesh()->getBounds());

	Vector halfSize = (bb.max - bb.min) * 0.5f;
	Vector worldPos = r.getObject().getWorldPosition();

	//for each plane, check where the AABB is placed
	for (auto&& i : range(4)) {
		if (mWorldFrustumPlanes[i].getSide(worldPos, halfSize) < 0) {
			return false;
		}
	}

	return true;
}
Пример #2
0
void Renderer::renderElement( Viewport& viewport, Renderable& elem )
{
	DEBUG_ASSERT( frameStarted, "Tried to render an element but the frame wasn't started" );
	DEBUG_ASSERT(elem.getMesh()->isLoaded(), "Rendering with a mesh with no GPU data!");
	DEBUG_ASSERT(elem.getMesh()->getVertexCount() > 0, "Rendering a mesh with no vertices");

#ifndef PUBLISH
	frameVertexCount += elem.getMesh()->getVertexCount();
	frameTriCount += elem.getMesh()->getPrimitiveCount();

	//each renderable is a single batch
	++frameBatchCount;
#endif // !PUBLISH
	
	currentState.world = elem.getWorldTransform();
	currentState.worldView = currentState.view * currentState.world;

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf( glm::value_ptr( currentState.worldView ) );
	
#ifdef DOJO_SHADERS_AVAILABLE
	if( elem.getShader() )
	{
		currentState.worldViewProjection = currentState.projection * currentState.worldView;
		elem.getShader()->use( elem );
	}
	else
		glUseProgram( 0 );
#endif
		
	//I'm not sure this actually makes sense
#ifndef USING_OPENGLES
	glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT );
#endif
	glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, (float*)(&elem.color) );
	
	glEnable( GL_COLOR_MATERIAL );

	elem.commitChanges();

	static const GLenum glModeMap[] = {
		GL_TRIANGLE_STRIP, //TriangleStrip,
		GL_TRIANGLES, //TriangleList,
		GL_LINE_STRIP, //LineStrip,
		GL_LINES, //LineList
		GL_POINTS
	};

	Mesh* m = elem.getMesh();
	GLenum mode = glModeMap[(byte)m->getTriangleMode()];

	if( !m->isIndexed() )
		glDrawArrays( mode, 0, m->getVertexCount() );
	else {
		DEBUG_ASSERT(m->getIndexCount() > 0, "Rendering an indexed mesh with no indices");
		glDrawElements(mode, m->getIndexCount(), m->getIndexGLType(), 0);  //on OpenGLES, we have max 65536 indices!!!
	}

#ifndef DOJO_DISABLE_VAOS
	glBindVertexArray( 0 );
#endif

#ifdef DOJO_SHADERS_AVAILABLE
	//HACK //TODO remove fixed function pipeline (it breaks if generic arrays are set)
	if( elem.getShader() )
	{
		for( auto& attr : elem.getShader()->getAttributes() )
			glDisableVertexAttribArray( attr.second.location );
	}
#endif
}