コード例 #1
0
void ScanSystem::test()
{
  GLuint scanbuffers[3];
  glGenBuffers(3,scanbuffers);

  GLuint low  = ScanSystem::BATCH_ELEMENTS/2;
  GLuint mid  = ScanSystem::BATCH_ELEMENTS*ScanSystem::BATCH_ELEMENTS;
  GLuint high = ScanSystem::BATCH_ELEMENTS*ScanSystem::BATCH_ELEMENTS*2;
  size_t offsize = ScanSystem::getOffsetSize(high);

  GLuint* data = new GLuint[high];
  for (GLuint i = 0; i < high; i++){
    data[i] = 1;
  }

  glNamedBufferStorageEXT(scanbuffers[0], high * sizeof(GLuint), &data[0], 0 );
  glNamedBufferStorageEXT(scanbuffers[1], high * sizeof(GLuint),0, GL_MAP_READ_BIT );
  glNamedBufferStorageEXT(scanbuffers[2], offsize,0,GL_MAP_READ_BIT);

  delete [] data;

  GLuint result;
  bool needcombine;

  // low
  needcombine = scanData(low, scanbuffers[0], scanbuffers[1], scanbuffers[2]);
  assert(needcombine == false);
  result = 0;
  glGetNamedBufferSubDataEXT(scanbuffers[1],sizeof(GLuint) * (low-1), sizeof(GLuint), &result);
  assert(result == low);

  // med
  needcombine = scanData(mid, scanbuffers[0], scanbuffers[1], scanbuffers[2]);
  assert(needcombine == true);
  result = 0;
  glGetNamedBufferSubDataEXT(scanbuffers[2],sizeof(GLuint) * (ScanSystem::BATCH_ELEMENTS-1), sizeof(GLuint), &result);
  assert(result == mid);

  combineWithOffsets(mid, scanbuffers[1], scanbuffers[2]);
  result = 0;
  glGetNamedBufferSubDataEXT(scanbuffers[1],sizeof(GLuint) * (mid-1), sizeof(GLuint), &result);
  assert(result == mid);

  // high
  needcombine = scanData(high, scanbuffers[0], scanbuffers[1], scanbuffers[2]);
  assert(needcombine == true);
  combineWithOffsets(high, scanbuffers[1], scanbuffers[2]);
  result = 0;
  glGetNamedBufferSubDataEXT(scanbuffers[1],sizeof(GLuint) * (high-1), sizeof(GLuint), &result);
  assert(result == high);

  glDeleteBuffers(3,scanbuffers);
}
コード例 #2
0
ファイル: topaz.cpp プロジェクト: fetchhell/topaz
void TopazSample::initBuffer(GLenum target, GLuint& buffer, GLuint64& buffer64, 
	GLsizeiptr size, const GLvoid* data, bool ismutable)
{
	if (buffer)
	{
		glDeleteBuffers(1, &buffer);
	}
	glGenBuffers(1, &buffer);

	if (!ismutable)
	{
		glNamedBufferStorageEXT(buffer, size, data, 0);
	}
	else
	{
		glBindBuffer(target, buffer);
		glBufferData(target, size, data, GL_DYNAMIC_DRAW);
		glBindBuffer(target, 0);
	}

	if (bindlessVboUbo)
	{
		glGetNamedBufferParameterui64vNV(buffer, GL_BUFFER_GPU_ADDRESS_NV, &buffer64);
		glMakeNamedBufferResidentNV(buffer, GL_READ_ONLY);
	}
}
コード例 #3
0
ファイル: Buffer.cpp プロジェクト: voxelinc/glow
void Buffer::setStorage(GLsizeiptr size, const GLvoid * data, GLbitfield flags)
{
    if (m_directStateAccess)
    {
        glNamedBufferStorageEXT(m_id, size, data, flags);
        CheckGLError();
    }
    else
    {
        bind();
        glBufferStorage(m_target, size, data, flags);
        CheckGLError();
    }
}
void BufferImplementation_DirectStateAccessEXT::setStorage(const Buffer * buffer, GLsizeiptr size, const GLvoid * data, BufferStorageMask flags) const
{
    glNamedBufferStorageEXT(buffer->id(), size, data, flags);
}
コード例 #5
0
//------------------------------------------------------------------------------
// It is possible to create one VBO for one Mesh; and one EBO for each primitive group
// however, for this sample, we will create only one VBO for all and one EBO
// meshes and primitive groups will have an offset in these buffers
//------------------------------------------------------------------------------
bool Bk3dModelStandard::initResourcesObject()
{
    LOGFLUSH();
    SHOWPROGRESS("Init resources")

    //m_pGenericModel->m_meshFile->pMeshes->n = 60000;
    //
    // create Buffer Object for materials
    //
    if(m_pGenericModel->m_meshFile->pMaterials && m_pGenericModel->m_meshFile->pMaterials->nMaterials )
    {
        //
        // Material UBO: *TABLE* of multiple materials
        // Then offset in it for various drawcalls
        //
        if(m_uboMaterial.Id == 0)
            glGenBuffers(1, &m_uboMaterial.Id);

        m_uboMaterial.Sz = sizeof(MaterialBuffer) * m_pGenericModel->m_materialNItems;
        glNamedBufferDataEXT(m_uboMaterial.Id, m_uboMaterial.Sz, m_pGenericModel->m_material, GL_STATIC_DRAW);
        glBindBufferBase(GL_UNIFORM_BUFFER,UBO_MATERIAL, m_uboMaterial.Id);

        LOGI("%d materials stored in %d Kb\n", m_pGenericModel->m_meshFile->pMaterials->nMaterials, (m_uboMaterial.Sz+512)/1024);
        LOGFLUSH();
    }

    //
    // create Buffer Object for Object-matrices
    //
    if(m_pGenericModel->m_meshFile->pTransforms && m_pGenericModel->m_meshFile->pTransforms->nBones)
    {
        //
        // Transformation UBO: *TABLE* of multiple transformations
        // Then offset in it for various drawcalls
        //
        if(m_uboObjectMatrices.Id == 0)
            glGenBuffers(1, &m_uboObjectMatrices.Id);

        m_uboObjectMatrices.Sz = sizeof(MatrixBufferObject) * m_pGenericModel->m_objectMatricesNItems;
        glNamedBufferDataEXT(m_uboObjectMatrices.Id, m_uboObjectMatrices.Sz, m_pGenericModel->m_objectMatrices, GL_STATIC_DRAW);
        glBindBufferBase(GL_UNIFORM_BUFFER,UBO_MATRIXOBJ, m_uboObjectMatrices.Id);

        LOGI("%d matrices stored in %d Kb\n", m_pGenericModel->m_meshFile->pTransforms->nBones, (m_uboObjectMatrices.Sz + 512)/1024);
        LOGFLUSH();
    }

    //
    // First pass: evaluate the size of the single VBO
    // and store offset to where we'll find data back
    //
    bk3d::Mesh *pMesh = NULL;
    for(int i=0; i< m_pGenericModel->m_meshFile->pMeshes->n; i++)
	{
        SETPROGRESSVAL(100.0f*(float)i/(float)m_pGenericModel->m_meshFile->pMeshes->n);
		pMesh = m_pGenericModel->m_meshFile->pMeshes->p[i];
        //
        // Slots: buffers for vertices
        //
        int n = pMesh->pSlots->n;
        for(int s=0; s<n; s++)
        {
            bk3d::Slot* pS = pMesh->pSlots->p[s];
            GLuint id;
            glGenBuffers(1, &id); // Buffer Object directly kept in the Slot
            pS->userData = id;
            #if 1
                glNamedBufferDataEXT(id, pS->vtxBufferSizeBytes, NULL, GL_STATIC_DRAW);
            #else
                glNamedBufferStorageEXT(id, pS->vtxBufferSizeBytes, NULL, 0); // Not working with NSight !!! https://www.opengl.org/registry/specs/ARB/buffer_storage.txt
            #endif
            glNamedBufferSubDataEXT(id, 0, pS->vtxBufferSizeBytes, pS->pVtxBufferData);
        }
        //
        // Primitive groups
        //
        for(int pg=0; pg<pMesh->pPrimGroups->n; pg++)
        {
            bk3d::PrimGroup* pPG = pMesh->pPrimGroups->p[pg];
            if(pPG->indexArrayByteSize > 0)
            {
                if((pPG->pOwnerOfIB == pPG)||(pPG->pOwnerOfIB == NULL)) // this primitive group doesn't use other's buffer
                {
                    GLuint id;
                    glGenBuffers(1, &id);
                    pPG->userPtr = (int*)id;
                #if 1
                    glNamedBufferDataEXT(id, pPG->indexArrayByteSize, NULL, GL_STATIC_DRAW);
                #else
                    glNamedBufferStorageEXT(id, pPG->indexArrayByteSize, NULL, 0); // Not working with NSight !!! https://www.opengl.org/registry/specs/ARB/buffer_storage.txt
                #endif
                    glNamedBufferSubDataEXT(id, pPG->indexArrayByteOffset, pPG->indexArrayByteSize, pPG->pIndexBufferData);
                } else {
                    pPG->userPtr = pPG->pOwnerOfIB->userPtr;
                }
            } else {
                pPG->userPtr = NULL;
            }
        }
	}
    //LOGI("meshes: %d in :%d VBOs (%f Mb) and %d EBOs (%f Mb) \n", m_pGenericModel->m_meshFile->pMeshes->n, .size(), (float)totalVBOSz/(float)(1024*1024), m_ObjEBOs.size(), (float)totalEBOSz/(float)(1024*1024));
    LOGFLUSH();
    HIDEPROGRESS()
    return true;
}
コード例 #6
0
bool CadScene::loadCSF( const char* filename, int clones, int cloneaxis)
{
  CSFile* csf;
  CSFileMemoryPTR mem = CSFileMemory_new();
  if (CSFile_loadExt(&csf,filename,mem) != CADSCENEFILE_NOERROR || !(csf->fileFlags & CADSCENEFILE_FLAG_UNIQUENODES)){
    CSFileMemory_delete(mem);
    return false;
  }

  int copies = clones + 1;

  CSFile_transform(csf);

  srand(234525);

  // materials
  m_materials.resize( csf->numMaterials );
  for (int n = 0; n < csf->numMaterials; n++ )
  {
    CSFMaterial* csfmaterial = &csf->materials[n];
    Material& material = m_materials[n];

    for (int i = 0; i < 2; i++){
      material.sides[i].ambient = randomVector(0.0f,0.1f);
      material.sides[i].diffuse = nv_math::vec4f(csf->materials[n].color) + randomVector(0.0f,0.07f);
      material.sides[i].specular = randomVector(0.25f,0.55f);
      material.sides[i].emissive = randomVector(0.0f,0.05f);
    }

  }

  glGenBuffers(1,&m_materialsGL);
  glNamedBufferStorageEXT(m_materialsGL, sizeof(Material) * m_materials.size(), &m_materials[0], 0);
  //glMapNamedBufferRange(m_materialsGL, 0, sizeof(Material) * m_materials.size(), GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT);

  // geometry
  int numGeoms = csf->numGeometries;
  m_geometry.resize( csf->numGeometries * copies );
  m_geometryBboxes.resize( csf->numGeometries * copies );
  for (int n = 0; n < csf->numGeometries; n++ )
  {
    CSFGeometry* csfgeom = &csf->geometries[n];
    Geometry& geom = m_geometry[n];
    
    geom.cloneIdx = -1;

    geom.numVertices = csfgeom->numVertices;
    geom.numIndexSolid = csfgeom->numIndexSolid;
    geom.numIndexWire = csfgeom->numIndexWire;

    std::vector<Vertex>   vertices( csfgeom->numVertices );
    for (int i = 0; i < csfgeom->numVertices; i++){
      vertices[i].position[0] = csfgeom->vertex[3*i + 0];
      vertices[i].position[1] = csfgeom->vertex[3*i + 1];
      vertices[i].position[2] = csfgeom->vertex[3*i + 2];
      vertices[i].position[3] = 1.0f;
      if (csfgeom->normal){
        vertices[i].normal[0] = csfgeom->normal[3*i + 0];
        vertices[i].normal[1] = csfgeom->normal[3*i + 1];
        vertices[i].normal[2] = csfgeom->normal[3*i + 2];
        vertices[i].normal[3] = 0.0f;
      }
      else{
        vertices[i].normal = normalize(nv_math::vec3f(vertices[i].position));
      }
      
      
      m_geometryBboxes[n].merge( vertices[i].position );
    }

    geom.vboSize = sizeof(Vertex) * vertices.size();

    glGenBuffers(1,&geom.vboGL);
    glNamedBufferStorageEXT(geom.vboGL,geom.vboSize, &vertices[0], 0);

    std::vector<GLuint> indices(csfgeom->numIndexSolid + csfgeom->numIndexWire);
    memcpy(&indices[0],csfgeom->indexSolid, sizeof(GLuint) * csfgeom->numIndexSolid);
    if (csfgeom->indexWire){
      memcpy(&indices[csfgeom->numIndexSolid],csfgeom->indexWire, sizeof(GLuint) * csfgeom->numIndexWire);
    }

    geom.iboSize = sizeof(GLuint) * indices.size();

    glGenBuffers(1,&geom.iboGL);
    glNamedBufferStorageEXT(geom.iboGL, geom.iboSize, &indices[0], 0);

    if (GLEW_NV_vertex_buffer_unified_memory){
      glGetNamedBufferParameterui64vNV(geom.vboGL, GL_BUFFER_GPU_ADDRESS_NV, &geom.vboADDR);
      glMakeNamedBufferResidentNV(geom.vboGL, GL_READ_ONLY);

      glGetNamedBufferParameterui64vNV(geom.iboGL, GL_BUFFER_GPU_ADDRESS_NV, &geom.iboADDR);
      glMakeNamedBufferResidentNV(geom.iboGL, GL_READ_ONLY);
    }
    
    geom.parts.resize( csfgeom->numParts );
    
    size_t offsetSolid = 0;
    size_t offsetWire = csfgeom->numIndexSolid * sizeof(GLuint);
    for (int i = 0; i < csfgeom->numParts; i++){
      geom.parts[i].indexWire.count   = csfgeom->parts[i].indexWire;
      geom.parts[i].indexSolid.count  = csfgeom->parts[i].indexSolid;

      geom.parts[i].indexWire.offset  = offsetWire;
      geom.parts[i].indexSolid.offset = offsetSolid;

      offsetWire  += csfgeom->parts[i].indexWire  * sizeof(GLuint);
      offsetSolid += csfgeom->parts[i].indexSolid * sizeof(GLuint);
    }
  }
  for (int c = 1; c <= clones; c++){
    for (int n = 0; n < numGeoms; n++ )
    {
      m_geometryBboxes[n + numGeoms * c] = m_geometryBboxes[n];

      const Geometry& geomorig  = m_geometry[n];
      Geometry& geom = m_geometry[n + numGeoms * c];

      geom = geomorig;
      
    #if 1
      geom.cloneIdx = n;
    #else
      geom.cloneIdx = -1;
      glGenBuffers(1,&geom.vboGL);
      glNamedBufferStorageEXT(geom.vboGL,geom.vboSize, 0, 0);

      glGenBuffers(1,&geom.iboGL);
      glNamedBufferStorageEXT(geom.iboGL,geom.iboSize, 0, 0);
      
      if (GLEW_NV_vertex_buffer_unified_memory){
        glGetNamedBufferParameterui64vNV(geom.vboGL, GL_BUFFER_GPU_ADDRESS_NV, &geom.vboADDR);
        glMakeNamedBufferResidentNV(geom.vboGL, GL_READ_ONLY);

        glGetNamedBufferParameterui64vNV(geom.iboGL, GL_BUFFER_GPU_ADDRESS_NV, &geom.iboADDR);
        glMakeNamedBufferResidentNV(geom.iboGL, GL_READ_ONLY);
      }

      glNamedCopyBufferSubDataEXT(geomorig.vboGL, geom.vboGL, 0, 0, geom.vboSize);
      glNamedCopyBufferSubDataEXT(geomorig.iboGL, geom.iboGL, 0, 0, geom.iboSize);
    #endif
    }
  }


  glGenBuffers(1,&m_geometryBboxesGL);
  glNamedBufferStorageEXT(m_geometryBboxesGL,sizeof(BBox) * m_geometryBboxes.size(), &m_geometryBboxes[0], 0);
  glGenTextures(1, &m_geometryBboxesTexGL);
  glTextureBufferEXT(m_geometryBboxesTexGL, GL_TEXTURE_BUFFER, GL_RGBA32F, m_geometryBboxesGL);
  
  // nodes
  int numObjects  = 0;
  m_matrices.resize( csf->numNodes * copies );

  for (int n = 0; n < csf->numNodes; n++){
    CSFNode*    csfnode  = &csf->nodes[n];

    memcpy( m_matrices[n].objectMatrix.get_value(), csfnode->objectTM, sizeof(float)*16 );
    memcpy( m_matrices[n].worldMatrix.get_value(),  csfnode->worldTM,  sizeof(float)*16 );
    
    m_matrices[n].objectMatrixIT  = nv_math::transpose( nv_math::invert(m_matrices[n].objectMatrix) );
    m_matrices[n].worldMatrixIT   = nv_math::transpose( nv_math::invert(m_matrices[n].worldMatrix) );

    if (csfnode->geometryIDX < 0) continue;
    
    numObjects++;
  }


  // objects
  m_objects.resize( numObjects * copies );
  m_objectAssigns.resize( numObjects * copies );
  numObjects = 0;
  for (int n = 0; n < csf->numNodes; n++){
    CSFNode*    csfnode  = &csf->nodes[n];

    if (csfnode->geometryIDX < 0) continue;
    
    Object& object = m_objects[numObjects];

    object.matrixIndex = n;
    object.geometryIndex = csfnode->geometryIDX;

    m_objectAssigns[numObjects] = nv_math::vec2i( object.matrixIndex, object.geometryIndex );

    object.parts.resize( csfnode->numParts );
    for (int i = 0; i < csfnode->numParts; i++){
      object.parts[i].active = 1;
      object.parts[i].matrixIndex = csfnode->parts[i].nodeIDX < 0 ? object.matrixIndex : csfnode->parts[i].nodeIDX;
      object.parts[i].materialIndex = csfnode->parts[i].materialIDX;
    }

    BBox bbox = m_geometryBboxes[object.geometryIndex].transformed( m_matrices[n].worldMatrix );
    m_bbox.merge( bbox );

    updateObjectDrawCache(object);

    numObjects++;
  }

  // compute clone move delta based on m_bbox;

  nv_math::vec4f dim = m_bbox.max - m_bbox.min;

  int sq = 1;
  int numAxis = 0;
  for (int i = 0; i < 3; i++){
    numAxis += (cloneaxis & (1<<i)) ? 1 : 0;
  }

  assert(numAxis);

  switch (numAxis)
  {
  case 1:
    sq = copies;
    break;
  case 2:
    while (sq * sq < copies){
      sq++;
    }
    break;
  case 3:
    while (sq * sq * sq < copies){
      sq++;
    }
    break;
  }
  

  for (int c = 1; c <= clones; c++){
    int numNodes = csf->numNodes;

    nv_math::vec4f shift = dim * 1.05f;

    float u = 0;
    float v = 0;
    float w = 0;

    switch (numAxis)
    {
    case 1:
      u = float(c);
      break;
    case 2:
      u = float(c % sq);
      v = float(c / sq);
      break;
    case 3:
      u = float(c % sq);
      v = float((c / sq) % sq);
      w = float( c / (sq*sq));
      break;
    }

    float use = u;

    if (cloneaxis & (1<<0)){
      shift.x *= -use;
      if (numAxis > 1 ) use = v;
    }
    else {
      shift.x = 0;
    }

    if (cloneaxis & (1<<1)){
      shift.y *= use;
      if (numAxis > 2 )       use = w;
      else if (numAxis > 1 )  use = v;
    }
    else {
      shift.y = 0;
    }

    if (cloneaxis & (1<<2)){
      shift.z *= -use;
    }
    else {
      shift.z = 0;
    }

    shift.w = 0;

    // move all world matrices
    for (int n = 0; n < numNodes; n++ )
    {
      MatrixNode &node = m_matrices[n + numNodes * c];
      MatrixNode &nodeOrig = m_matrices[n];
      node = nodeOrig;
      node.worldMatrix.set_col(3,node.worldMatrix.col(3) + shift);
      node.worldMatrixIT   = nv_math::transpose( nv_math::invert(node.worldMatrix) );
    }

    {
      // patch object matrix of root
      MatrixNode &node = m_matrices[csf->rootIDX + numNodes * c];
      node.objectMatrix.set_col(3,node.objectMatrix.col(3) + shift);
      node.objectMatrixIT  = nv_math::transpose( nv_math::invert(node.objectMatrix) );
    }
    
    // clone objects
    for (int n = 0; n < numObjects; n++ )
    {
      const Object& objectorig  = m_objects[n];
      Object& object            = m_objects[ n + numObjects * c];
      
      object = objectorig;
      object.geometryIndex      += c * numGeoms;
      object.matrixIndex        += c * numNodes;
      for (size_t i = 0; i < object.parts.size(); i++){
        object.parts[i].matrixIndex += c * numNodes;
      }
      for (size_t i = 0; i < object.cacheSolid.state.size(); i++){
        object.cacheSolid.state[i].matrixIndex += c * numNodes;
      }
      for (size_t i = 0; i < object.cacheWire.state.size(); i++){
        object.cacheWire.state[i].matrixIndex += c * numNodes;
      }

      m_objectAssigns[n + numObjects * c] = nv_math::vec2i( object.matrixIndex, object.geometryIndex );
    }

  }

  glGenBuffers(1,&m_matricesGL);
  glNamedBufferStorageEXT(m_matricesGL, sizeof(MatrixNode) * m_matrices.size(), &m_matrices[0], 0);
  //glMapNamedBufferRange(m_matricesGL, 0, sizeof(MatrixNode) * m_matrices.size(), GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT);
  
  glGenTextures(1,&m_matricesTexGL);
  glTextureBufferEXT(m_matricesTexGL, GL_TEXTURE_BUFFER, GL_RGBA32F, m_matricesGL);

  glGenBuffers(1,&m_objectAssignsGL);
  glNamedBufferStorageEXT(m_objectAssignsGL,sizeof(nv_math::vec2i) * m_objectAssigns.size(), &m_objectAssigns[0], 0);

  if (GLEW_NV_vertex_buffer_unified_memory){
    glGetNamedBufferParameterui64vNV(m_materialsGL, GL_BUFFER_GPU_ADDRESS_NV, &m_materialsADDR);
    glMakeNamedBufferResidentNV(m_materialsGL, GL_READ_ONLY);

    glGetNamedBufferParameterui64vNV(m_matricesGL, GL_BUFFER_GPU_ADDRESS_NV, &m_matricesADDR);
    glMakeNamedBufferResidentNV(m_matricesGL, GL_READ_ONLY);

    if (GLEW_NV_bindless_texture){
      m_matricesTexGLADDR = glGetTextureHandleNV(m_matricesTexGL);
      glMakeTextureHandleResidentNV(m_matricesTexGLADDR);
    }
  }

  m_nodeTree.create(copies * csf->numNodes);
  for (int i = 0; i < copies; i++){
    int cloneoffset = (csf->numNodes) * i;
    int root = csf->rootIDX+cloneoffset;
    recursiveHierarchy(m_nodeTree,csf,csf->rootIDX,cloneoffset);

    m_nodeTree.setNodeParent( (NodeTree::nodeID)root, m_nodeTree.getTreeRoot() );
    m_nodeTree.addToTree( (NodeTree::nodeID)root );
  }

  glGenBuffers(1,&m_parentIDsGL);
  glNamedBufferStorageEXT(m_parentIDsGL, m_nodeTree.getTreeCompactNodes().size() * sizeof(GLuint), &m_nodeTree.getTreeCompactNodes()[0], 0);

  glGenBuffers(1,&m_matricesOrigGL);
  glNamedBufferStorageEXT(m_matricesOrigGL, sizeof(MatrixNode) * m_matrices.size(), &m_matrices[0], 0);
  glGenTextures(1,&m_matricesOrigTexGL);
  glTextureBufferEXT(m_matricesOrigTexGL, GL_TEXTURE_BUFFER, GL_RGBA32F, m_matricesOrigGL);
  
  CSFileMemory_delete(mem);
  return true;
}
コード例 #7
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengles_EXTBufferStorage_nglNamedBufferStorageEXT__IJJI(JNIEnv *__env, jclass clazz, jint buffer, jlong size, jlong dataAddress, jint flags) {
    glNamedBufferStorageEXTPROC glNamedBufferStorageEXT = (glNamedBufferStorageEXTPROC)tlsGetFunction(395);
    intptr_t data = (intptr_t)dataAddress;
    UNUSED_PARAM(clazz)
    glNamedBufferStorageEXT(buffer, (intptr_t)size, data, flags);
}
コード例 #8
0
ファイル: buffer.cpp プロジェクト: fabiopolimeni/experiments
buffer::buffer(std::size_t Size, const void* Data, std::uint32_t Flags)
{
    glGenBuffers(1, &this->Name);
    glNamedBufferStorageEXT(this->Name, static_cast<GLsizeiptr>(Size), Data, Flags);
}
コード例 #9
0
ファイル: topaz.cpp プロジェクト: fetchhell/topaz
void TopazSample::initCommandListWeightBlended()
{
	if (!isTokenInternalsInited)
	{
		hwsupport = init_NV_command_list(sysGetProcAddress) ? true : false;
		nvtokenInitInternals(hwsupport, bindlessVboUbo);

		isTokenInternalsInited = true;
	}

	enum States
	{
		STATE_CLEAR,
		STATE_OPAQUE,
		STATE_TRANSPARENT,
		STATE_TRASPARENT_LINES,
		STATE_COMPOSITE,
		STATES_COUNT
	};

	if (hwsupport)
	{
		for (size_t i = 0; i < STATES_COUNT; i++)
		{
			glCreateStatesNV(1, &cmdlist.stateObjectsWeightBlended[i]);
		}

		glGenBuffers(1, &cmdlist.tokenBufferWeightBlended);
		glCreateCommandListsNV(1, &cmdlist.tokenCmdListWeightBlended);
	}

	NVTokenSequence& seq = cmdlist.tokenSequenceWeightBlended;
	std::string& stream = cmdlist.tokenDataWeightBlended;
	size_t offset = 0;

	{
		NVTokenUbo  ubo;
		ubo.setBuffer(ubos.sceneUbo, ubos.sceneUbo64, 0, sizeof(SceneData));
		ubo.setBinding(UBO_SCENE, NVTOKEN_STAGE_VERTEX);
		nvtokenEnqueue(stream, ubo);
		ubo.setBinding(UBO_SCENE, NVTOKEN_STAGE_FRAGMENT);
		nvtokenEnqueue(stream, ubo);
	}

	// 1. render 'background' into framebuffer 'fbos.scene' 
	{
		auto& model = models.at(0);
		setTokenBuffers(model.get(), stream);

		NVTokenDrawElems  draw;
		draw.setParams(model->getModel()->getCompiledIndexCount(NvModelPrimType::TRIANGLES));
		draw.setMode(GL_TRIANGLES);
		nvtokenEnqueue(stream, draw);

		pushTokenParameters(seq, offset, stream, fbos.scene, cmdlist.stateObjectsWeightBlended[STATE_OPAQUE]);
	}

	// 2. geometry pass OIT 
	for (auto model = models.begin() + 1; model != models.end(); model++)
	{
		// like call glClearBufferfv
		{
			NVTokenVbo vbo;
			vbo.setBinding(0);
			vbo.setBuffer(fullScreenRectangle.vboFullScreen, fullScreenRectangle.vboFullScreen64, 0);
			nvtokenEnqueue(stream, vbo);

			NVTokenUbo ubo;
			ubo.setBuffer(ubos.identityUbo, ubos.identityUbo64, 0, sizeof(IdentityData));
			ubo.setBinding(UBO_IDENTITY, NVTOKEN_STAGE_VERTEX);
			nvtokenEnqueue(stream, ubo);

			NVTokenDrawArrays  draw;
			draw.setParams(4, 0);
			draw.setMode(GL_TRIANGLE_STRIP);
			nvtokenEnqueue(stream, draw);
		}
		pushTokenParameters(seq, offset, stream, oit->getFramebufferID(), cmdlist.stateObjectsWeightBlended[STATE_CLEAR]);

		// 2. geometry pass
		{
			setTokenBuffers((*model).get(), stream);

			NVTokenDrawElems  draw;
			draw.setParams((*model)->getModel()->getCompiledIndexCount(NvModelPrimType::TRIANGLES));
			draw.setMode(GL_TRIANGLES);
			nvtokenEnqueue(stream, draw);
		}
		pushTokenParameters(seq, offset, stream, oit->getFramebufferID(), cmdlist.stateObjectsWeightBlended[STATE_TRANSPARENT]);

		{
			setTokenBuffers((*model).get(), stream, true);

			NVTokenDrawElems  draw;
			draw.setParams((*model)->getCornerIndices().size());
			draw.setMode(GL_LINE_STRIP);
			nvtokenEnqueue(stream, draw);
		}
		pushTokenParameters(seq, offset, stream, oit->getFramebufferID(), cmdlist.stateObjectsWeightBlended[STATE_TRASPARENT_LINES]);

		// 3. composite pass
		{
			NVTokenVbo vbo;
			vbo.setBinding(0);
			vbo.setBuffer(fullScreenRectangle.vboFullScreen, fullScreenRectangle.vboFullScreen64, 0);
			nvtokenEnqueue(stream, vbo);

			NVTokenUbo ubo;
			ubo.setBuffer(ubos.identityUbo, ubos.identityUbo64, 0, sizeof(IdentityData));
			ubo.setBinding(UBO_IDENTITY, NVTOKEN_STAGE_VERTEX);
			nvtokenEnqueue(stream, ubo);

			NVTokenUbo uboWeightBlended;
			uboWeightBlended.setBuffer(ubos.weightBlendedUbo, ubos.weightBlendedUbo64, 0, sizeof(WeightBlendedData));
			uboWeightBlended.setBinding(UBO_OIT, NVTOKEN_STAGE_FRAGMENT);
			nvtokenEnqueue(stream, uboWeightBlended);

			NVTokenDrawArrays  draw;
			draw.setParams(4, 0);
			draw.setMode(GL_TRIANGLE_STRIP);
			nvtokenEnqueue(stream, draw);
		}
		pushTokenParameters(seq, offset, stream, fbos.scene, cmdlist.stateObjectsWeightBlended[STATE_COMPOSITE]);
	}
	
	if (hwsupport)
	{
		glNamedBufferStorageEXT(cmdlist.tokenBufferWeightBlended, cmdlist.tokenDataWeightBlended.size(), &cmdlist.tokenDataWeightBlended.at(0), 0);

		cmdlist.tokenSequenceListWeightBlended = cmdlist.tokenSequenceWeightBlended;
		for (size_t i = 0; i < cmdlist.tokenSequenceListWeightBlended.offsets.size(); i++)
		{
			cmdlist.tokenSequenceListWeightBlended.offsets[i] += (GLintptr)&cmdlist.tokenDataWeightBlended.at(0);
		}
	}
	
	glEnableVertexAttribArray(VERTEX_POS);
	glVertexAttribFormat(VERTEX_POS, 3, GL_FLOAT, GL_FALSE, 0);
	glVertexAttribBinding(VERTEX_POS, 0);

	glEnable(GL_DEPTH_TEST);

	// 1. opaque modes
	{
		glBindFramebuffer(GL_FRAMEBUFFER, fbos.scene);

		shaderPrograms["draw"]->enable();

		glBindVertexBuffer(0, 0, 0, 9 * sizeof(float));
		glStateCaptureNV(cmdlist.stateObjectsWeightBlended[STATE_OPAQUE], GL_TRIANGLES);
		
		shaderPrograms["draw"]->disable();

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	glDisable(GL_DEPTH_TEST);

	// like a glClearBufferfv
	{
		glBindFramebuffer(GL_FRAMEBUFFER, oit->getFramebufferID());

		const GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
		glDrawBuffers(2, drawBuffers);

		shaderPrograms["clear"]->enable();

		glBindVertexBuffer(0, 0, 0, sizeof(nv::vec3f));
		glStateCaptureNV(cmdlist.stateObjectsWeightBlended[STATE_CLEAR], GL_TRIANGLES);

		shaderPrograms["clear"]->disable();

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	// 2. oit first step
	{
		glBindFramebuffer(GL_FRAMEBUFFER, oit->getFramebufferID());

		// ???
		//glEnable(GL_POLYGON_STIPPLE);
		//glPolygonStipple(brushStyle->brushPattern8to32(QtStyles::DiagCrossPattern).data());

		const GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
		glDrawBuffers(2, drawBuffers);

		glEnable(GL_BLEND);
		glBlendEquation(GL_FUNC_ADD);
		glBlendFunci(0, GL_ONE, GL_ONE);
		glBlendFunci(1, GL_ZERO, GL_ONE_MINUS_SRC_COLOR);

		shaderPrograms["weightBlended"]->enable();

		glBindVertexBuffer(0, 0, 0, 9 * sizeof(float));
		glStateCaptureNV(cmdlist.stateObjectsWeightBlended[STATE_TRANSPARENT], GL_TRIANGLES);

		glBindVertexBuffer(0, 0, 0, sizeof(nv::vec3f));
		glStateCaptureNV(cmdlist.stateObjectsWeightBlended[STATE_TRASPARENT_LINES], GL_LINES);

		shaderPrograms["weightBlended"]->disable();

		// ???
		//glDisable(GL_POLYGON_STIPPLE);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	// 3. oit second step
	{
		glBindFramebuffer(GL_FRAMEBUFFER, fbos.scene);
		glDisable(GL_BLEND);

		shaderPrograms["weightBlendedFinal"]->enable();

		glBindVertexBuffer(0, 0, 0, sizeof(nv::vec3f));
		glStateCaptureNV(cmdlist.stateObjectsWeightBlended[STATE_COMPOSITE], GL_TRIANGLES);

		shaderPrograms["weightBlendedFinal"]->disable();
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	// compile command list
	NVTokenSequence& sequenceList = cmdlist.tokenSequenceListWeightBlended;
	glCommandListSegmentsNV(cmdlist.tokenCmdListWeightBlended, 1);
	glListDrawCommandsStatesClientNV(cmdlist.tokenCmdListWeightBlended, 0, (const void**)&sequenceList.offsets[0], &sequenceList.sizes[0], &sequenceList.states[0], &sequenceList.fbos[0], int(sequenceList.states.size()));
	glCompileCommandListNV(cmdlist.tokenCmdListWeightBlended);
}
コード例 #10
0
ファイル: topaz.cpp プロジェクト: fetchhell/topaz
void TopazSample::initCommandList()
{
	if (!isTokenInternalsInited)
	{
		hwsupport = init_NV_command_list(sysGetProcAddress) ? true : false;
		nvtokenInitInternals(hwsupport, bindlessVboUbo);

		isTokenInternalsInited = true;
	}

	enum States
	{
		STATE_DRAW,
		STATE_GEOMETRY_DRAW,
		STATE_LINES_DRAW,
		STATES_COUNT
	};
	
	if (hwsupport)
	{
		for (size_t i = 0; i < STATES_COUNT; i++)
		{
			glCreateStatesNV(1, &cmdlist.stateObjects[i]);
		}

		glGenBuffers(1, &cmdlist.tokenBuffer);
		glCreateCommandListsNV(1, &cmdlist.tokenCmdList);
	}

	NVTokenSequence& seq = cmdlist.tokenSequence;
	std::string& stream = cmdlist.tokenData;
	size_t offset = 0;

	{
		NVTokenUbo  ubo;
		ubo.setBuffer(ubos.sceneUbo, ubos.sceneUbo64, 0, sizeof(SceneData));
		ubo.setBinding(UBO_SCENE, NVTOKEN_STAGE_VERTEX);
		nvtokenEnqueue(stream, ubo);
		ubo.setBinding(UBO_SCENE, NVTOKEN_STAGE_FRAGMENT);
		nvtokenEnqueue(stream, ubo);
	}
	
	for (auto & model : models)
	{
		setTokenBuffers(model.get(), stream);

		NVTokenDrawElems  draw;
		draw.setParams(model->getModel()->getCompiledIndexCount(NvModelPrimType::TRIANGLES));
		draw.setMode(GL_TRIANGLES);
		nvtokenEnqueue(stream, draw);
	}
	pushTokenParameters(seq, offset, stream, fbos.scene, cmdlist.stateObjects[STATE_DRAW]);
	
	for (auto & model : models)
	{
		if (model->cornerPointsExists())
		{
			setTokenBuffers(model.get(), stream, true);

			NVTokenDrawElems drawCorner;
			drawCorner.setParams(model->getCornerIndices().size());
			drawCorner.setMode(GL_LINE_STRIP);
			nvtokenEnqueue(stream, drawCorner);
		}
	}
	pushTokenParameters(seq, offset, stream, fbos.scene, cmdlist.stateObjects[STATE_LINES_DRAW]);

	if (hwsupport)
	{
		glNamedBufferStorageEXT(cmdlist.tokenBuffer, cmdlist.tokenData.size(), &cmdlist.tokenData.at(0), 0);

		cmdlist.tokenSequenceList = cmdlist.tokenSequence;
		for (size_t i = 0; i < cmdlist.tokenSequenceList.offsets.size(); i++)
		{
			cmdlist.tokenSequenceList.offsets[i] += (GLintptr) &cmdlist.tokenData.at(0);
		}
	}

	updateCommandListState();
}
コード例 #11
0
    void init()
    {
        vf::skinned_geom_t::vao    = createVAO(ARRAY_SIZE(vf::descSkinnedGeom),  vf::descSkinnedGeom,  0, NULL);
        vf::static_geom_t::vao     = createVAO(ARRAY_SIZE(vf::descStaticGeom),   vf::descStaticGeom,   0, NULL);
        vf::p2_vertex_t::vao       = createVAO(ARRAY_SIZE(vf::fmtdesc_p2),       vf::fmtdesc_p2,       0, NULL);
        vf::p2uv2_vertex_t::vao    = createVAO(ARRAY_SIZE(vf::fmtdesc_p2uv2),    vf::fmtdesc_p2uv2,    0, NULL);
        vf::p2uv3_vertex_t::vao    = createVAO(ARRAY_SIZE(vf::fmtdesc_p2uv3),    vf::fmtdesc_p2uv3,    0, NULL);
        vf::p2cu4_vertex_t::vao    = createVAO(ARRAY_SIZE(vf::fmtdesc_p2cu4),    vf::fmtdesc_p2cu4,    0, NULL);
        vf::p2uv2cu4_vertex_t::vao = createVAO(ARRAY_SIZE(vf::fmtdesc_p2uv2cu4), vf::fmtdesc_p2uv2cu4, 0, NULL);
        vf::p3_vertex_t::vao       = createVAO(ARRAY_SIZE(vf::fmtdesc_p3),       vf::fmtdesc_p3,       0, NULL);
        vf::p3cu4_vertex_t::vao    = createVAO(ARRAY_SIZE(vf::fmtdesc_p3cu4),    vf::fmtdesc_p3cu4,    0, NULL);
        vf::p3uv2cu4_vertex_t::vao = createVAO(ARRAY_SIZE(vf::fmtdesc_p3uv2cu4), vf::fmtdesc_p3uv2cu4, 0, NULL);
        glGenVertexArrays(1, &vf::empty_geom_t::vao);

        prgUI               = res::createProgramFromFiles("UI.vert",         "UI.frag");
        prgRasterCubic      = res::createProgramFromFiles("VG.Cubic.vert",   "VG.Mask.Cubic.frag");
        prgRasterCubicAA    = res::createProgramFromFiles("VG.Cubic.vert",   "VG.Mask.Cubic.AA.frag");
        prgPaintSolid       = res::createProgramFromFiles("VG.Paint.vert",   "VG.Paint.Solid.frag");
        prgPaintLinGradient = res::createProgramFromFiles("VG.Paint.vert",   "VG.Paint.LinearGradient.frag");

        const char* version       = "#version 430\n\n";
        const char* enableColor   = "#define ENABLE_COLOR\n";
        const char* enableTexture = "#define ENABLE_TEXTURE\n";
        const char* enableVGAA    = "#define EDGE_AA 1\n";

        const char* headers[3] = {version};
        size_t numHeaders;

        for (size_t i=0; i<STD_PROGRAM_COUNT; ++i)
        {
            numHeaders = 1;
            if (i&gfx::STD_FEATURE_COLOR)
            {
                headers[numHeaders++] = enableColor;
            }
            if (i&gfx::STD_FEATURE_TEXTURE)
            {
                headers[numHeaders++] = enableTexture;
            }
            stdPrograms[i] = res::createProgramFromFiles("MESH.std.vert", "MESH.std.frag", numHeaders, headers);
        }
        
        headers[1] = enableColor;
        prgLine  = res::createProgramFromFiles("MESH.Line.vert",  "MESH.std.frag", 2, headers);
        prgPoint = res::createProgramFromFiles("MESH.Point.vert", "MESH.std.frag", 2, headers);
        prgRect  = res::createProgramFromFiles("MESH.Rect.vert",  "MESH.std.frag", 2, headers);

        headers[1] = enableVGAA;
        prgNanoVG   = res::createProgramFromFiles("NanoVG.vert",  "NanoVG.frag", 1, headers);
        prgNanoVGAA = res::createProgramFromFiles("NanoVG.vert",  "NanoVG.frag", 2, headers);

        gfx::vertex_element_t ve[2] = {
            {0, 0, 0, GL_FLOAT,         4, GL_FALSE, GL_FALSE},
            {1, 0, 1, GL_UNSIGNED_BYTE, 4, GL_FALSE, GL_TRUE },
        };

        GLuint divs[2] = {1, 1};

        vaoRect = gfx::createVAO(2, ve, 2, divs);

        vgGArena = etlsf_create(VG_BUFFER_SIZE, GFX_MAX_ALLOCS);
        glGenBuffers(1, &buffer);
        glNamedBufferStorageEXT(buffer, VG_BUFFER_SIZE, 0, GL_MAP_WRITE_BIT);

        vg::defaultFont = vg::createFont(anonymousProBTTF, sizeof(anonymousProBTTF), 16);
        vg::nvgDefFont  = nvgCreateFontMem(vg::ctx, "default", anonymousProBTTF, sizeof(anonymousProBTTF), 0);
    }
コード例 #12
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBBufferStorage_nglNamedBufferStorageEXT(JNIEnv *env, jclass clazz, jint buffer, jlong size, jlong data, jint flags, jlong function_pointer) {
	const GLvoid *data_address = (const GLvoid *)(intptr_t)data;
	glNamedBufferStorageEXTPROC glNamedBufferStorageEXT = (glNamedBufferStorageEXTPROC)((intptr_t)function_pointer);
	glNamedBufferStorageEXT(buffer, size, data_address, flags);
}