Beispiel #1
0
/** Called from test harness/main */
void
PerfInit(void)
{
   const GLenum filter = GL_LINEAR;
   GLenum stat;
   int i;

   if (!PerfExtensionSupported("GL_EXT_framebuffer_object")) {
      perf_printf("fboswitch: GL_EXT_framebuffer_object not supported\n");
      exit(0);
   }

   /* setup VBO */
   glGenBuffersARB(1, &VBO);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
   glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertices),
                   vertices, GL_STATIC_DRAW_ARB);

   glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(x));
   glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(s));
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);

   glGenFramebuffersEXT(2, FBO);
   glGenTextures(2, Tex);

   for (i = 0; i < 2; i++) {
      /* setup texture */
      glBindTexture(GL_TEXTURE_2D, Tex[i]);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
                   TexSize, TexSize, 0,
                   GL_RGBA, GL_UNSIGNED_BYTE, NULL);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);

      
      /* setup fbo */
      glBindFramebufferEXT(GL_FRAMEBUFFER, FBO[i]);
      glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                                GL_COLOR_ATTACHMENT0_EXT,
                                GL_TEXTURE_2D, Tex[i], 0/*level*/);
      stat = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
      if (stat != GL_FRAMEBUFFER_COMPLETE_EXT) {
         perf_printf("fboswitch: Error: incomplete FBO!\n");
         exit(1);
      }

      /* clear the FBO */
      glClear(GL_COLOR_BUFFER_BIT);
   }

   glEnable(GL_TEXTURE_2D);
}
Beispiel #2
0
void View::initScenePbo()
{
    // Iterate through all of the objects
    for( vector<SceneObject *>::iterator it = m_objects.begin(); it != m_objects.end(); it++ )
    {
        int bufferSize = (*it)->m_bumpResolution * (*it)->m_bumpResolution * sizeof(BGRA);
        GLuint* ids = (*it)->m_pbo;
        //generate two buffers to alternate between during updating for performance (halting)
        glGenBuffersARB(2, ids);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ids[m_pboIndexA]);
        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufferSize, 0, GL_STREAM_DRAW_ARB);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ids[m_pboIndexB]);
        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufferSize, 0, GL_STREAM_DRAW_ARB);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
        // Tell the scene object its pbo buffer
        (*it)->setPboBuffers(ids);

    }
}
Beispiel #3
0
static GLuint init_ibo(int n, const GLushort *data)
{
    GLuint ibo;
    GLsizei N = n * (n + 1) * 2 * sizeof (GLushort);

    glGenBuffersARB(1, &ibo);
    glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ibo);
    glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, N, data, GL_STATIC_DRAW_ARB);

    opengl_check("init_ibo");
    return ibo;
}
Beispiel #4
0
static GLuint init_vbo(int n, const struct vertex *data)
{
    GLuint vbo;
    GLsizei N = (n + 1) * (n + 1) * sizeof (struct vertex);

    glGenBuffersARB(1, &vbo);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, N, data, GL_STATIC_DRAW_ARB);

    opengl_check("init_vbo");
    return vbo;
}
Beispiel #5
0
void
piglit_init(int argc, char **argv)
{
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	piglit_require_extension("GL_ARB_vertex_buffer_object");

	glGenBuffersARB(1, &vbo);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 12 * sizeof(GLfloat),
			NULL, GL_DYNAMIC_DRAW);
}
Beispiel #6
0
	void meshVBO::load( vboType t, unsigned int sz, void* data )
	{
		type = vboEnumToType( t );
		size = sz;

		glGenBuffersARB( 1, &vboID );
		glBindBufferARB( type, vboID );
		glBufferDataARB( type, sz, data, GL_STATIC_DRAW );
		glBindBufferARB( type, 0 );

		assert( glGetError() == GL_NO_ERROR );
	}
