Ejemplo n.º 1
0
void agp_draw_vobj(float x1, float y1, float x2, float y2,
	float* txcos, float* model)
{
	GLfloat verts[] = {
		x1, y1,
		x2, y1,
		x2, y2,
	 	x1, y2
	};
	bool settex = false;

	agp_shader_envv(MODELVIEW_MATR, model?model:ident, sizeof(float) * 16);
/* projection, scissor is set when activating rendertarget */

	GLint attrindv = agp_shader_vattribute_loc(ATTRIBUTE_VERTEX);
	GLint attrindt = agp_shader_vattribute_loc(ATTRIBUTE_TEXCORD);

	if (attrindv != -1){
		glEnableVertexAttribArray(attrindv);
		glVertexAttribPointer(attrindv, 2, GL_FLOAT, GL_FALSE, 0, verts);

		if (txcos && attrindt != -1){
			settex = true;
			glEnableVertexAttribArray(attrindt);
			glVertexAttribPointer(attrindt, 2, GL_FLOAT, GL_FALSE, 0, txcos);
		}

		glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

		if (settex)
			glDisableVertexAttribArray(attrindt);

		glDisableVertexAttribArray(attrindv);
	}
}
Ejemplo n.º 2
0
void agp_submit_mesh(struct mesh_storage_t* base, enum agp_mesh_flags fl)
{
/* make sure the current program actually uses the attributes from the mesh */
	int attribs[3] = {
		agp_shader_vattribute_loc(ATTRIBUTE_VERTEX),
		agp_shader_vattribute_loc(ATTRIBUTE_NORMAL),
		agp_shader_vattribute_loc(ATTRIBUTE_TEXCORD)
	};

	if (attribs[0] == -1)
		return;
	else {
		glEnableVertexAttribArray(attribs[0]);
		glVertexAttribPointer(attribs[0], 3, GL_FLOAT, GL_FALSE, 0, base->verts);
	}

	if (attribs[1] != -1 && base->normals){
		glEnableVertexAttribArray(attribs[1]);
		glVertexAttribPointer(attribs[1], 3, GL_FLOAT, GL_FALSE,0, base->normals);
	}
	else
		attribs[1] = -1;

	if (attribs[2] != -1 && base->txcos){
		glEnableVertexAttribArray(attribs[2]);
		glVertexAttribPointer(attribs[2], 2, GL_FLOAT, GL_FALSE, 0, base->txcos);
	}
	else
		attribs[2] = -1;

		if (base->type == AGP_MESH_TRISOUP){
			if (base->indices)
				glDrawElements(GL_TRIANGLES, base->n_indices,
					GL_UNSIGNED_INT, base->indices);
			else
				glDrawArrays(GL_TRIANGLES, 0, base->n_vertices);
		}
		else if (base->type == AGP_MESH_POINTCLOUD){
			glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
			glDrawArrays(GL_POINTS, 0, base->n_vertices);
			glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
		}

		for (size_t i = 0; i < sizeof(attribs) / sizeof(attribs[0]); i++)
			if (attribs[i] != -1)
				glDisableVertexAttribArray(attribs[i]);
}
Ejemplo n.º 3
0
static void setup_transfer(struct mesh_storage_t* base, enum agp_mesh_flags fl)
{
	struct agp_fenv* env = agp_env();
	int attribs[3] = {
		agp_shader_vattribute_loc(ATTRIBUTE_VERTEX),
		agp_shader_vattribute_loc(ATTRIBUTE_NORMAL),
		agp_shader_vattribute_loc(ATTRIBUTE_TEXCORD)
	};
	if (attribs[0] == -1)
		return;
	else {
		env->enable_vertex_attrarray(attribs[0]);
		env->vertex_attrpointer(attribs[0], 3, GL_FLOAT, GL_FALSE, 0, base->verts);
	}

	if (attribs[1] != -1 && base->normals){
		env->enable_vertex_attrarray(attribs[1]);
		env->vertex_attrpointer(attribs[1], 3, GL_FLOAT, GL_FALSE,0, base->normals);
	}
	else
		attribs[1] = -1;

	if (attribs[2] != -1 && base->txcos){
		env->enable_vertex_attrarray(attribs[2]);
		env->vertex_attrpointer(attribs[2], 2, GL_FLOAT, GL_FALSE, 0, base->txcos);
	}
	else
		attribs[2] = -1;

	if (base->type == AGP_MESH_TRISOUP){
		if (base->indices)
			env->draw_elements(GL_TRIANGLES, base->n_indices,
				GL_UNSIGNED_INT, base->indices);
		else
			env->draw_arrays(GL_TRIANGLES, 0, base->n_vertices);
	}
	else if (base->type == AGP_MESH_POINTCLOUD){
		env->enable(GL_VERTEX_PROGRAM_POINT_SIZE);
		env->draw_arrays(GL_POINTS, 0, base->n_vertices);
		env->disable(GL_VERTEX_PROGRAM_POINT_SIZE);
	}

	for (size_t i = 0; i < sizeof(attribs) / sizeof(attribs[0]); i++)
		if (attribs[i] != -1)
			env->disable_vertex_attrarray(attribs[i]);
}
Ejemplo n.º 4
0
void agp_draw_vobj(float x1, float y1, float x2, float y2,
	const float* txcos, const float* model)
{
	GLfloat verts[] = {
		x1, y1,
		x2, y1,
		x2, y2,
		x1, y2
	};
	bool settex = false;
	struct agp_fenv* env = agp_env();

	agp_shader_envv(MODELVIEW_MATR,
		model ? (void*) model : ident, sizeof(float) * 16);

/* projection, scissor is set when activating rendertarget */
	GLint attrindv = agp_shader_vattribute_loc(ATTRIBUTE_VERTEX);
	GLint attrindt = agp_shader_vattribute_loc(ATTRIBUTE_TEXCORD);

	if (attrindv != -1){
		env->enable_vertex_attrarray(attrindv);
		env->vertex_attrpointer(attrindv, 2, GL_FLOAT, GL_FALSE, 0, verts);

		if (txcos && attrindt != -1){
			settex = true;
			env->enable_vertex_attrarray(attrindt);
			env->vertex_attrpointer(attrindt, 2, GL_FLOAT, GL_FALSE, 0, txcos);
		}

		env->draw_arrays(GL_TRIANGLE_FAN, 0, 4);

		if (settex)
			env->disable_vertex_attrarray(attrindt);

		env->disable_vertex_attrarray(attrindv);
	}
}