示例#1
0
// Runs into main thread
static void particles_draw(particles_type *ps, float x, float y, float zoom) 
{
	if (!ps->alive || !ps->vertices || !ps->colors || !ps->texcoords) return;
	GLfloat *vertices = ps->vertices;
	GLfloat *colors = ps->colors;
	GLshort *texcoords = ps->texcoords;

	if (x < -10000) x = -10000;
	if (x > 10000) x = 10000;
	if (y < -10000) y = -10000;
	if (y > 10000) y = 10000;

	SDL_mutexP(ps->lock);

	if (ps->blend_mode == BLEND_ADDITIVE) glBlendFunc(GL_SRC_ALPHA,GL_ONE);

	if (multitexture_active) tglActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, ps->texture);
	if (multitexture_active && main_fbo) {
		tglActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, main_fbo->texture);
	}
	glTexCoordPointer(2, GL_SHORT, 0, texcoords);
	glColorPointer(4, GL_FLOAT, 0, colors);
	glVertexPointer(2, GL_FLOAT, 0, vertices);

	glTranslatef(x, y, 0);
	glPushMatrix();
	glScalef(ps->zoom * zoom, ps->zoom * zoom, ps->zoom * zoom);
	glRotatef(ps->rotate, 0, 0, 1);

	if (ps->shader) useShader(ps->shader, 1, 1, main_fbo ? main_fbo->w : 1, main_fbo ? main_fbo->h : 1, 1, 1, 1, 1);

	int remaining = ps->batch_nb;
	while (remaining >= PARTICLES_PER_ARRAY)
	{
		glDrawArrays(GL_QUADS, remaining - PARTICLES_PER_ARRAY, PARTICLES_PER_ARRAY);
		remaining -= PARTICLES_PER_ARRAY;
	}
	if (remaining) glDrawArrays(GL_QUADS, 0, remaining);

	if (ps->shader) tglUseProgramObject(0);

	glPopMatrix();
	glTranslatef(-x, -y, 0);

	if (ps->blend_mode) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	if (multitexture_active && main_fbo) {
		tglActiveTexture(GL_TEXTURE0);
	}

	SDL_mutexV(ps->lock);
}
示例#2
0
		void teTexture::Bind(u32 layer) const
		{
			switch(textureType)
			{
			case TT_2D: tglActiveTexture(GL_TEXTURE0 + layer); glBindTexture(GL_TEXTURE_2D, textureId); break;
			case TT_RENDERBUFFER: tglBindRenderbuffer(textureId); break;
			default: TE_ASSERT(0); break;
			}
		}