Exemple #1
0
	virtual void pull() override
	{
		PlaceProgram::pull();
		source = getUniform("uSource");
		factor = getUniform("uFactor");
		delta = getUniform("uDelta");
	}
Exemple #2
0
	virtual void pull() override
	{
		PlaceProgram::pull();
        velocity = getUniform("uVelocity");
        delta = getUniform("uDelta");
        force = getUniform("uForce");
	}
Exemple #3
0
void Shader::setUniforms()
{
	// Note: m_proj is (er, should be) guaranteed to exist by GameManager.
	glUniformMatrix4fv(getUniform("ModelViewMatrix"), 1, false, glm::value_ptr(m_model->matrix));
	glUniformMatrix4fv(getUniform("ProjectionMatrix"), 1, false, glm::value_ptr(m_proj->matrix));
	
	glUniform1i(getUniform("Texture0"), 0);
}
Exemple #4
0
void Shader::loadUniform(int uni, int texture, TextureStorage store) {
    if ((Render::getMode() == RenderMode::Solid)
        && (store == TextureStorage::GAME)) {
        gl::glUniform1i(getUniform(uni), TextureManager::bindTexture(TEXTURE_SPLASH,
                        TextureStorage::SYSTEM));
    } else {
        gl::glUniform1i(getUniform(uni), TextureManager::bindTexture(texture, store));
    }
}
Exemple #5
0
void inciarlizar_motor_render(float m_viewWidth, float m_viewHeight){

    glClearColor(0.1f, 0.2f, 0.0f, 1.0f);
    
    glUseProgram(_program);
    
    
    _shd_posicion = getParametro( "position");
    _shd_normal    = getParametro( "normal");
    _shd_textura  = getParametro("textura_cord");
    _shd_mvp      = getUniform( "MVP");
    _shd_text     = getUniform("textura");
    
    // Enable depth test
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    /*
        Perspectiva
     */
    mtxLoadPerspective(mPerspectiva, 45, (float)m_viewWidth / (float)m_viewHeight,1.0,10000);
    mtxLoadIdentity(mModelo);
    
    
    /*
        Camara
     4.0f, 3.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f)
     */
    
    
    
    float vecEye[3] = {2.0f, 0.0f, 3.0f};
    float vecCentro[3] = {0.0, 0.0, 0.0};
    float vecUp[3] = {0.0, 1.0, 0.0};
    
    mtxLookAt(mModeloCamara, vecEye, vecCentro, vecUp);
    
    
    
    //colocamos el modelo en las cordenadas 0.0f en la x,y,z
	mtxTranslateApply(mModelo, 0.0f, 0.0f, 0.0f);

    
    crear_buffers();
    
    long witdh = 0.0f, height = 0.0f;
    textura_id = load_texture_TGA(PATH_TEXTURA, &witdh, &height, GL_REPEAT, GL_REPEAT);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, textura_id);
    glUseProgram(0);
    
}
Exemple #6
0
void CGLSLProgram::loadUniformMatrix(const string name, const GLint size, const GLfloat* pointer){

	switch (size){

	case nGLSLProgram::GLSLUniform::UNIFORM_SIZE_3X3:
		glUniformMatrix3fv(getUniform(name), 1, GL_FALSE, pointer);
		break;
	case nGLSLProgram::GLSLUniform::UNIFORM_SIZE_4X4:
		glUniformMatrix4fv(getUniform(name), 1, GL_FALSE, pointer);
		break;

	}

}
void Scene::onPolyhedronChanged()
{
    // Update Polyhedron
    auto symbol = "#" + wild::conversion_cast<std::string>(wild::mod(_index, 80) + 1);

    _pgeometry->setSymbol(symbol);
    _pgeometry->setFaceMask(static_cast<osgKaleido::PolyhedronGeometry::FaceMask>(_faces));

    auto polyhedron = _pgeometry->getOrCreatePolyhedron();

    OSG_INFO << polyhedron->getName() << " (" << polyhedron->getDualName() << "*)" << std::endl;
    OSG_INFO << polyhedron->getWythoffSymbol() << std::endl;
    OSG_INFO << polyhedron->getVertexConfiguration() << std::endl;
    OSG_INFO << polyhedron->getVertexCount() << std::endl;
    OSG_INFO << polyhedron->getFaceCount() << std::endl;

    // Update Vertices
    osg::ref_ptr<osg::Vec3Array> vertices = osgKaleido::createVertexArray(*polyhedron);

    auto stateSet = _vgeode->getOrCreateStateSet();
    auto offsets = stateSet->getUniform("offsets");

    copy(offsets, vertices, osg::Vec3());

    // Update Text
    _text->setText(polyhedron->getName() + "\n" + polyhedron->getWythoffSymbol());
}
void Program::setColor(FloatColor color) {
    if (!mHasColorUniform) {
        mColorUniform = getUniform("color");
        mHasColorUniform = true;
    }
    glUniform4f(mColorUniform, color.r, color.g, color.b, color.a);
}
StandardShaderProgram::StandardShaderProgram(std::string vertexCode, std::string fragmentCode) :
		ShaderProgram(vertexCode, fragmentCode) {

	vertexPointer = getAttribute("vPosition");
	colorPointer = getAttribute("vColor");
	mvpMatrixPointer = getUniform("mvp_matrix");

}
void Program::use() {
    glUseProgram(mProgramId);
    if (texCoords >= 0 && !mHasSampler) {
        glUniform1i(getUniform("baseSampler"), 0);
        mHasSampler = true;
    }
    mUse = true;
}
Exemple #11
0
 void GLProgram::setUniform1i(const char* uniform, int v1) const
 {
     use();
     GLint location = getUniform(uniform);
     if(location != -1) {
         glUniform1i(location, v1);
         CHECK_GL_ERROR_DEBUG();
     }        
 }
