Beispiel #1
0
/*
=================
GL_LoadMatrix
=================
*/
void GL_LoadMatrix( cmatrix4x4 source )
{
	GLfloat	dest[16];

	Matrix4x4_ToArrayFloatGL( source, dest );
	pglLoadMatrixf( dest );
}
Beispiel #2
0
void drawPLightOCallback(renderlistitem_t * ilist, unsigned int count){
//	printf("added!\n");

	renderPLightCallbackData_t *d = ilist->data;
	shaderpermutation_t * perm = d->perm;
	if(shader_bindPerm(perm) == 2){
	//TODODODODODO
		viewport_t *v = d->v;
		//also have to set some basic uniforms?
	//	framebuffer_t *df = returnFramebufferById(v->dfbid);
		framebuffer_t *of = returnFramebufferById(v->outfbid);

		GLfloat mout[16];	//todo calc MOUT per viewport in viewport update
		Matrix4x4_ToArrayFloatGL(&v->viewproj, mout);
		glUniformMatrix4fv(perm->unimat40, 1, GL_FALSE, mout);
		Matrix4x4_ToArrayFloatGL(&v->view, mout);
		glUniformMatrix4fv(perm->unimat41, 1, GL_FALSE, mout);
		glUniform2f(perm->uniscreensizefix, 1.0/of->width, 1.0/of->height);
//		float far = v->far;
//		float near = v->near;
//		glUniform2f(perm->uniscreentodepth, far/(far-near),far*near/(near-far));
		glUniform2f(perm->uniscreentodepth, v->projection.m[0][0], v->projection.m[1][1]);
		unsigned char numsamples = d->numsamples;
		if(numsamples) glUniform1i(perm->uniint0, numsamples);
	}

	model_t *m = model_returnById(d->modelid);
	vbo_t *v = returnVBOById(m->vbo);

//	states_bindVertexArray(v->vaoid);
	unsigned int mysize = ((count * sizeof(pLightUBOStruct_t)));
//	states_bindBufferRange(GL_UNIFORM_BUFFER, 0, renderqueueuboid, d->ubodataoffset, mysize);
//	glstate_t s = {STATESENABLECULLFACE | STATESENABLEBLEND, GL_ONE, GL_ONE, GL_LESS, GL_FRONT, GL_FALSE, GL_LESS, 0.0, v->vaoid, renderqueueuboid, GL_UNIFORM_BUFFER, 0, d->ubodataoffset, mysize, perm->id};
	glstate_t s = {STATESENABLECULLFACE | STATESENABLEBLEND, GL_ONE, GL_ONE, GL_LESS, GL_FRONT, GL_FALSE, GL_LESS, 0.0, v->vaoid, 0, 0, 0, 0, 0, perm->id, 0, {0}, {0}, {renderqueueuboid, 0},{d->ubodataoffset, 0}, {mysize, 0}};
	states_setState(s);
	//states_cullFace(GL_FRONT);
	CHECKGLERROR
	glDrawElementsInstanced(GL_TRIANGLES, v->numfaces * 3, GL_UNSIGNED_INT, 0, count);

	//todo
}
Beispiel #3
0
void cube_render(camera_t *c){
	glstate_t s = {STATESENABLEDEPTH|STATESENABLECULLFACE, GL_ONE, GL_ONE, GL_LESS, GL_BACK, GL_FALSE, GL_LESS, 0.0, cubevao, 0, 0, 0, 0, 0, cubeshader.programid, 0, {0}, {0}, {0, 0}, {0, 0}, {0, 0}};
	states_setState(s);
	states_bindActiveTexture(0, GL_TEXTURE_CUBE_MAP, cubemapid);
//	states_bindTexture(GL_TEXTURE_CUBE_MAP, cubemapid);
//	states_useProgram(cubeshader.programid);
//	glBindVertexArray(cubevao);
	GLfloat mvp[16];
	Matrix4x4_ToArrayFloatGL(&c->mvronlyp, mvp);
	glUniformMatrix4fv(cubeshader.unimat40, 1, GL_FALSE, mvp);
	glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
}
Beispiel #4
0
int lights_addToRenderQueue(viewport_t *v, renderqueue_t * q, unsigned int numsamples){
	shaderprogram_t * shader = shader_returnById(lightshaderid);
	unsigned int permutation = 0;
	shaderpermutation_t * perm, *spotperm;

//	framebuffer_t *df = returnFramebufferById(v->dfbid);
//	framebuffer_t *of = returnFramebufferById(v->outfbid);
//	if(!df || !of) return FALSE;

//	unsigned int numsamples = df->rbflags & FRAMEBUFFERRBFLAGSMSCOUNT;

	if(numsamples){
//		numsamples = 1<<numsamples;
//		resolveMultisampleFramebuffer(df); //only resolves if multisampled
//		resolveMultisampleFramebufferSpecify(df, 4);
		permutation = 2;
	}
	perm = shader_addPermutationToProgram(shader, permutation);
	spotperm = shader_addPermutationToProgram(shader, permutation|4);

	lightrenderout_t out = readyLightsForRender(v, 50, 0);
	if(!out.lin.count && !out.lout.count) return FALSE;
//	out.lout.count = 0;
//	if(out.lin.count) out.lin.count = 1;
	int i;
	renderPLightCallbackData_t pl; //i can do this because the data is copied
	pl.modelid = sphereModel;
	pl.shaderid = lightshaderid;
	pl.shaderperm = permutation;
	pl.perm = perm;
	pl.numsamples = numsamples;
	pl.shaderprogram = perm->id;
	pl.v = v;
	renderSLightCallbackData_t sl; //i can do this because the data is copied
	sl.modelid = lightconeModel;
	sl.shaderid = lightshaderid;
	sl.shaderperm = permutation|4;
	sl.perm = spotperm;
	sl.numsamples = numsamples;
	sl.shaderprogram = spotperm->id;
	sl.v = v;

	renderlistitem_t r;
	r.sort[0] = 0; //first to be drawn in this queue
	r.sort[1] = 0;
	r.sort[2] = 0;
	r.sort[3] = 0;
	r.sort[4] = (pl.shaderprogram >> 0) & 0xFF;
	r.sort[5] = (pl.shaderprogram >> 8) & 0xFF;
	r.sort[6] = (pl.shaderprogram >> 16) & 0xFF;
	r.sort[7] = (pl.shaderprogram >> 24) & 0xFF;
	r.sort[8] = (pl.modelid >> 0) & 0xFF;
	r.sort[9] = (pl.modelid >> 8) & 0xFF;
	r.flags = 2 | 4; //copyable, instanceable
	for(i = 0; i < out.lin.count; i++){
		//check if its spot or not
		if(out.lin.list[i]->type ==2){
			matrix4x4_t ct;
			Matrix4x4_Concatsimdu(&ct, &v->viewproj, &out.lin.list[i]->camproj);
			Matrix4x4_ToArrayFloatGL(&ct, sl.light.mvp);
			sl.light.size = out.lin.list[i]->scale;
			Matrix4x4_Concatsimdu(&ct, &v->view, &out.lin.list[i]->camproj);
			Matrix4x4_ToArrayFloatGL(&ct, sl.light.mv);
			Matrix4x4_ToArrayFloatGL(&out.lin.list[i]->viewproj, sl.light.lmv);
			sl.light.pos[0] = out.lin.list[i]->pos[0];
			sl.light.pos[1] = out.lin.list[i]->pos[1];
			sl.light.pos[2] = out.lin.list[i]->pos[2];

			r.draw = drawSLightICallback;
			r.setup = setupSLightCallback;
			r.datasize = sizeof(renderSLightCallbackData_t);
			r.data = &sl;

		} else {
			pl.light.size = out.lin.list[i]->scale;
			pl.light.pos[0] = out.lin.list[i]->pos[0];
			pl.light.pos[1] = out.lin.list[i]->pos[1];
			pl.light.pos[2] = out.lin.list[i]->pos[2];
			r.draw = drawPLightICallback;
			r.setup = setupPLightCallback;
			r.datasize = sizeof(renderPLightCallbackData_t);
			r.data = &pl;
		}
		addRenderlistitem(q, r);
	}
	for(i = 0; i < out.lout.count; i++){
		//check if its spot or not
		if(out.lout.list[i]->type ==2){
			matrix4x4_t ct;
			Matrix4x4_Concatsimdu(&ct, &v->viewproj, &out.lout.list[i]->camproj);
			Matrix4x4_ToArrayFloatGL(&ct, sl.light.mvp);
			sl.light.size = out.lout.list[i]->scale;
			Matrix4x4_Concatsimdu(&ct, &v->view, &out.lout.list[i]->camproj);
			Matrix4x4_ToArrayFloatGL(&ct, sl.light.mv);
			Matrix4x4_ToArrayFloatGL(&out.lout.list[i]->viewproj, sl.light.lmv);
			sl.light.pos[0] = out.lout.list[i]->pos[0];
			sl.light.pos[1] = out.lout.list[i]->pos[1];
			sl.light.pos[2] = out.lout.list[i]->pos[2];

			r.draw = drawSLightOCallback;
			r.setup = setupSLightCallback;
			r.datasize = sizeof(renderSLightCallbackData_t);
			r.data = &sl;
		} else {
			pl.light.size = out.lout.list[i]->scale;
			pl.light.pos[0] = out.lout.list[i]->pos[0];
			pl.light.pos[1] = out.lout.list[i]->pos[1];
			pl.light.pos[2] = out.lout.list[i]->pos[2];
			r.draw = drawPLightOCallback;
			r.setup = setupPLightCallback;
			r.datasize = sizeof(renderPLightCallbackData_t);
			r.data = &pl;
		}
		addRenderlistitem(q, r);
	}

	//todo
	//gotta free the list!
	if(out.lout.list) free(out.lout.list);
	if(out.lin.list) free(out.lin.list);
	return TRUE;
}