Beispiel #1
0
 //------------------------------------------------------------------------------
 void GLMesh::Bind(GLShader* glShader) noexcept
 {
     auto vertexFormat = m_renderMesh->GetVertexFormat();
     
     //TODO: This should be pre-calculated.
     GLint maxVertexAttributes = 0;
     glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttributes);
     CS_ASSERT(u32(maxVertexAttributes) >= vertexFormat.GetNumElements(), "Too many vertex elements.");
     
     glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferHandle);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferHandle);
     
     CS_ASSERT_NOGLERROR("An OpenGL error occurred while binding GLMesh.");
     
     for (u32 i = 0; i < vertexFormat.GetNumElements(); ++i)
     {
         glEnableVertexAttribArray(i);
         
         auto elementType = vertexFormat.GetElement(i);
         auto name = GLMeshUtils::GetAttributeName(elementType);
         auto numComponents = ChilliSource::VertexFormat::GetNumComponents(elementType);
         auto type = GLMeshUtils::GetGLType(ChilliSource::VertexFormat::GetDataType(elementType));
         auto normalised = GLMeshUtils::IsNormalised(elementType);
         auto offset = reinterpret_cast<const GLvoid*>(u64(vertexFormat.GetElementOffset(i)));
         
         glShader->SetAttribute(name, numComponents, type, normalised, vertexFormat.GetSize(), offset);
     }
     
     for (s32 i = vertexFormat.GetNumElements(); i < maxVertexAttributes; ++i)
     {
         glDisableVertexAttribArray(i);
     }
 }