Exemple #12
0
 void GLProgram::setUniform4f(const char* uniform, float v1, float v2, float v3, float v4) const
 {
     use();
     GLint location = getUniform(uniform);
     if(location != -1) {
         glUniform4f(location, v1, v2, v3, v4);
         CHECK_GL_ERROR_DEBUG();
     }        
 }
Exemple #13
0
 void GLProgram::setUniform4x4f(const char* uniform, fzUInt count, bool transpose, float *matrix) const
 {
     use();
     GLint location = getUniform(uniform);
     if(location != -1) {
         glUniformMatrix4fv(location, count, transpose, matrix);
         CHECK_GL_ERROR_DEBUG();
     }
 }
Exemple #14
0
	void Shader::setUniform( const std::string &name, float v0, float v1, float v2, float v3 )
	{
		AttributePtr u = getUniform(name);
		if(!u)
		{
			u = Attribute::createVec4f();
			u->appendElement<float>(v0,v1,v2,v3);
			setUniform(name, u);
		}else
			u->set<float>(0, v0, v1, v2, v3);
	}
Exemple #15
0
	void Shader::setUniform( const std::string &name, math::Matrix44f value )
	{
		AttributePtr u = getUniform(name);
		if(!u)
		{
			u = Attribute::createMat44();
			u->appendElement<math::Matrix44f>(value);
			setUniform(name, u);
		}else
			u->set<math::Matrix44f>(0, value);
	}
Exemple #16
0
	void Shader::setUniform( const std::string &name, int value )
	{
		AttributePtr u = getUniform(name);
		if(!u)
		{
			u = Attribute::createInt();
			u->appendElement<int>(value);
			setUniform(name, u);
		}else
			u->set<int>(0, value);
	}
Exemple #17
0
void CGLSLProgram::loadUniformf(const string name, const GLint size, const GLfloat* pointer){

	switch (size){

	case nGLSLProgram::GLSLUniform::UNIFORM_SIZE_1D:
		glUniform1f(getUniform(name), pointer[0]);
		break;
	case nGLSLProgram::GLSLUniform::UNIFORM_SIZE_2D:
		glUniform2f(getUniform(name), pointer[0], pointer[1]);
		break;
	case nGLSLProgram::GLSLUniform::UNIFORM_SIZE_3D:
		glUniform3f(getUniform(name), pointer[0], pointer[1], pointer[2]);
		break;
	case nGLSLProgram::GLSLUniform::UNIFORM_SIZE_4D:
		glUniform4f(getUniform(name), pointer[0], pointer[1], pointer[2], pointer[3]);
		break;

	}

}
Exemple #18
0
 void GLProgram::setUniform4fv(const char* uniform, fzUInt count, float* values) const
 {
     if(count == 0)
         return;
     use();
     GLint location = getUniform(uniform);
     if(location != -1) {
         glUniform4fv(location, count, values);
         CHECK_GL_ERROR_DEBUG();
     }
 }
