void ofBufferObject::copyTo(ofBufferObject & dstBuffer) const{
	bind(GL_COPY_READ_BUFFER);
	dstBuffer.bind(GL_COPY_WRITE_BUFFER);
	glCopyBufferSubData(GL_COPY_READ_BUFFER,GL_COPY_WRITE_BUFFER,0,0,size());
	unbind(GL_COPY_READ_BUFFER);
	dstBuffer.unbind(GL_COPY_WRITE_BUFFER);
}
Esempio n. 2
0
//----------------------------------------------------------
void ofTexture::allocateAsBufferTexture(const ofBufferObject & buffer, int glInternalFormat){
	texData.glInternalFormat = glInternalFormat;
	texData.textureTarget = GL_TEXTURE_BUFFER;
	texData.bufferId = buffer.getId();
	allocate(texData,0,0);
	buffer.bind(GL_TEXTURE_BUFFER);
}
void ofBufferObject::copyTo(ofBufferObject & dstBuffer, int readOffset, int writeOffset, size_t size) const{
	bind(GL_COPY_READ_BUFFER);
	dstBuffer.bind(GL_COPY_WRITE_BUFFER);
	glCopyBufferSubData(GL_COPY_READ_BUFFER,GL_COPY_WRITE_BUFFER,readOffset,writeOffset,size);
	unbind(GL_COPY_READ_BUFFER);
	dstBuffer.unbind(GL_COPY_WRITE_BUFFER);
}
Esempio n. 4
0
//----------------------------------------------------------
void ofFbo::copyTo(ofBufferObject & buffer) const{
	if(!bIsAllocated) return;
	bind();
	buffer.bind(GL_PIXEL_PACK_BUFFER);
	glReadPixels(0, 0, settings.width, settings.height, ofGetGLFormatFromInternal(settings.internalformat), ofGetGlTypeFromInternal(settings.internalformat), NULL);
	buffer.unbind(GL_PIXEL_PACK_BUFFER);
	unbind();
}
Esempio n. 5
0
//----------------------------------------------------------
void ofTexture::copyTo(ofBufferObject & buffer) const{
	ofSetPixelStoreiAlignment(GL_PACK_ALIGNMENT,getWidth(),ofGetBytesPerChannelFromGLType(ofGetGlTypeFromInternal(texData.glInternalFormat)),ofGetNumChannelsFromGLFormat(ofGetGLFormatFromInternal(texData.glInternalFormat)));
	buffer.bind(GL_PIXEL_PACK_BUFFER);
	glBindTexture(texData.textureTarget,texData.textureID);
	glGetTexImage(texData.textureTarget,0,ofGetGLFormatFromInternal(texData.glInternalFormat),ofGetGlTypeFromInternal(texData.glInternalFormat),0);
	glBindTexture(texData.textureTarget,0);
	buffer.unbind(GL_PIXEL_PACK_BUFFER);

}
Esempio n. 6
0
void ofBufferObject::copyTo(ofBufferObject & dstBuffer, int readOffset, int writeOffset, size_t size) const{
#ifdef GLEW_VERSION_4_5
	if (GLEW_EXT_direct_state_access) {
		glCopyNamedBufferSubData(data->id,dstBuffer.getId(),readOffset,writeOffset,size);
		return;
	}
#endif
	bind(GL_COPY_READ_BUFFER);
	dstBuffer.bind(GL_COPY_WRITE_BUFFER);
	glCopyBufferSubData(GL_COPY_READ_BUFFER,GL_COPY_WRITE_BUFFER,readOffset,writeOffset,size);
	unbind(GL_COPY_READ_BUFFER);
	dstBuffer.unbind(GL_COPY_WRITE_BUFFER);
}
Esempio n. 7
0
void TransitionParticles::update(const ofBufferObject & blobs, const ofxTexture3d & noiseField, float now){
	auto numParticles = totalVertices / every;

	computeShader.begin();
	computeShader.setUniform1f("every", every);
	computeShader.setUniform1f("now", now);
	computeShader.setUniform1f("dt",ofGetLastFrameTime()*speed);
	computeShader.setUniform1f("repulsionForce", repulsion);
	computeShader.setUniform1f("attractionForce", attraction);
	computeShader.setUniform1f("elapsedTime",now);
	computeShader.setUniform1f("bufferSize", totalVertices);
	computeShader.setUniform1f("noiseSize", noiseField.texData.width);
	computeShader.setUniform1f("frameNum", ofGetFrameNum());
	computeShader.setUniformTexture("noiseField", GL_TEXTURE_3D, noiseField.texData.textureID, 0);
	computeShader.dispatchCompute(numParticles / 1024 + 1, 1, 1);
	computeShader.end();

	glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, numVerticesQuery);
	shader.beginTransformFeedback(GL_TRIANGLES, feedbackBuffer);
	blobs.bindBase(GL_SHADER_STORAGE_BUFFER, 0);
	shader.setUniform1f("every", every);
	shader.setUniform1f("scale", scale);
	shader.setUniform4f("particleColor", color);
	model.drawInstanced(GL_TRIANGLES, 0, model.getNumVertices(), numParticles);
	shader.endTransformFeedback(feedbackBuffer);
	glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
	glGetQueryObjectuiv(numVerticesQuery, GL_QUERY_RESULT, &numPrimitives);
}
Esempio n. 8
0
//--------------------------------------------------------------
void ofVbo::setVertexBuffer(ofBufferObject & buffer, int numCoords, int stride, int offset){
	positionAttribute.setBuffer(buffer, numCoords, stride, offset);
	bUsingVerts = true;
	// TODO: Check: we have no perfect way of knowing the new number of total vertices,
	// since the buffer does not tell us, so we try to calculate based on the data size
	// and the number of coordinates.
	totalVerts = buffer.size() / (numCoords * sizeof(float));

}
Esempio n. 9
0
//--------------------------------------------------------------
void ofVbo::setVertexBuffer(ofBufferObject & buffer, int numCoords, int stride, int offset){
	positionAttribute.setBuffer(buffer, numCoords, stride, offset);
	bUsingVerts = true;
	vaoChanged = true;
	// Calculate the total number of vertices based on what we know:
	int tmpStride = stride;
	if (tmpStride == 0) {
		// if stride is not given through argument, we need to calculate it based on 
		// on the data size and the number of coordinates.
		tmpStride = (numCoords * sizeof(float));
		if (tmpStride == 0) {
			ofLogWarning() << "Setting buffer with 0 vertices.";
			totalVerts = 0;
			return;
		}
	}
	totalVerts = buffer.size() / tmpStride;
}
Esempio n. 10
0
//----------------------------------------------------------
void ofTexture::loadData(const ofBufferObject & buffer, int glFormat, int glType){
	buffer.bind(GL_PIXEL_UNPACK_BUFFER);
	loadData(0,texData.width,texData.height,glFormat,glType);
	buffer.unbind(GL_PIXEL_UNPACK_BUFFER);
}