Mariusmssj4
Posts: 15
Joined: Thu Jan 23, 2014 10:37 am

glDrawArrays only handles up to 65535 points

Mon May 11, 2015 12:57 pm

Hi guys,

Seems to have an issue with OpenGLES2.0 as it can only draw up to 65535 on my:

Code: Select all

glDrawArrays(GL_POINTS, 0, pointCount); //307200 points 
call.
So is there any way to increase the point count for the call?

Thanks.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: glDrawArrays only handles up to 65535 points

Mon May 11, 2015 1:08 pm

GLsizei is probably 16bit
so cannot be increased
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Mariusmssj4
Posts: 15
Joined: Thu Jan 23, 2014 10:37 am

Re: glDrawArrays only handles up to 65535 points

Mon May 11, 2015 1:25 pm

Yeah it seems to be the case, is it possible to make up a point cloud out of multiple 65535 point segments?

e.g:

Code: Select all

glVertexAttribPointer(posAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)segment1);
glEnableVertexAttribArray(posAttrib);
glDrawArrays(GL_POINTS, 0, 65535);
glVertexAttribPointer(posAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)segment2);
glEnableVertexAttribArray(posAttrib);
glDrawArrays(GL_POINTS, 0, 65535);
glVertexAttribPointer(posAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)segment3);
glEnableVertexAttribArray(posAttrib);
glDrawArrays(GL_POINTS, 0, 65535);

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: glDrawArrays only handles up to 65535 points

Mon May 11, 2015 6:55 pm

Mariusmssj4 wrote:Yeah it seems to be the case, is it possible to make up a point cloud out of multiple 65535 point segments?
There shouldn't be a problem. Although in your code you showed you call glEnableVertexAttribArray(posAttrib); three times, you only need to enable it the first time, it'll stay active until you disable it with glDisableVertexAttribArray (posAttrib);

You might be able to get away with not setting the array pointer each time, instead just add 65536 to first of glDrawArrays().

Code: Select all

glDrawArrays(GL_POINTS, 0, 65535);
glDrawArrays(GL_POINTS, 65536, 65535);
glDrawArrays (GL_POINTS, 131072, 65535); 
She who travels light — forgot something.

Mariusmssj4
Posts: 15
Joined: Thu Jan 23, 2014 10:37 am

Re: glDrawArrays only handles up to 65535 points

Tue May 12, 2015 8:41 am

Thanks for the replies guys :)

Paeryn the change of starting point didn't work so I wrote a for loop and changed the starting pointer on the array. This is the draw call now and it works:

Code: Select all

void Renderer::draw(pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointCloud)
{
	// Set the viewport
	glViewport(0, 0, this->GScreenWidth, this->GScreenHeight);

	//Clear colour buffer
	glClearColor(0.0f, 0.8f, 0.8f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	if (pointCloud->size() == 0)
		return;

	pcl::PointXYZRGB *pointPtr = &pointCloud->points[0];
	size_t pointCount = pointCloud->points.size();	

	int segments = pointCount / 65535;
	int lowSegm = pointCount % 65535; //307200

	//Use program object
	glUseProgram(this->programObject);

	//Get attribute location
	GLint posAttrib = glGetAttribLocation(this->programObject, "position");
	glEnableVertexAttribArray(posAttrib);

	for (int i = 0; i <= segments; i++)
	{
		float  * ptrV = (float*)(&pointPtr[65535 * i]);
		//Load vertex data
		glVertexAttribPointer(posAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)(ptrV));

		if (i < segments)
			glDrawArrays(GL_POINTS, 0, 65535);
		else
			glDrawArrays(GL_POINTS, 0, lowSegm);
	}

	glDisableVertexAttribArray(posAttrib);
	eglSwapBuffers(this->GDisplay, this->GSurface);
}

Return to “Graphics programming”