void renderer::setTexture(string name,unsigned int texTarget,GLuint number,GLuint& texture)
{
    GLint v;
    glActiveTexture(number - GL_TEXTURE0+GL_TEXTURE0);
    //glBindTexture(texture);
    glBindTexture(GL_TEXTURE_2D,texture);
    getUniform(name,v);
    //glEnable(GL_TEXTURE_2D);
    glUniform1i(v, number - GL_TEXTURE0);


};
// Getting random structures (Template Method pattern)
Vector<double, long> UniformGenerator::getUniformVector(long N, double A, double B)
{ // Invariant part

	Vector<double, long> vec(N);

//#pragma omp parallel for shared(A, B)
	for(long i=vec.MinIndex(); i<=vec.MaxIndex();  ++i)
	{
		vec[i] = A + (B-A)* getUniform(); // Variant part
	}
	
	return vec;
}
Exemple #21
0
Lightmap::Lightmap(std::vector<glm::vec2> coords,std::vector<GLuint> indexes)
{
    GL_CHECK(glGenVertexArrays(1, &_vao));
    GL_CHECK(glBindVertexArray(_vao));

    // generate VBOs for verts and tex
    GL_CHECK(glGenBuffers(1, &_coords));
    GL_CHECK(glGenBuffers(1, &_lights));
    GL_CHECK(glGenBuffers(1, &_ebo));

    if (coords.size()<=0) return;

    GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _coords));
    //update coords
    GL_CHECK(glBufferData(GL_ARRAY_BUFFER, coords.size() * sizeof(glm::vec2), &coords[0], GL_STATIC_DRAW));


    GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _lights));
    //update texcoords
//    GL_CHECK(glBufferData(GL_ARRAY_BUFFER, textureCoords.size() * sizeof(glm::vec2), &textureCoords[0], GL_STATIC_DRAW));

    GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo));
    // update indexes
    GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexes.size() * sizeof(GLuint), &indexes[0], GL_DYNAMIC_DRAW));
    _indexes = indexes.size();

    GL_CHECK(glBindVertexArray(0));

    auto shader = ResourceManager::getInstance()->shader("lightmap");

    _uniformFade = shader->getUniform("fade");
    _uniformMVP = shader->getUniform("MVP");
    _uniformOffset = shader->getUniform("offset");

    _attribPos = shader->getAttrib("Position");
    _attribLights = shader->getAttrib("lights");
}
Exemple #22
0
void gDrawRing(GContext *context, float in)
{
	Program *prog = context->programs.ring;
	glUseProgram(prog->id);
	{
		setVectorUniforms(prog,context->translation,context->modelview_matrix,context->projection_matrix);
		setColorUniform(prog,context->color);
		glUniform1fv(getUniform(prog,U_INNER_MUL), 1, &in);
		
		drawArray(context, prog);
	}
	glUseProgram(0);
#ifdef DEBUG
	checkError();
#endif
}
Exemple #23
0
void gDrawImage(GContext *context, GImage *image)
{
	Program *prog = context->programs.tex;
	glUseProgram(prog->id);
	{
		setVectorUniforms(prog,context->translation,context->modelview_matrix,context->projection_matrix);
		setColorUniform(prog,context->color);
		
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, image->_id);
		glUniform1i(getUniform(prog,U_TEXTURE),0);
		
		drawArray(context, prog);
	}
	glUseProgram(0);
#ifdef DEBUG
	checkError();
#endif
}
 void getUniform(fmat3* value) { getUniform(value->ptr()); }
const Uniform& ShaderVariableManager::getUniform(
		const UniformDescription& desc) const {
	return getUniform(desc.getId());
}
 void getUniform(uvec2* value) { getUniform(value->ptr()); }
 void getUniform(fvec3* value) { getUniform(value->ptr()); }
 void getUniform(dvec4* value) { getUniform(value->ptr()); }
 void getUniform(dmat4* value) { getUniform(value->ptr()); }
