Ejemplo n.º 1
0
	void loadInto(ci::geom::Target* target, const ci::geom::AttribSet& requestedAttribs) const {
    for (auto &attrib : requestedAttribs) {
      size_t dims = getAttribDims(attrib);
      if (dims) {
        const void* pointer = getAttribPointer(attrib);
        if(pointer) target->copyAttrib(attrib, dims, 0, static_cast<const float*>(pointer), getNumVertices());
      }
    }

    if (getNumIndices()) {
      target->copyIndices(getPrimitive(), &indices[0], getNumIndices(), sizeof(element_t));
    }
  }
Ejemplo n.º 2
0
void ofxMesh::addFace(ofVec3f a, ofVec3f b, ofVec3f c) {
    ofVec3f normal = ((c - a).cross(b - a)).normalize();
    
	addNormal(normal);
	addVertex(a);
	addNormal(normal);
	addVertex(b);
	addNormal(normal);
	addVertex(c);
    
    addIndex(getNumIndices());
    addIndex(getNumIndices());
    addIndex(getNumIndices());    
}
Ejemplo n.º 3
0
void TriangleMeshData::getDataProperty(int property, void **_pvData)
{
    if (property == NUM_VERTICES)
    {
        ((int *)*_pvData)[0] = getNumVertices();
    }
    else if (property == NUM_INDICES)
    {
        ((int *)*_pvData)[0] = getNumIndices();
    }
    else if (property == COORDINATES)
    {
        *_pvData = getVertices();
    }
    else if (property == INDICES)
    {
        *_pvData = getIndices();
    }
    else if (property == VALUES)
    {
        *_pvData = getValues();
    }
    else
    {
        Data3D::getDataProperty(property, _pvData);
    }
}
Ejemplo n.º 4
0
void TriangleMeshFecData::getDataProperty(int property, void **_pvData)
{
    if (property == NUM_INDICES)
    {
        ((int *) *_pvData)[0] = getNumIndices();
    }
    else if (property == FEC_TRIANGLES)
    {
        *_pvData = getFecTriangles();
    }
    else
    {
        TriangleMeshData::getDataProperty(property, _pvData);
    }

}
Ejemplo n.º 5
0
ofxMesh &ofxMesh::addMesh(ofMesh b) {

    int numVertices = getNumVertices();
    int numIndices = getNumIndices();

    //add b
    addVertices(b.getVertices());
    addNormals(b.getNormals());
    addIndices(b.getIndices());

    //shift indices for b
    for (int i=0; i<b.getNumIndices(); i++) {
        getIndices()[numIndices+i] += numVertices;
    }

    return *this;
}
Ejemplo n.º 6
0
void ViveControllerManager::renderHand(UserInputMapper::PoseValue pose, gpu::Batch& batch, int index) {
    auto userInputMapper = DependencyManager::get<UserInputMapper>();
    Transform transform(userInputMapper->getSensorToWorldMat());
    transform.postTranslate(pose.getTranslation() + pose.getRotation() * glm::vec3(0, 0, CONTROLLER_LENGTH_OFFSET));

    int sign = index == LEFT_HAND ? 1.0f : -1.0f;
    glm::quat rotation = pose.getRotation() * glm::angleAxis(PI, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::angleAxis(sign * PI_OVER_TWO, glm::vec3(0.0f, 0.0f, 1.0f));
    transform.postRotate(rotation);

    batch.setModelTransform(transform);

    auto mesh = _modelGeometry.getMesh();
    batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer());
    batch.setInputBuffer(gpu::Stream::NORMAL,
        mesh->getVertexBuffer()._buffer,
        sizeof(float) * 3,
        mesh->getVertexBuffer()._stride);
    //batch.setInputBuffer(gpu::Stream::TEXCOORD,
    //    mesh->getVertexBuffer()._buffer,
    //    2 * 3 * sizeof(float),
    //    mesh->getVertexBuffer()._stride);
    batch.setIndexBuffer(gpu::UINT16, mesh->getIndexBuffer()._buffer, 0);
    batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
}
Ejemplo n.º 7
0
// Map for data access
volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 access)
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	if (mFinal)
	{
		llerrs << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << llendl;
	}
	if (!useVBOs() && !mMappedData && !mMappedIndexData)
	{
		llerrs << "LLVertexBuffer::mapVertexBuffer() called on unallocated buffer." << llendl;
	}
		
	if (!mVertexLocked && useVBOs())
	{
		{
			setBuffer(0, type);
			mVertexLocked = TRUE;
			stop_glerror();	

			if(sDisableVBOMapping)
			{
				allocateClientVertexBuffer() ;
			}
			else
			{
				mMappedData = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
			}
			stop_glerror();
		}
		
		if (!mMappedData)
		{
			if(!sDisableVBOMapping)
			{
				//--------------------
				//print out more debug info before crash
				llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ;
				GLint size ;
				glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size) ;
				llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl ;
				//--------------------

				GLint buff;
				glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff);
				if ((GLuint)buff != mGLBuffer)
				{
					llerrs << "Invalid GL vertex buffer bound: " << buff << llendl;
				}

				
				llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl;
			}
			else
			{
				llerrs << "memory allocation for vertex data failed." << llendl ;
			}
		}
		sMappedCount++;
	}
	
	return mMappedData;
}
Ejemplo n.º 8
0
// Map for data access
U8* LLVertexBuffer::mapBuffer(S32 access)
{
    LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
    if (mFinal)
    {
        llwarns << "LLVertexBuffer::mapBuffer() called on a finalized buffer." << llendl;
    }
    if (!useVBOs() && !mMappedData && !mMappedIndexData)
    {
        llwarns << "LLVertexBuffer::mapBuffer() called on unallocated buffer." << llendl;
    }

    if (!mLocked && useVBOs())
    {
        setBuffer(0);
        mLocked = TRUE;
        stop_glerror();
        mMappedData = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
        stop_glerror();
        mMappedIndexData = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
        stop_glerror();

        if (!mMappedData)
        {
            //--------------------
            //print out more debug info before crash
            llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ;
            GLint size ;
            glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size) ;
            llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl ;
            //--------------------

            GLint buff;
            glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff);
            if (buff != mGLBuffer)
            {
                llwarns << "Invalid GL vertex buffer bound: " << buff << llendl;
            }


            llwarns << "glMapBuffer returned NULL (no vertex data)" << llendl;
        }

        if (!mMappedIndexData)
        {
            GLint buff;
            glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff);
            if (buff != mGLIndices)
            {
                llwarns << "Invalid GL index buffer bound: " << buff << llendl;
            }

            llwarns << "glMapBuffer returned NULL (no index data)" << llendl;
        }

        sMappedCount++;
    }

    return mMappedData;
}
Ejemplo n.º 9
0
void Mesh::render (ShaderProgram* shader, int primitiveType) 
{
	render(shader, primitiveType, 0, m_indices->getNumIndices() > 0 ? getNumIndices() : getNumVertices());
}
Ejemplo n.º 10
0
void Mesh::render (int primitiveType) 
{
	render(primitiveType, 0, m_indices->getNumIndices() > 0 ? getNumIndices() : getNumVertices());
}
Ejemplo n.º 11
0
// @todo remove ... or just remove this complete class 
void VertexData::debugDraw(int drawMode) {
#if ROXLU_GL_MODE != ROXLU_GL_STRICT
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glDisable(GL_TEXTURE_2D);
	glUseProgram(0);
	glEnable(GL_DEPTH_TEST);
	// we adjust the size of the normals lines dynamically
	float line_length = 0.2;
	if(vertices.size() > 2) {
		float length = (vertices[1] - vertices[2]).length();
		if(length >= 3) {
			line_length = 3.2;
		}
	}


	float colors[4][3] = {
			{0.88,0.25,0.11}
			,{0.6,0.78,0.212}
			,{0.2,0.65,0.698}
			,{0.94,0.72,0.29}
	};
	 
	// draw using indices
	if(getNumTriangles() > 0) {
		// triangles (fills)
		Triangle tri;
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glColor3f(0.8,0.8,0.8);
		glBegin(GL_TRIANGLES);
			for(int i = 0; i < triangles.size(); ++i) {	
				tri = triangles[i];
				glVertex3fv(vertices[tri.va].getPtr());
				glVertex3fv(vertices[tri.vb].getPtr());
				glVertex3fv(vertices[tri.vc].getPtr());
			}
		glEnd();
		
		// triangles lines.
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glColor3f(0.1,0.1,0.1);
		glBegin(GL_TRIANGLES);
			for(int i = 0; i < triangles.size(); ++i) {	
				tri = triangles[i];
				glVertex3fv(vertices[tri.va].getPtr());
				glVertex3fv(vertices[tri.vb].getPtr());
				glVertex3fv(vertices[tri.vc].getPtr());
			}
		glEnd();
		
		// normals, tangents and binormals
		bool draw_normals= true;
		bool draw_tangents = true;
		bool draw_binormals = true;
		float s = 0.2;
		glBegin(GL_LINES);
			for(int i = 0; i < triangles.size(); ++i) {	
				tri = triangles[i];
				
				// normal - a
				if(draw_normals && tri.na) {
					glColor3f(0,1,1);
					glVertex3fv(vertices[tri.va].getPtr());
					glVertex3fv((vertices[tri.va]+normals[tri.na]*s).getPtr());	
				}

				// tangent - a
				if(draw_tangents && tri.ta) {
					glColor3f(1,0,0);
					glVertex3fv(vertices[tri.va].getPtr());
					glVertex3fv((vertices[tri.va]+(tangents[tri.ta]*s)).getPtr());	
				}

				// binormal - a 
				if(draw_binormals && tri.ba) {
					glColor3f(0,1,0);
					glVertex3fv(vertices[tri.va].getPtr());
					glVertex3fv((vertices[tri.va]+(binormals[tri.ba]*s)).getPtr());	
				}
				
				// normal - b
				if(draw_normals && tri.nb) {
					glColor3f(0,1,1);
					glVertex3fv(vertices[tri.vb].getPtr());
					glVertex3fv((vertices[tri.vb]+normals[tri.nb]*s).getPtr());	
				}
				
				// tangent - b
				if(draw_tangents && tri.tb) {
					glColor3f(1,0,0);
					glVertex3fv(vertices[tri.vb].getPtr());
					glVertex3fv((vertices[tri.vb]+(tangents[tri.tb]*s)).getPtr());	
				}
				
				// binormal - b
				if(draw_binormals && tri.bb) {
					glColor3f(0,1,0);
					glVertex3fv(vertices[tri.vb].getPtr());
					glVertex3fv((vertices[tri.vb]+(binormals[tri.bb]*s)).getPtr());	
				}
				
				// normal - c
				if(draw_normals && tri.nc) {
					glColor3f(0,1,1);
					glVertex3fv(vertices[tri.vc].getPtr());
					glVertex3fv((vertices[tri.vc]+normals[tri.nc]*s).getPtr());	
				}
				
				// tangent - c
				if(draw_tangents && tri.tc) {
					glColor3f(1,0,0);
					glVertex3fv(vertices[tri.vc].getPtr());
					glVertex3fv((vertices[tri.vc]+(tangents[tri.tc]*s)).getPtr());	
				}
				
				// binormal - c
				if(draw_binormals && tri.bc) {
					glColor3f(0,1,0);
					glVertex3fv(vertices[tri.vc].getPtr());
					glVertex3fv((vertices[tri.vc]+(binormals[tri.bc]*s)).getPtr());	
				}

			}
		glEnd();
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}
	else if(getNumIndices() > 0) {
		if(getNumTexCoords() > 0) {
			int len = indices.size();
			glBegin(drawMode);
			for(int i = 0; i < len; ++i) {
				glTexCoord2fv(texcoords[indices[i]].getPtr());
				glVertex3fv(vertices[indices[i]].getPtr());
			}
			glEnd();
		}
		else {
			int len = indices.size();
			int mod = (drawMode == GL_QUADS) ? 4 : 3;
			
			Vec4 colors[4];
			colors[0].set(1,0,0, 0.8);
			colors[1].set(0,1,0, 0.8);
			colors[2].set(0,0,1, 0.8);
			colors[3].set(1,1,0, 0.8);
			
			glBegin(drawMode);
			for(int i = 0; i < len; ++i) {
				glColor4fv(colors[i%mod].getPtr());
				glVertex3fv(vertices[indices[i]].getPtr());
			}
			glEnd();
			
			if(normals.size() > 0) {
				glBegin(GL_LINES);
				for(int i = 0; i < len; ++i) {
					int dx = indices[i];
					//printf("%d <--\n", dx);
					Vec3 pos = vertices[dx];
					Vec3 norm = normals[dx];
					
					Vec3 end = pos + (norm.scale(line_length*2));
					glColor4f(1.0f,0.0f,0.4f,1.0f);
					glColor4f(0.98, 0.92, 0.75, 0.6);
					glVertex3fv(pos.getPtr());
					glColor4f(1.0f, 0.0f,1.0f,1.0f);
					glColor3f(0.98, 0.92, 0.75);
					glColor4f(0.98, 0.92, 0.75,0.6);
					glVertex3fv(end.getPtr());
					
				}
				glEnd();
			}


		}
	}
	// w/o indices
	else {

		glColor4f(1,1,1,1);
		glUseProgram(0);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_BLEND);
		bool draw_texture = false;		
		bool draw_tangents = true;
		bool draw_normals = true;
		bool draw_binormals = true;
		if(draw_texture && getNumTexCoords() > 0) {
			glColor3f(0.98, 0.92, 0.75); // yellowish
			int len = vertices.size();
			glEnable(GL_TEXTURE_2D);
			glBegin(drawMode);
			for(int i = 0; i < len; ++i) {
				int parts = 3;
				if(drawMode == GL_QUADS) {
					parts = 4;
				}
				glColor3fv(colors[i%parts]);
				glTexCoord2fv(texcoords[i].getPtr());
				glVertex3fv(vertices[i].getPtr());
			}
			glEnd();
			glDisable(GL_TEXTURE_2D);
			
		
		}
		else {
			// shape	
			//glColor3f(0.98, 0.92, 0.75); // yellowish
			glColor3f(0.8,0.8,0.8);
			glBegin(drawMode);
			vector<Vec3>::iterator it = vertices.begin();
			float len = vertices.size();
			while(it != vertices.end()) {	
				glVertex3fv((*it).getPtr());
				++it;
			}
			glEnd();
		}

		// normals.
		int len = normals.size();
		if(draw_normals && len == vertices.size()) {	
			glColor3f(0,1,1);
			glLineWidth(3.0);
			glBegin(GL_LINES);
			for(int i = 0; i < len; ++i) {
				Vec3 pos = vertices[i];
				Vec3 norm = normals[i];
				norm.normalize();
				Vec3 end = pos + (norm.scale(line_length));
				glVertex3fv(pos.getPtr());
				glVertex3fv(end.getPtr());
			}
			glEnd();
		}
		
		// tangents
		if(draw_tangents && tangents.size() > 0) {
			glLineWidth(3.0);
			glColor3f(1.0f,0.0f,0.0f);
			int len = tangents.size();
			glBegin(GL_LINES);
			for(int i = 0; i < len; ++i) {
				Vec3 pos = vertices[i];
				Vec3 norm = tangents[i];
				norm.normalize();
				Vec3 end = pos + (norm.scale(line_length));
				glVertex3fv(pos.getPtr());
				glVertex3fv(end.getPtr());
			};
			glEnd();
		}

		// binormals
		if(draw_binormals && binormals.size() > 0) {
			glLineWidth(3.0);
			glColor4f(0.0f,1.0f,0.0f,1.0f);
			int len = tangents.size();
			glBegin(GL_LINES);
			for(int i = 0; i < len; ++i) {
				Vec3 pos = vertices[i];
				Vec3 binorm = binormals[i].normalize();
				Vec3 end = pos + (binorm.scale(line_length));
				glVertex3fv(pos.getPtr());
				glVertex3fv(end.getPtr());
			};
			glEnd();
		}

		
		// draw lines
		glPolygonOffset(-1.0f, -1.0f);
		glEnable(GL_POLYGON_OFFSET_LINE);
		glEnable(GL_LINE_SMOOTH);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glLineWidth(0.5f);
		glDisable(GL_TEXTURE_2D);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glColor3f(0.4,0.4,0.4);
		glBegin(drawMode);
		for(int i = 0; i < vertices.size(); ++i) {
			glVertex3fv(vertices[i].getPtr());
		}
		glEnd();
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		glEnable(GL_TEXTURE_2D);
		glDisable(GL_POLYGON_OFFSET_LINE);
		glLineWidth(1.0f);
		glDisable(GL_BLEND);
		glDisable(GL_LINE_SMOOTH);
		glColor3f(1,1,1);

		
	}
	
