コード例 #1
0
ファイル: gcameraplugin.cpp プロジェクト: Nlcke/gideros
	void nativeRender(int camtex, float *mat) {
		if (!running) return;
		ShaderEngine::Engine->reset();
		ShaderBuffer *oldfbo = ShaderEngine::Engine->setFramebuffer(rdrTgt);
		ShaderEngine::Engine->setViewport(0, 0, tex->width, tex->height);
		Matrix4 projection = ShaderEngine::Engine->setOrthoFrustum(0,
				tex->baseWidth, 0, tex->baseHeight, -1, 1);
		ShaderEngine::Engine->setProjection(projection);
		Matrix4 model;
		ShaderEngine::Engine->setModel(model);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_EXTERNAL_OES, camtex);

		shader->setConstant(shader->getConstantByName("tMatrix"),
				ShaderProgram::CMATRIX, 1, mat);
		shader->setData(ShaderProgram::DataVertex, ShaderProgram::DFLOAT, 2,
				&vertices[0], vertices.size(), vertices.modified,
				&vertices.bufferCache);
		shader->setData(ShaderProgram::DataTexture, ShaderProgram::DFLOAT, 2,
				&texcoords[0], texcoords.size(), texcoords.modified,
				&texcoords.bufferCache);
		shader->drawElements(ShaderProgram::TriangleStrip, indices.size(),
				ShaderProgram::DUSHORT, &indices[0], indices.modified,
				&indices.bufferCache);
		vertices.modified = false;
		texcoords.modified = false;
		indices.modified = false;

		ShaderEngine::Engine->setFramebuffer(oldfbo);
	}
コード例 #2
0
ファイル: shaderbinder.cpp プロジェクト: popcade/gideros
int ShaderBinder::setConstant(lua_State* L)
{
	StackChecker checker(L, "ShaderBinder::setConstant", 0);

	Binder binder(L);

	ShaderProgram* shd = static_cast<ShaderProgram*>(binder.getInstance("Shader", 1));

   // virtual void setConstant(int index,ConstantType type,const void *ptr);

	int idx=-1;
	if (lua_isstring(L,2))
	{
		idx=shd->getConstantByName(luaL_checkstring(L,2));
	}
	else
		idx = luaL_checknumber(L, 2);

	if (idx<0)
	{
		lua_pushstring(L,"Shader has no constant of that name/index");
		lua_error(L);
	}
	ShaderProgram::ConstantType type = (ShaderProgram::ConstantType) luaL_checkinteger(L, 3);
	int mult = luaL_checknumber(L, 4);
	int cm=1;
	switch (type)
	{
	case ShaderProgram::CFLOAT4: cm=4; break;
	case ShaderProgram::CMATRIX: cm=16; break;
	default: cm=1;
	}

	cm*=mult;
	switch (type)
	{
	case ShaderProgram::CINT:
	{
		int *m=(int *) malloc(sizeof(int)*cm);
		if (lua_istable(L,5))
		{
			for (int k=0;k<cm;k++)
			{
				lua_rawgeti(L, 5, k+1);
				m[k]=luaL_checkinteger(L,-1);
				lua_pop(L,1);
			}
		}
		else
		{
			for (int k=0;k<cm;k++)
				m[k]=luaL_checkinteger(L,5+k);
		}
		shd->setConstant(idx,type,mult,m);
		free(m);
		break;
	}
	case ShaderProgram::CFLOAT:
	case ShaderProgram::CFLOAT4:
	case ShaderProgram::CMATRIX:
	{
		float *m=(float *) malloc(sizeof(float)*cm);
		if (lua_istable(L,5))
		{
			for (int k=0;k<cm;k++)
			{
				lua_rawgeti(L, 5, k+1);
				m[k]=luaL_checknumber(L,-1);
				lua_pop(L,1);
			}
		}
		else
		{
			for (int k=0;k<cm;k++)
				m[k]=luaL_checknumber(L,5+k);
		}
		shd->setConstant(idx,type,mult,m);
		free(m);
		break;
	}
	case ShaderProgram::CTEXTURE:
		break;
	}

	return 0;
}