Beispiel #7
0
    void DiGLIndexBuffer::WriteData(uint32 offset, uint32 length, const void* pSource, bool discardWholeBuffer /*= false*/)
    {
        glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mBufferId);

        if (offset == 0 && length == mBufferSize)
        {
            glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mBufferSize, pSource,
                DiGLTypeMappings::GetGLUsage(mResUsage));
        }
        else
        {
            if (discardWholeBuffer)
            {
                glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mBufferSize, NULL,
                    DiGLTypeMappings::GetGLUsage(mResUsage));
            }

            // Now update the real buffer
            glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, pSource);
        }
    }
Beispiel #8
0
	void Flush(uint& buffer, int& vtxs) {

		//上次才知道原来Flush还有冲厕所的意思QAQ
		//OpenGL有个函数glFlush(),翻译过来就是GL冲厕所() ←_←

		vtxs = Vertexes;

		if (EnableShaders) {
			for (int i = 0; i != shadercount; i++) {
				glUseProgramObjectARB(shaderPrograms[i]);
			}
		}

		if (Vertexes > 0) {

			glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer);

			if (Textured) {
				if (Colored)
					glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertexes * 8 * sizeof(float), VertexArray.data(), GL_STATIC_DRAW);
				else
					glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertexes * 5 * sizeof(float), VertexArray.data(), GL_STATIC_DRAW);
			}
			else {
				if (Colored)
					glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertexes * 6 * sizeof(float), VertexArray.data(), GL_STATIC_DRAW);
				else
					glBufferDataARB(GL_ARRAY_BUFFER_ARB, Vertexes * 3 * sizeof(float), VertexArray.data(), GL_STATIC_DRAW);
			}

			glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

			//重置
			Init();

		}

		if (EnableShaders) glUseProgramObjectARB(0);

	}
Beispiel #9
0
/* Create a vertex buffer object (VBO) to store data in video memory. */
uint ModelGL::createVBO (const void* data, int dataSize, uint target, uint usage) {
  uint id = 0;
  glGenBuffersARB (1, &id);  // Create a vertex buffer object.
  if (id == 0) {             // Check for success.
    printf ("[ERROR] VBO could not be created!\n");
    return 0;
  }
  
  // Select new VBO, update data to video card and return ID.
  glBindBufferARB (target, id);                    
  glBufferDataARB (target, dataSize, data, usage);
  return id;
}
void
CheckRender::allocateMemory( unsigned int width, unsigned int height, unsigned int bpp, bool bUsePBO)
{
    // Create the PBO for readbacks
    if (bUsePBO) {
        glGenBuffersARB(1, &m_pboReadback);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, m_pboReadback);
        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width*height*bpp, NULL, GL_STREAM_READ);
        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
    }

    m_pImageData = (unsigned char *)malloc(width*height*bpp);  // This is the image data stored in system memory
}
Beispiel #11
0
void Patch::VBOUploadVertices()
{
	if (renderMode == VBO) {
		// Upload vertexBuffer
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBuffer);
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertices.size() * sizeof(float), &vertices[0], GL_STATIC_DRAW_ARB);
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

		vboVerticesUploaded = true;
	} else {
		vboVerticesUploaded = false;
	}
}
Beispiel #12
0
	void	VertexBuffer::writeData(uint offset,uint length,const void* pSource,bool discardWholeBuffer)
	{
        glBindBufferARB(GL_ARRAY_BUFFER,m_ui32BufferID);

		if(discardWholeBuffer)
		{
			glBufferDataARB(GL_ARRAY_BUFFER,m_ui32VertexSize * m_ui32NumVertices,0,BufferManager::getGLUsage(m_Usage));
		}

		// Now update the real buffer
		glBufferSubDataARB(GL_ARRAY_BUFFER,offset,length,pSource);
		glBindBufferARB(GL_ARRAY_BUFFER,0);
	}