Exemple #30
0
static int getActiveUniforms(ShaderProgram *shader)
{
	GLint maxLength;
	char *name = NULL;
	int i, error, numBaseUniforms, n;
	ActiveUniform *baseUniforms = NULL;

	ORIG_GL(glGetProgramiv)(shader->programHandle, GL_ACTIVE_UNIFORMS,
	                        &numBaseUniforms);
	ORIG_GL(glGetProgramiv)(shader->programHandle, GL_ACTIVE_UNIFORM_MAX_LENGTH,
	                        &maxLength);
	error = glError();
	if (error) {
		shader->numUniforms = 0;
		return error;
	}

	if (!(name = (char*)malloc(maxLength*sizeof(char)))) {
		dbgPrint(DBGLVL_ERROR, "Allocation failed: uniform name\n");
		shader->numUniforms = 0;
		return DBG_ERROR_MEMORY_ALLOCATION_FAILED;
	}

	dbgPrint(DBGLVL_INFO, "ACTIVE UNIFORMS: %i\n", numBaseUniforms);

	if (!(baseUniforms = (ActiveUniform*)malloc(numBaseUniforms*sizeof(ActiveUniform)))) {
		dbgPrint(DBGLVL_ERROR, "Allocation failed: base uniforms\n");
		shader->numUniforms = 0;
		free(name);
		return DBG_ERROR_MEMORY_ALLOCATION_FAILED;
	}

	shader->numUniforms = 0;

	for (i = 0; i < numBaseUniforms; i++) {
		ActiveUniform *u = &baseUniforms[i];
		ORIG_GL(glGetActiveUniform)(shader->programHandle, i, maxLength, NULL,
		                            &u->size, &u->type, name);
		error = glError();
		if (error) {
			free(name);
			free(baseUniforms);
			shader->numUniforms = 0;
			return error;
		}
		dbgPrint(DBGLVL_INFO, "FOUND UNIFORM: %s size=%i type=%s\n",
				name, u->size, lookupEnum(u->type));
		if (!strncmp(name, "gl_", 3)) {
			u->builtin = 1;
		} else {
			if (!(u->name = strdup(name))) {
				dbgPrint(DBGLVL_ERROR, "Allocation failed: uniform name\n");
				free(name);
				free(baseUniforms);
				shader->numUniforms = 0;
				return DBG_ERROR_MEMORY_ALLOCATION_FAILED;
			}
			u->builtin = 0;
			shader->numUniforms += u->size;
		}
	}

	free(name);

	if (!(shader->uniforms = (ActiveUniform*)malloc(shader->numUniforms*sizeof(ActiveUniform)))) {
		dbgPrint(DBGLVL_ERROR, "Allocation failed: uniforms\n");
		shader->numUniforms = 0;
		free(baseUniforms);
		return DBG_ERROR_MEMORY_ALLOCATION_FAILED;
	}

	n = 0;
	for (i = 0; i < numBaseUniforms; i++) {
		ActiveUniform *bu = &baseUniforms[i];
		if (!bu->builtin) {

			if (bu->size == 1) {
				ActiveUniform *u = &shader->uniforms[n];
				u->type = bu->type;
				u->size = 1;
				u->builtin = 0;
				u->value = NULL;
				if (!(u->name = strdup(bu->name))) {
					dbgPrint(DBGLVL_ERROR, "Allocation failed: uniform name\n");
					free(baseUniforms);
					shader->numUniforms = n;
					return DBG_ERROR_MEMORY_ALLOCATION_FAILED;
				}
				u->location = ORIG_GL(glGetUniformLocation)(shader->programHandle,
							u->name);
				error = glError();
				if (error) {
					free(baseUniforms);
					free(u->name);
					shader->numUniforms = n;
					return error;
				}
				dbgPrint(DBGLVL_INFO, "SAVE UNIFORM: %s size=%i type=%s location=%i\n",
				         u->name, u->size, lookupEnum(u->type), u->location);
				error = getUniform(shader->programHandle, u);
				if (error) {
					free(u->name);
					free(baseUniforms);
					shader->numUniforms = n;
					return error;
				}
				n++;
			} else {
				int j;
				for (j = 0; j < bu->size; j++) {
					ActiveUniform *u = &shader->uniforms[n];
					u->type = bu->type;
					u->size = 1;
					u->builtin = 0;
					u->value = NULL;
					if (asprintf(&u->name, "%s[%i]", bu->name, j) < 0) {
						dbgPrint(DBGLVL_ERROR, "Allocation failed: uniform name\n");
						free(baseUniforms);
						shader->numUniforms = n;
						return DBG_ERROR_MEMORY_ALLOCATION_FAILED;
					}
					u->location = ORIG_GL(glGetUniformLocation)(shader->programHandle,
							u->name);
					error = glError();
					if (error) {
						free(baseUniforms);
						free(u->name);
						shader->numUniforms = n;
						return error;
					}
					dbgPrint(DBGLVL_INFO, "SAVE UNIFORM: %s size=%i type=%s location=%i\n",
							u->name, u->size, lookupEnum(u->type), u->location);
					error = getUniform(shader->programHandle, u);
					if (error) {
						free(u->name);
						free(baseUniforms);
						shader->numUniforms = n;
						return error;
					}
					n++;
				}
			}
		}
	}
	free(baseUniforms);
	return DBG_NO_ERROR;
}