Beispiel #2
0
//appends an element onto the end of the element list
bool CLTANode::AppendElement(CLTANode* pElement, ILTAAllocator* pAllocator)
{
	ASSERT(pAllocator);
	ASSERT(IsList());
	
	//resize the array
	CLTANode** pNewBuffer = (CLTANode**)pAllocator->AllocateBlock(sizeof(CLTANode*) * (GetNumElements() + 1));

	//make sure it worked
	if(pNewBuffer == NULL)
	{
		return false;
	}

	//copy over the old data
	memcpy(pNewBuffer, m_pData, sizeof(CLTANode*) * GetNumElements());

	//add the new element onto the end
	pNewBuffer[GetNumElements()] = pElement;

	//delete the old buffer
	pAllocator->FreeBlock(m_pData);

	//and set up the new buffer
	m_pData = pNewBuffer;
	m_nFlags++;

	return true;
}
Beispiel #3
0
void BufferObject::SizeBufferObject()
{
	ASSERT(IsClientSideBuffer() == false);
	ASSERT(GetNumElements() > 0);
	ASSERT(GetElementWidthInBytes() > 0);

	GLenum usage = 0;
	if (m_usage == BUFFEROBJECT_USAGE_STATIC)
		usage = GL_STATIC_DRAW;
	else if (m_usage == BUFFEROBJECT_USAGE_STREAM)
		usage = GL_STREAM_DRAW;
	else if (m_usage == BUFFEROBJECT_USAGE_DYNAMIC)
		usage = GL_DYNAMIC_DRAW;
	ASSERT(usage != 0);

	GLenum target = 0;
	if (m_type == BUFFEROBJECT_TYPE_INDEX)
		target = GL_ELEMENT_ARRAY_BUFFER;
	else if (m_type == BUFFEROBJECT_TYPE_VERTEX)
		target = GL_ARRAY_BUFFER;
	ASSERT(target != 0);

	m_sizeInBytes = GetNumElements() * GetElementWidthInBytes();

	// resize the buffer object without initializing it's data
	GL_CALL(glBindBuffer(target, m_bufferId));
	GL_CALL(glBufferData(target, m_sizeInBytes, NULL, usage));
	GL_CALL(glBindBuffer(target, 0));

	m_isDirty = true;
}
Beispiel #4
0
int SendProp::GetNumArrayLengthBits() const
{
    Assert( GetType() == DPT_Array );
#if _X360
    int elemCount = GetNumElements();
    if ( !elemCount )
        return 1;
    return (32 - _CountLeadingZeros(GetNumElements()));
#else
    return Q_log2( GetNumElements() ) + 1;
#endif
}
Beispiel #5
0
void BufferObject::Update()
{
	ASSERT(IsClientSideBuffer() == false);
	ASSERT(IsDirty() == true);
	ASSERT(GetNumElements() > 0);
	ASSERT(GetElementWidthInBytes() > 0);

	size_t currentSizeInBytes = GetNumElements() * GetElementWidthInBytes();

	GLenum usage = 0;
	if (m_usage == BUFFEROBJECT_USAGE_STATIC)
		usage = GL_STATIC_DRAW;
	else if (m_usage == BUFFEROBJECT_USAGE_STREAM)
		usage = GL_STREAM_DRAW;
	else if (m_usage == BUFFEROBJECT_USAGE_DYNAMIC)
		usage = GL_DYNAMIC_DRAW;
	ASSERT(usage != 0);

	GLenum target = 0;
	if (m_type == BUFFEROBJECT_TYPE_INDEX)
		target = GL_ELEMENT_ARRAY_BUFFER;
	else if (m_type == BUFFEROBJECT_TYPE_VERTEX)
		target = GL_ARRAY_BUFFER;
	ASSERT(target != 0);

	GL_CALL(glBindBuffer(target, m_bufferId));

	if (m_sizeInBytes != currentSizeInBytes)
	{
		// means that the buffer object hasn't been allocated. So let's allocate and update at the same time
		// figure out the size...
		m_sizeInBytes = currentSizeInBytes;

		// and then allocate + update
		GL_CALL(glBufferData(target, m_sizeInBytes, GetBuffer(), usage));
	}
	else
	{
		// possible performance enhancement? passing a NULL pointer to
		// glBufferData tells the driver that we don't care about the buffer's
		// previous contents allowing it to do some extra optimizations which is
		// fine since our glBufferSubData call is going to completely replace 
		// the contents anyway
		GL_CALL(glBufferData(target, m_sizeInBytes, NULL, usage));

		GL_CALL(glBufferSubData(target, 0, m_sizeInBytes, GetBuffer()));
	}

	GL_CALL(glBindBuffer(target, 0));

	m_isDirty = false;
}
Beispiel #6
0
void VertexBuffer::Copy(const VertexBuffer *source, uint destIndex)
{
	ASSERT(source != NULL);
	ASSERT(source->GetNumElements() > 0);
	ASSERT(source->GetStandardAttribs() == m_standardTypeAttribs);
	ASSERT(destIndex >= 0);
	ASSERT(destIndex + source->GetNumElements() <= GetNumElements());

	uint destOffset = GetVertexPosition(destIndex);
	memcpy(&m_buffer[destOffset], source->GetBuffer(), GetNumElements() * GetElementWidthInBytes());

	SetDirty();
}
Beispiel #7
0
bool
OsdCpuGLVertexBuffer::allocate() {
    _cpuBuffer = new real[GetNumElements() * GetNumVertices()];
    _dataDirty = true;
    int size = GetNumElements() * GetNumVertices() * sizeof(real);

    glGenBuffers(1, &_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    return true;
}
bool
OsdCpuGLVertexBuffer::allocate() {
    _cpuBuffer = new float[GetNumElements() * GetNumVertices()];
    _dataDirty = true;
    int size = GetNumElements() * GetNumVertices() * sizeof(float);

    glGenBuffers(1, &_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    if (glGetError() == GL_NO_ERROR) return true;
    return false;
}
float Pulse::ComputeHR(int edges[]){
  //count the number of edges first
  int numEdges = GetNumElements(edges);
  Serial.print("Number of edges = ");
  Serial.println(numEdges);
  
  for(int i = 1; i < numEdges; i++){
     float diff = (edges[i] - edges[i - 1])*sampleRate; //in ms
     float diffmin = diff/1000/60; //in min
     float HR = 1/diffmin;
     HeartRates[i - 1] = HR;
     Serial.print("HR: ");
     Serial.println(HR);
  }
  
  int numHR = numEdges - 1; // number of HR calculated will be one less than #rising edge 
  float total = 0;
  for(int i = 0; i < numHR; i++){
    total = total + HeartRates[i];
  }
  
  avgHR = total/numHR;
  Serial.print("Avg HR: ");
  Serial.println(avgHR);
  
  return avgHR;
}
float Pulse::ComputePTT(){
  int numEdges = GetNumElements(RisingEdges);
  int numEdges2 = GetNumElements(RisingEdges2);
  int numEdge = min(numEdges,numEdges2);
  Serial.print("Number of edges for PTT = ");
  Serial.println(numEdge);
  
  float total = 0;
  for(int i = 0; i < numEdge; i++){
    float ptt = abs(RisingEdges[i] - RisingEdges2[i]);
    total = total + ptt;
  }
  avgPTT = total/numEdge;
  Serial.print("Average PTT = ");
  Serial.println(avgPTT);
}
void
OsdD3D11VertexBuffer::UpdateData(const float *src, int startVertex, int numVertices,
                                 void *param) {

    ID3D11DeviceContext * pd3dDeviceContext =
        static_cast<ID3D11DeviceContext*>(param);
    assert(pd3dDeviceContext);

    D3D11_MAPPED_SUBRESOURCE resource;
    HRESULT hr = pd3dDeviceContext->Map(_uploadBuffer, 0,
                                        D3D11_MAP_WRITE_DISCARD, 0, &resource);

    if (FAILED(hr)) {
        OsdError(OSD_D3D11_BUFFER_MAP_ERROR, "Failed to map buffer\n");
        return;
    }

    int size = GetNumElements() * numVertices * sizeof(float);

    memcpy((float*)resource.pData + startVertex * _numElements, src, size);

    pd3dDeviceContext->Unmap(_uploadBuffer, 0);

    D3D11_BOX srcBox = { 0, 0, 0, size, 1, 1 };
    pd3dDeviceContext->CopySubresourceRegion(_buffer, 0, 0, 0, 0,
                                             _uploadBuffer, 0, &srcBox);
}
Beispiel #12
0
 size_t NDMask::MaskedCount() const
 {
     auto maskMatrix = GetMatrix();
     std::unique_ptr<char[]> maskData(maskMatrix->CopyToArray());
     return std::count_if(maskData.get(), maskData.get() + maskMatrix->GetNumElements(), [](const char& val) {
         return val == 0;
     });
 }
Beispiel #13
0
GLuint
OsdCpuGLVertexBuffer::BindVBO() {
    if (not _dataDirty)
        return _vbo;

    int size = GetNumElements() * GetNumVertices() * sizeof(float);

    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    glBufferData(GL_ARRAY_BUFFER, size, _cpuBuffer, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    _dataDirty = false;
    return _vbo;
}
void SourceList2D::SetSources2D(int ii) {
    for(unsigned int i=0;i<GetNumElements();i++) {
        GetElement(i)->SetSource2D(ii);
    }
  return;
}
Beispiel #15
0
void
OsdCpuGLVertexBuffer::UpdateData(const float *src, int startVertex, int numVertices) {

    memcpy(_cpuBuffer + startVertex * GetNumElements(), src, GetNumElements() * numVertices * sizeof(float));
    _dataDirty = true;
}
Beispiel #16
0
int SendProp::GetNumArrayLengthBits() const
{
	Assert( GetType() == DPT_Array );
	return Q_log2( GetNumElements() ) + 1;
}
void
OsdCpuGLVertexBuffer::UpdateData(const float *src, int numVertices) {

    map();
    memcpy(_cpuBuffer, src, GetNumElements() * numVertices * sizeof(float));
}
Beispiel #18
0
void VertexBuffer::Extend(uint amount)
{
	uint newSize = GetNumElements() + amount;
	Resize(newSize);
}
void
OsdCpuVertexBuffer::UpdateData(const float *src, int startVertex, int numVertices) {

    memcpy(_cpuBuffer + startVertex * _numElements,
           src, GetNumElements() * numVertices * sizeof(float));
}
//--------------------------------------------------------------------------------------
// GPU Bitonic Sort
//--------------------------------------------------------------------------------------
void BitonicSort::GPUSort( ID3D11DeviceContext* pContext )
{
	int cbData [] = { 0,0,0,0 };

	m_usNumbersToOrder2->GetUAV()->SetId( m_usNumbersToOrder1->GetUAV()->GetId() );
	m_usNumbersToOrder1->GetSRV()->SetId( m_usNumbersToOrder2->GetSRV()->GetId() );

    // Sort the data
    // First sort the rows for the levels <= to the block size
    for( unsigned int level = 2 ; level <= GetBlockSize() ; level = level * 2 )
    {
		//SetConstants( level, level, m_pBitonicSort-GetMatrixHeight(), GetMatrixWidth() );
		cbData[0] = level; /* level */
		cbData[1] = level; /* level mask */
		cbData[2] = GetMatrixHeight(); /* width */
		cbData[3] = GetMatrixWidth(); /* height */
		m_cbBitonicSort->UpdateCB<cbBitonicSort, int>( cbData, pContext );

        // Sort the row data
		pContext->CSSetUnorderedAccessViews( m_usNumbersToOrder1->GetUAV()->GetId(), 1, m_usNumbersToOrder1->GetUAV()->GetPtrView(), NULL );
		m_csBitonicSort->SetDimensiones( GetNumElements() / GetBlockSize(), 1, 1 );
		m_csBitonicSort->Dispatch( pContext );
    }
    
    // Then sort the rows and columns for the levels > than the block size
    // Transpose. Sort the Columns. Transpose. Sort the Rows.
    for( unsigned int level = (GetBlockSize() * 2) ; level <= GetNumElements() ; level = level * 2 )
    {
        //SetConstants( (level / m_pBitonicSort-GetBlockSize()), (level & ~GetNumElements()) / m_pBitonicSort-GetBlockSize(), GetMatrixWidth(), m_pBitonicSort-GetMatrixHeight() );
		cbData[0] = (level / GetBlockSize()); /* level */
		cbData[1] = (level & ~GetNumElements()) / GetBlockSize(); /* level mask */
		cbData[2] = GetMatrixWidth(); /* width */
		cbData[3] = GetMatrixHeight(); /* height */
		m_cbBitonicSort->UpdateCB<cbBitonicSort, int>( cbData, pContext );

        // Transpose the data from buffer 1 into buffer 2
		m_usNumbersToOrder2->SetUAVs( pContext );
		m_usNumbersToOrder1->SetShaderResources( pContext );
		m_csTranspose->SetDimensiones(GetMatrixWidth() / GetTransposeBlockSize(), GetMatrixHeight() / GetTransposeBlockSize(), 1);
		m_csTranspose->Dispatch( pContext );

        // Sort the transposed column data
		m_csBitonicSort->SetDimensiones( GetNumElements() / GetBlockSize(), 1, 1 );
		m_csBitonicSort->Dispatch( pContext );

		cbData[0] = GetBlockSize(); /* level */
		cbData[1] = level; /* level mask */
		cbData[2] = GetMatrixHeight(); /* width */
		cbData[3] = GetMatrixWidth(); /* height */
		m_cbBitonicSort->UpdateCB<cbBitonicSort, int>( cbData, pContext );

        // Transpose the data from buffer 2 back into buffer 1
		m_usNumbersToOrder1->SetUAVs( pContext );
		m_usNumbersToOrder2->SetShaderResources( pContext );
		m_csTranspose->SetDimensiones( GetMatrixHeight() / GetTransposeBlockSize(), GetMatrixWidth() / GetTransposeBlockSize(), 1);
		m_csTranspose->Dispatch( pContext );

        // Sort the row data
        m_csBitonicSort->SetDimensiones( GetNumElements() / GetBlockSize(), 1, 1 );
		m_csBitonicSort->Dispatch( pContext );
    }
}
void SourceList2D::ClearSources2D() {
    for(unsigned int i=0;i<GetNumElements();i++) {
        GetElement(i)->ClearSource2D();
    }
  return;
}