Beispiel #13
0
void upload_image_data_to_opengl(unsigned char* raw_image_data,
                                 CameraPixelCoding coding,
				 int device_number) {
  unsigned char * gl_image_data;
  static unsigned char* show_pixels=NULL;
  GLuint textureId;
  GLubyte* ptr;

  textureId = textureId_all[device_number];

  if (use_pbo) {
#ifdef USE_GLEW
    glBindTexture(GL_TEXTURE_2D, textureId);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);

    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex_width, tex_height, gl_data_format, GL_UNSIGNED_BYTE, 0);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, PBO_stride*tex_height, 0, GL_STREAM_DRAW_ARB);
    ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
    if(ptr) {
      convert_pixels(raw_image_data, coding, PBO_stride, ptr, 1);
      glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
    }
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
#endif  /* ifdef USE_GLEW */
  } else {

    if (show_pixels==NULL) {
      /* allocate memory */
      show_pixels = (unsigned char *)malloc( PBO_stride*height );
      if (show_pixels==NULL) {
        fprintf(stderr,"couldn't allocate memory in %s, line %d\n",__FILE__,__LINE__);
        exit(1);
      }
    }

    gl_image_data = convert_pixels(raw_image_data, coding, PBO_stride, show_pixels, 0);

    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexSubImage2D(GL_TEXTURE_2D, /* target */
                    0, /* mipmap level */
                    0, /* x offset */
                    0, /* y offset */
                    width,
                    height,
                    gl_data_format, /* data format */
                    GL_UNSIGNED_BYTE, /* data type */
                    gl_image_data);

  }
}
	void* OpenGLTexture::lock(TextureUsage _access)
	{
		MYGUI_PLATFORM_ASSERT(mTextureID, "Texture is not created");

		if (_access == TextureUsage::Read)
		{
			glBindTexture(GL_TEXTURE_2D, mTextureID);

			mBuffer = new unsigned char[mDataSize];
			glGetTexImage(GL_TEXTURE_2D, 0, mPixelFormat, GL_UNSIGNED_BYTE, mBuffer);

			mLock = false;

			return mBuffer;
		}

		// bind the texture
		glBindTexture(GL_TEXTURE_2D, mTextureID);
		if (!OpenGLRenderManager::getInstance().isPixelBufferObjectSupported())
		{
			//Fallback if PBO's are not supported
			mBuffer = new unsigned char[mDataSize];
		}
		else
		{
			// bind the PBO
			glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID);
			
			// Note that glMapBufferARB() causes sync issue.
			// If GPU is working with this buffer, glMapBufferARB() will wait(stall)
			// until GPU to finish its job. To avoid waiting (idle), you can call
			// first glBufferDataARB() with NULL pointer before glMapBufferARB().
			// If you do that, the previous data in PBO will be discarded and
			// glMapBufferARB() returns a new allocated pointer immediately
			// even if GPU is still working with the previous data.
			glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage);

			// map the buffer object into client's memory
			mBuffer = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mAccess);
			if (!mBuffer)
			{
				glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
				glBindTexture(GL_TEXTURE_2D, 0);
				MYGUI_PLATFORM_EXCEPT("Error texture lock");
			}
		}

		mLock = true;

		return mBuffer;
	}