//	if(!blend_enabled) {
//		glDisable(GL_BLEND);
//	}
	
	glPopAttrib();
#endif // roxlu_gl_variant	
}
Ejemplo n.º 12
0
// Map for data access
volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index)
{
	LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
	if (mFinal)
	{
		llerrs << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << llendl;
	}
	if (!useVBOs() && !mMappedData && !mMappedIndexData)
	{
		llerrs << "LLVertexBuffer::mapVertexBuffer() called on unallocated buffer." << llendl;
	}
		
	if (!mVertexLocked && useVBOs())
	{
		{
			setBuffer(0, type);
			mVertexLocked = TRUE;
			stop_glerror();	

			if(sDisableVBOMapping)
			{
				allocateClientVertexBuffer() ;
			}
			else
			{
				U8* src = NULL;
				{
					src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
				}
				mMappedData = LL_NEXT_ALIGNED_ADDRESS<U8>(src);
				mAlignedOffset = mMappedData - src;
			}
			stop_glerror();
		}
		
		if (!mMappedData)
		{
			log_glerror();

			//check the availability of memory
			U32 avail_phy_mem, avail_vir_mem;
			LLMemoryInfo::getAvailableMemoryKB(avail_phy_mem, avail_vir_mem) ;
			llinfos << "Available physical mwmory(KB): " << avail_phy_mem << llendl ; 
			llinfos << "Available virtual memory(KB): " << avail_vir_mem << llendl;

			if(!sDisableVBOMapping)
			{			
				//--------------------
				//print out more debug info before crash
				llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl ;
				GLint size ;
				glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size) ;
				llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl ;
				//--------------------

				GLint buff;
				glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff);
				if ((GLuint)buff != mGLBuffer)
				{
					llerrs << "Invalid GL vertex buffer bound: " << buff << llendl;
				}

				
				llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl;
			}
			else
			{
				llerrs << "memory allocation for vertex data failed." << llendl ;
			}
		}
		sMappedCount++;
	}
	
	return mMappedData+mOffsets[type]+ (mIsStrided ? mStride : sTypeSize[type])*index;
}