ShDataVariant<T, DT>::ShDataVariant(const ShDataVariant<T, DT> &other)
    : m_managed(true)
{
    int size = other.size();
    alloc(size);
    memcpy(m_begin, other.m_begin, size * datasize());
}
ShDataVariant<T, DT>::ShDataVariant(void *data, int N, bool managed)
    : m_managed(managed)
{
    if(m_managed) {
        alloc(N);
        memcpy(m_begin, data, N * datasize());
    } else {
        m_begin = reinterpret_cast<DataType*>(data);
        m_end = m_begin + N;
    }
}
int
pktchan_to_tracebuf( PktChannel *pktchan,
		     TracePacket *tp,
		     double starttime, 
		     int *nbytes )
{
	char	*datap;
	int	dsize_bytes;
	STACHAN *stachan;

	strcpy( tp->trh.datatype, UNSTUFFPKT_DATATYPE );

	if( ( stachan = lookup_stachan( pktchan->sta, pktchan->chan ) ) == NULL )
	{
		logit( "et", "Couldn't find %s %s in station info\n",
			pktchan->sta, pktchan->chan );
		return -1;
	}
	else
	{
		tp->trh.pinno = stachan->pinno;
	}

	strcpy( tp->trh.sta, pktchan->sta );
	strcpy( tp->trh.chan, pktchan->chan );
	strcpy( tp->trh.net, pktchan->net );
	tp->trh.samprate = pktchan->samprate;
	tp->trh.nsamp = pktchan->nsamp;
	tp->trh.starttime = starttime;
	tp->trh.endtime = ENDTIME( starttime,
				   pktchan->samprate,
				   pktchan->nsamp );
	strcpy( tp->trh.quality, "" );
	strcpy( tp->trh.pad, "" );

	datap = &tp->msg[0] + sizeof( TRACE_HEADER );
	dsize_bytes = datasize( tp->trh.datatype ) * tp->trh.nsamp;

	*nbytes = dsize_bytes + sizeof( TRACE_HEADER );

	memcpy( datap, pktchan->data, dsize_bytes );

	return 0;
}
Beispiel #4
0
void
OGLShaderObject::_initActiveUniformBlock() noexcept
{
	GLint numUniformBlock = 0;
	GLint maxUniformBlockLength = 0;
	GLint maxUniformLength = 0;

	glGetProgramiv(_program, GL_ACTIVE_UNIFORM_BLOCKS, &numUniformBlock);
	glGetProgramiv(_program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &maxUniformBlockLength);
	glGetProgramiv(_program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLength);

	if (numUniformBlock)
	{
		auto nameUniformBlock = make_scope<GLchar[]>(maxUniformBlockLength + 1);
		nameUniformBlock[maxUniformBlockLength] = 0;

		for (GLint i = 0; i < numUniformBlock; ++i)
		{
			GLsizei lengthUniformBlock;
			glGetActiveUniformBlockName(_program, (GLuint)i, maxUniformBlockLength, &lengthUniformBlock, nameUniformBlock.get());

			GLuint location = glGetUniformBlockIndex(_program, nameUniformBlock.get());
			if (location == GL_INVALID_INDEX)
				continue;

			glUniformBlockBinding(_program, location, location);

			GLint size;
			GLint count;

			glGetActiveUniformBlockiv(_program, location, GL_UNIFORM_BLOCK_DATA_SIZE, &size);
			glGetActiveUniformBlockiv(_program, location, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &count);

			if (count)
			{
				std::vector<GLint> indices(count);
				glGetActiveUniformBlockiv(_program, location, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, indices.data());

				std::vector<GLint> offset((std::size_t)count);
				std::vector<GLint> type((std::size_t)count);
				std::vector<GLint> datasize((std::size_t)count);
				std::vector<std::string> varlist((std::size_t)count);
				std::vector<GLchar> name(maxUniformLength);

				glGetActiveUniformsiv(_program, count, (GLuint*)&indices[0], GL_UNIFORM_OFFSET, &offset[0]);
				glGetActiveUniformsiv(_program, count, (GLuint*)&indices[0], GL_UNIFORM_TYPE, &type[0]);
				glGetActiveUniformsiv(_program, count, (GLuint*)&indices[0], GL_UNIFORM_SIZE, &datasize[0]);

				for (GLint j = 0; j < count; ++j)
				{
					GLsizei length = 0;
#if !defined(EGLAPI)
					glGetActiveUniformName(_program, indices[j], maxUniformLength, &length, name.data());
#else
					glGetActiveUniform(_program, indices[j], maxUniformLength, &length, &datasize[j], (GLenum*)&type[j], name.data());
#endif
					
					varlist[j].append(name.data(), length);
				}

				auto uniformblock = std::make_shared<ShaderUniform>();
				uniformblock->setName(nameUniformBlock.get());
				uniformblock->setType(ShaderVariantType::SPT_BUFFER);
				uniformblock->setLocation(location);

				_activeUniforms.push_back(uniformblock);
			}
		}
	}
}