Beispiel #15
0
void
glmMakeVBOs(GLMmodel *model)
{
   uint bytes, vertexFloats, i;
   float *buffer;

   vertexFloats = 3;
   model->posOffset = 0;

   if (model->numnormals > 0) {
      assert(model->numnormals == model->numvertices);
      model->normOffset = vertexFloats * sizeof(GLfloat);
      vertexFloats += 3;
   }      

   if (model->numtexcoords > 0) {
      assert(model->numtexcoords == model->numvertices);
      model->texOffset = vertexFloats * sizeof(GLfloat);
      vertexFloats += 2;
   }

   model->vertexSize = vertexFloats;

   bytes = (model->numvertices + 1) * vertexFloats * sizeof(float);

   buffer = (float *) malloc(bytes);
   for (i = 0; i < model->numvertices; i++) {
      /* copy vertex pos */
      uint j = 0;
      buffer[i * vertexFloats + j++] = model->vertices[i * 3 + 0];
      buffer[i * vertexFloats + j++] = model->vertices[i * 3 + 1];
      buffer[i * vertexFloats + j++] = model->vertices[i * 3 + 2];
      if (model->numnormals > 0) {
         buffer[i * vertexFloats + j++] = model->normals[i * 3 + 0];
         buffer[i * vertexFloats + j++] = model->normals[i * 3 + 1];
         buffer[i * vertexFloats + j++] = model->normals[i * 3 + 2];
      }
      if (model->numtexcoords > 0) {
         buffer[i * vertexFloats + j++] = model->texcoords[i * 2 + 0];
         buffer[i * vertexFloats + j++] = model->texcoords[i * 2 + 1];
      }
   }

   glGenBuffersARB(1, &model->vbo);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, model->vbo);
   glBufferDataARB(GL_ARRAY_BUFFER_ARB, bytes, buffer, GL_STATIC_DRAW_ARB);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

   free(buffer);
}
Beispiel #16
0
	void cVertexBufferVBO::UpdateData(tVertexFlag aTypes, bool abIndices)
	{
		GLenum usageType = GL_STATIC_DRAW_ARB;
		if(mUsageType== eVertexBufferUsageType_Dynamic) usageType = GL_DYNAMIC_DRAW_ARB;
		else if(mUsageType== eVertexBufferUsageType_Stream) usageType = GL_STREAM_DRAW_ARB;

		//Create the VBO vertex arrays
		for(int i=0;i< klNumOfVertexFlags; i++)
		{
			if((mVertexFlags & kvVertexFlags[i]) && (aTypes & kvVertexFlags[i]))
			{
				glBindBufferARB(GL_ARRAY_BUFFER_ARB, mvArrayHandle[i]);

				//This was apparently VERY slow.
				glBufferDataARB(GL_ARRAY_BUFFER_ARB, mvVertexArray[i].size()*sizeof(float),
					NULL, usageType);//Clear memory

				glBufferDataARB(GL_ARRAY_BUFFER_ARB, mvVertexArray[i].size()*sizeof(float),
					&(mvVertexArray[i][0]), usageType);
			}
		}
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

		//Create the VBO index array
		if(abIndices)
		{
			glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,mlElementHandle);

			//glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,GetIndexNum()*sizeof(unsigned int),
			//	NULL, usageType);

			glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GetIndexNum()*sizeof(unsigned int),
				&mvIndexArray[0], usageType);

			glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
		}
	}
Beispiel #17
0
// Initialize GL
//*****************************************************************************
void initPixelBuffer()
{
     ciErrNum = CL_SUCCESS;

    if (pbo) {
        // delete old buffer
        clReleaseMemObject(pbo_cl);
        glDeleteBuffersARB(1, &pbo);
    }

    // create pixel buffer object for display
    glGenBuffersARB(1, &pbo);
	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
	glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * sizeof(GLubyte) * 4, 0, GL_STREAM_DRAW_ARB);
	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

	if( g_glInterop ) 
	{
		// create OpenCL buffer from GL PBO
		pbo_cl = clCreateFromGLBuffer(cxGPUContext,CL_MEM_WRITE_ONLY, pbo, &ciErrNum);
		//oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);
		printf("Create from GL buffer error %i\n",ciErrNum);		
	} 
	else 
	{
		pbo_cl = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, width * height * sizeof(GLubyte) * 4, NULL, &ciErrNum);
	}

    // calculate new grid size
	//gridSize[0] = floor(width/LOCAL_SIZE_X);
	//gridSize[1] = floor(height/LOCAL_SIZE_Y);

	gridSize[0] = width;
	gridSize[1] = height;

	int xBlocks = (size_t)ceil((float)width / (float)LOCAL_SIZE_X);
	int yBlocks = (size_t)ceil((float)height / (float)LOCAL_SIZE_Y);

	// Calculate total number of threads (this is done to guarantee that total number of threads is multiple of local work size, required by OpenCL)
	gridSize[0] = xBlocks * LOCAL_SIZE_X;
	gridSize[1] = yBlocks * LOCAL_SIZE_Y;

    ciErrNum |= clSetKernelArg(ckKernel, 0, sizeof(cl_mem), (void *) &pbo_cl);
    ciErrNum |= clSetKernelArg(ckKernel, 1, sizeof(unsigned int), &width);
    ciErrNum |= clSetKernelArg(ckKernel, 2, sizeof(unsigned int), &height);
	printf("Error first kernel args is %i\n",ciErrNum);

    //oclCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);
}
void initGLBuffers()
{
    if (pbo)
    {
        // delete old buffer
        checkCudaErrors(cudaGraphicsUnregisterResource(cuda_pbo_resource));
        glDeleteBuffersARB(1, &pbo);
    }

    // create pixel buffer object for display
    glGenBuffersARB(1, &pbo);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
    glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width*height*sizeof(uchar4), 0, GL_STREAM_DRAW_ARB);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

    checkCudaErrors(cudaGraphicsGLRegisterBuffer(&cuda_pbo_resource, pbo,
                    cudaGraphicsMapFlagsWriteDiscard));

