当前位置: 首页>>代码示例>>C++>>正文


C++ ShaderProgram::getConstantByName方法代码示例

本文整理汇总了C++中ShaderProgram::getConstantByName方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::getConstantByName方法的具体用法?C++ ShaderProgram::getConstantByName怎么用?C++ ShaderProgram::getConstantByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShaderProgram的用法示例。


在下文中一共展示了ShaderProgram::getConstantByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: nativeRender

	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);
	}
开发者ID:Nlcke,项目名称:gideros,代码行数:31,代码来源:gcameraplugin.cpp

示例2: setConstant

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;
}
开发者ID:popcade,项目名称:gideros,代码行数:86,代码来源:shaderbinder.cpp


注:本文中的ShaderProgram::getConstantByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。