#if USE_BUFFER_TEX

    // create buffer texture, attach to pbo
    if (bufferTex)
    {
        glDeleteTextures(1, &bufferTex);
    }

    glGenTextures(1, &bufferTex);
    glBindTexture(GL_TEXTURE_BUFFER_EXT, bufferTex);
    glTexBufferEXT(GL_TEXTURE_BUFFER_EXT, GL_RGBA8, pbo);
    glBindTexture(GL_TEXTURE_BUFFER_EXT, 0);
#else

    // create texture for display
    if (displayTex)
    {
        glDeleteTextures(1, &displayTex);
    }

    glGenTextures(1, &displayTex);
    glBindTexture(GL_TEXTURE_TYPE, displayTex);
    glTexImage2D(GL_TEXTURE_TYPE, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glTexParameteri(GL_TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glBindTexture(GL_TEXTURE_TYPE, 0);
#endif

    // calculate new grid size
    gridSize = dim3(iDivUp(width, blockSize.x), iDivUp(height, blockSize.y));
}
Beispiel #19
0
/* Context activation is done by the caller. */
static void wined3d_volume_prepare_pbo(struct wined3d_volume *volume, struct wined3d_context *context)
{
    const struct wined3d_gl_info *gl_info = context->gl_info;

    if (volume->pbo)
        return;

    GL_EXTCALL(glGenBuffersARB(1, &volume->pbo));
    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
    GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->resource.size, NULL, GL_STREAM_DRAW_ARB));
    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
    checkGLcall("Create PBO");

    TRACE("Created PBO %u for volume %p.\n", volume->pbo, volume);
}
Beispiel #20
0
//--------------------------------------------------------------
void ofVbo::setTexCoordData(const ofVec2f * texCoords, int total, int usage) {
    if(texCoords == NULL) {
        ofLog(OF_LOG_WARNING,"ofVbo: bad texCoord data!\n");
        return;
    }
    texUsage = usage;
    if(!bUsingTexCoords) {
        bUsingTexCoords = true;
        glGenBuffers(1, &texCoordId);
    }

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, texCoordId);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, total * sizeof(ofVec2f), &texCoords[0].x, usage);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
Beispiel #21
0
	void CMesh::Setup(unsigned int vbovertices)
	{
		m_nVBOVertices = vbovertices;
		_ASSERT_EXPR_A(!(error = glGetError()), (const char*)gluErrorString(error));
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOVertices);
		_ASSERT_EXPR_A(!(error = glGetError()), (const char*)gluErrorString(error));
		std::vector<XMFLOAT3> data(polygons.size() * VERTICESPERPOLY);
		for (size_t i = 0, dst = 0; i < polygons.size(); ++i) {
			data[dst++] = vertices[polygons[i].v[0]];
			data[dst++] = vertices[polygons[i].v[1]];
			data[dst++] = vertices[polygons[i].v[2]];
		}

		glBufferDataARB(GL_ARRAY_BUFFER_ARB, data.size() * sizeof(XMFLOAT3), &data.front(), GL_STATIC_DRAW_ARB);
		_ASSERT_EXPR_A(!(error = glGetError()), (const char*)gluErrorString(error));
		// Normals...
		glGenBuffersARB(1, &m_nVBONormals);
		_ASSERT_EXPR_A(!(error = glGetError()), (const char*)gluErrorString(error));
		std::vector<XMFLOAT3> normals(polygons.size() * VERTICESPERPOLY);
		for (size_t i = 0, dst = 0; i < polygons.size(); ++i) {
			// TODO:: ccw hack
			XMFLOAT3 n;
			XMStoreFloat3(&n, XMVectorScale(XMLoadFloat3(&normalsV[i].n[0]), -1.f));
			normals[dst++] = n;
			XMStoreFloat3(&n, XMVectorScale(XMLoadFloat3(&normalsV[i].n[1]), -1.f));
			normals[dst++] = n;
			XMStoreFloat3(&n, XMVectorScale(XMLoadFloat3(&normalsV[i].n[2]), -1.f));
			normals[dst++] = n;
		}

		glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBONormals);
		_ASSERT_EXPR_A(!(error = glGetError()), (const char*)gluErrorString(error));
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, normals.size() * sizeof(XMFLOAT3), &normals.front(), GL_STATIC_DRAW_ARB);
		_ASSERT_EXPR_A(!(error = glGetError()), (const char*)gluErrorString(error));

	}
Beispiel #22
0
//--------------------------------------------------------------
void ofVbo::setColorData(const ofColor * colors, int total, int usage) {
    if(colors == NULL) {
        ofLog(OF_LOG_WARNING,"ofVbo: bad color data!\n");
        return;
    }
    colorUsage = usage;
    if(!bUsingColors) {
        bUsingColors = true;
        glGenBuffers(1, &colorId);
    }

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorId);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, total * sizeof(ofColor), &colors[0].r, usage);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
void OpenNI2ViewNode::customDraw() {	
	update();
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[0]);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, nPoints * 3 * sizeof(float), Wxyz.getPixels(), GL_STATIC_DRAW_ARB);
	glVertexPointer(3, GL_FLOAT, 0, 0);
    
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[1]);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, nPoints * 3 * sizeof(unsigned char), kinect.getRGBPixels().getPixels(), GL_STATIC_DRAW_ARB);
	glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
	
	
	glPointSize(2.0f);
	glDrawArrays(GL_POINTS, 0, nPoints);
	
	
	glDisableClientState(GL_VERTEX_ARRAY); 
	glDisableClientState(GL_COLOR_ARRAY);
	
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);	
}
Beispiel #24
0
//--------------------------------------------------------------
void ofVbo::setNormalData(const ofVec3f * normals, int total, int usage) {
    if(normals == NULL) {
        ofLog(OF_LOG_WARNING,"ofVbo: bad normal data!\n");
        return;
    }
    normUsage = usage;
    if(!bUsingNormals) {
        bUsingNormals = true;
        glGenBuffers(1, &normalId);
    }

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, normalId);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, total * sizeof(ofVec3f), &normals[0].x, usage);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
enum piglit_result
piglit_display(void)
{
	GLuint vbo;
	GLboolean pass;

	glGenBuffersARB(1, &vbo);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 100*100, NULL, GL_STATIC_DRAW_ARB);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

	pass = test_Purgeable(vbo, GL_BUFFER_OBJECT_APPLE);

	glDeleteBuffersARB(1, &vbo);
	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Beispiel #26
0
//--------------------------------------------------------------
void ofVbo::setIndexData(const GLuint * indices, int total, int usage) {
    if(indices == NULL) {
        ofLog(OF_LOG_WARNING,"ofVbo: bad index data!\n");
        return;
    }

    if(!bUsingIndices) {
        bUsingIndices = true;
        glGenBuffers(1, &indexId);
    }

    glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexId);
    indexData = (GLuint*)indices;
    glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(GLuint) * total, indexData, usage);
    glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
Beispiel #27
0
TGen::VertexData * TGen::OpenGL::Renderer::createVertexData(const TGen::VertexStructure & vertstruct, uint size, ushort usage) {
	GLuint newVBO = 0;
	glGenBuffersARB(1, &newVBO);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, newVBO);
	
	DEBUG_PRINT("[opengl]: created new vbo for vertex data: " << newVBO);
	
	GLenum fixedUsage = 0;
	
	if (usage & TGen::UsageStream) {
		if (usage & TGen::UsageDraw)
			fixedUsage = GL_STREAM_DRAW_ARB;
		else if (usage & TGen::UsageCopy)
			fixedUsage = GL_STREAM_COPY_ARB;
		else if (usage & TGen::UsageRead)
			fixedUsage = GL_STREAM_READ_ARB;
		else
			fixedUsage = GL_STREAM_DRAW_ARB;
	}
	else if (usage & TGen::UsageDynamic) {
		if (usage & TGen::UsageDraw)
			fixedUsage = GL_DYNAMIC_DRAW_ARB;
		else if (usage & TGen::UsageCopy)
			fixedUsage = GL_DYNAMIC_COPY_ARB;
		else if (usage & TGen::UsageRead)
			fixedUsage = GL_DYNAMIC_READ_ARB;
		else
			fixedUsage = GL_DYNAMIC_DRAW_ARB;
	}
	else if (usage & TGen::UsageStatic) {
		if (usage & TGen::UsageDraw)
			fixedUsage = GL_STATIC_DRAW_ARB;
		else if (usage & TGen::UsageCopy)
			fixedUsage = GL_STATIC_COPY_ARB;
		else if (usage & TGen::UsageRead)
			fixedUsage = GL_STATIC_READ_ARB;
		else
			fixedUsage = GL_STATIC_DRAW_ARB;
	}
	
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, NULL, fixedUsage);
	
	// TODO: in i ~ också...
	PSTAT_ADD_VAL(TGen::StatBufferAlloc, size);
	
	return new TGen::OpenGL::VertexData(*this, stats, vertstruct, size, fixedUsage, newVBO);	
}
Beispiel #28
0
    void* mapWrite()
        {
            if( !_testInitialized( ))
                return 0;

            if( _type != GL_WRITE_ONLY_ARB )
            {
                _setError( ERROR_PBO_READ_ONLY );
                return 0;
            }

            bind();
            // cancel all draw operations on this buffer to prevent stalling
            EQ_GL_CALL( glBufferDataARB( GL_PIXEL_UNPACK_BUFFER_ARB, size, 0, 
                                         GL_STREAM_DRAW_ARB ));
            return glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, _type );
        }
void PointCloudViewer::drawPointCloud()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glBindBufferARB(GL_ARRAY_BUFFER, buffers[0]);
    glBufferDataARB(GL_ARRAY_BUFFER, sizeof(float)*pointCloud->cols*pointCloud->rows*3, pointCloud->ptr(), GL_DYNAMIC_DRAW);
    glVertexPointer(3 , GL_FLOAT , 0 , 0);
    glBindBufferARB(GL_ARRAY_BUFFER, buffers[1]);
    glTexCoordPointer(2, GL_FLOAT, 0, 0);
    glEnable(GL_TEXTURE_2D);
    glDrawArrays(GL_POINTS, 0, pointCloud->cols * pointCloud->rows);
    glDisable(GL_TEXTURE_2D);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Beispiel #30
0
//--------------------------------------------------------------
void ofVbo::setVertexData(const ofVec3f * verts, int total, int usage) {
    if(verts == NULL) {
        ofLog(OF_LOG_WARNING,"ofVbo: bad vertex data!\n");
        return;
    }
    vertUsage = usage;
    if(!bUsingVerts) {
        bAllocated  = true;
        bUsingVerts = true;
        glGenBuffers(1, &vertId);
    }

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertId);
    vertData = (float*)&verts[0].x;
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, total * sizeof(ofVec3f), vertData, usage);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}