Ejemplo n.º 1
0
	void TextBox::display(int translateDistanceLoc, float invFrameRate)
	{
		//display the text box
		glBindTexture(GL_TEXTURE_2D, textureID);

		quadDisplayer->display();

		//displays the cursor
		static float blink=0.0;
		blink+=invFrameRate*cursorBlinkSpeed;
		if(state==ACTIVE && ((int)blink%2)>0)
		{
			glUniform2iv(translateDistanceLoc, 1, (const int*)(getTranslateDistance() + Vector2<int>(cursorPosition, 0)));
			glBindTexture(GL_TEXTURE_2D, 0);

			glDisable(GL_DEPTH_TEST);
			glDepthMask(GL_FALSE);

			glBindVertexArray(cursorLineVAO);
			glDrawArrays(GL_LINES, 0, 2);

			glDepthMask(GL_TRUE);
			glEnable(GL_DEPTH_TEST);

			glUniform2iv(translateDistanceLoc, 1, (const int*)getTranslateDistance());
		}

		//displays children
		Widget::display(translateDistanceLoc, invFrameRate);
	}
void Renderer::LoadWireFrameShader(const Desc & /*desc*/)
{
	PRINT_MESSAGE("Initialize Perlin Noise Ocean Renderer (Wire Frame) Shaders : .....");

	const char * uniformNames[] =
	{
		"u_PatchCount",
		"u_MapSize",
		"u_HeightMapTextureSize",
		"u_MaxAmplitude",
		"u_HeightMapSampler",
		"u_PerMapDataSampler",
	};


	//setup shader
	mWireFrameShader.LoadFromFile(GL_VERTEX_SHADER, "shaders/HeightFieldOcean.vs.glsl");

	mWireFrameShader.LoadFromFile(GL_TESS_CONTROL_SHADER, "shaders/HeightFieldOcean.tcs.glsl");

	mWireFrameShader.LoadFromFile(GL_TESS_EVALUATION_SHADER, "shaders/PerlinNoiseOcean.tes.glsl");

	//mWireFrameShader.LoadFromFile(GL_GEOMETRY_SHADER, "shaders/HeightFieldOcean.gs.glsl");

	mWireFrameShader.LoadFromFile(GL_FRAGMENT_SHADER, "shaders/HeightFieldOcean.wireframe.fs.glsl");

	mWireFrameShader.CreateAndLinkProgram();
	mWireFrameShader.Use();

	mWireFrameShader.AddUniforms(uniformNames, 6);

	//pass values of constant uniforms at initialization
	glUniform2iv(mWireFrameShader.GetUniform(u_PatchCount), 1, glm::value_ptr(mPatchCount)); GL_CHECK_ERRORS;
	glUniform2iv(mWireFrameShader.GetUniform(u_MapSize), 1, glm::value_ptr(mMapSize)); GL_CHECK_ERRORS;
	glUniform2iv(mShader.GetUniform(u_HeightMapTextureSize), 1, glm::value_ptr(mHeightMapTextureSize)); GL_CHECK_ERRORS;
	glUniform1f(mShader.GetUniform(u_MaxAmplitude), mHeightMapCS->GetMaxAmplitude()); GL_CHECK_ERRORS;
	glUniform1i(mWireFrameShader.GetUniform(u_HeightMapSampler), 0); GL_CHECK_ERRORS;
	glUniform1i(mWireFrameShader.GetUniform(u_PerMapDataSampler), 1); GL_CHECK_ERRORS;

	//GetWavePropertyUniformIndex(mWireFrameShader, mWireFrameShaderWaveProps);

	mWireFrameShader.SetupFrameDataBlockBinding();
	mWireFrameShader.UnUse();

	GL_CHECK_ERRORS;

	PRINT_MESSAGE(".....done.");
}
Ejemplo n.º 3
0
void ShaderProgram::sendUniform2i(GLint location, vec2 v)
{
	bind();
	int a[] = { v.x, v.y };
	glUniform2iv(location, 2, a);
	unbind();
}
/** bind uniform array of int-scalars/vectors
 */
void FragmentProgram::BindInt(string parameterName, vector<vector<int> > intvectors) {
    if (intvectors.size() == 0) return;

    int vectorsize = intvectors.at(0).size();
    if (vectorsize < 1 || vectorsize > 4) throw PPEResourceException("GLSL doesn't have a ivecX type, with the supplied X!");

    // create a C array of all the intvector-values (to be supplied to OpenGL)
      GLint* intarray = new GLint[vectorsize * intvectors.size()];

    for (unsigned int i=0; i<intvectors.size(); i++) {
        vector<int> intvector = intvectors.at(i);
	if (intvector.size() != vectorsize) throw PPEResourceException("all vectors in an array must have the same size!");
	for (unsigned int j=0; j<vectorsize; j++)
	    intarray[i*vectorsize + j] = intvector.at(j);
    }


    GuardedBind();

    // get input parameter handle by name
    GLint paramID = glGetUniformLocation(programID, parameterName.c_str());
    if (paramID == -1) logger.error << "uniform \"" << parameterName << "\" does not exist" << logger.end;

    // set value of variable (type: float, float2, float3, float4)
    if (vectorsize==1) glUniform1iv(paramID, intvectors.size(), intarray); // see: http://www.thescripts.com/forum/thread394740.html
    if (vectorsize==2) glUniform2iv(paramID, intvectors.size(), intarray); // see: http://developer.3dlabs.com/documents/glmanpages/glUniform.htm
    if (vectorsize==3) glUniform3iv(paramID, intvectors.size(), intarray);
    if (vectorsize==4) glUniform4iv(paramID, intvectors.size(), intarray);

    GuardedUnbind();

    delete intarray;
}
Ejemplo n.º 5
0
	void GUIRenderer::display(float dt)
	{
		ScopeProfiler profiler("3d", "uiRenderDisplay");

		ShaderManager::instance()->bind(GUIShader);
		glUniform1i(diffuseTexSamplerLoc, 0);

		glActiveTexture(GL_TEXTURE0);

		for (auto &widget : widgets)
		{
			if(widget->isVisible())
			{
				Vector2<int> translateVector(widget->getGlobalPositionX(), widget->getGlobalPositionY());
				glUniform2iv(translateDistanceLoc, 1, (const int*)translateVector);

				widget->display(translateDistanceLoc, dt);
			}
		}

		#ifdef _DEBUG
//			//display font texture
//			Font *font = MediaManager::instance()->getMedia<Font>("font/font.fnt");
//
//			TextureDisplayer textureDisplayer(font->getTextureID(), TextureDisplayer::DEFAULT_VALUE);
//			textureDisplayer.setPosition(TextureDisplayer::USER_DEFINED_X, TextureDisplayer::USER_DEFINED_Y);
//			textureDisplayer.setSize(20.0, font->getDimensionTexture() + 20.0, 20.0, font->getDimensionTexture() + 20.0);
//			textureDisplayer.initialize(512, 512, -1.0, -1.0);
//			textureDisplayer.display();
//			font->release();
		#endif
	}
Ejemplo n.º 6
0
	void GUIRenderer::display(float invFrameRate)
	{
		ShaderManager::instance()->bind(GUIShader);
		glUniform1i(diffuseTexSamplerLoc, 0);

		glActiveTexture(GL_TEXTURE0);

		for(unsigned int i=0;i<widgets.size();++i)
		{
			if(widgets[i]->isVisible())
			{
				Vector2<int> translateVector(widgets[i]->getGlobalPositionX(), widgets[i]->getGlobalPositionY());
				glUniform2iv(translateDistanceLoc, 1, (const int*)translateVector);

				widgets[i]->display(translateDistanceLoc, invFrameRate);
			}
		}

		#ifdef _DEBUG
			//display font texture
//			std::shared_ptr<XmlChunk> fontChunk = GUISkinService::instance()->getXmlSkin()->getUniqueChunk(true, "text", XmlAttribute("nameSkin", "defaultSkin"));
//			std::shared_ptr<XmlChunk> fileFontChunk = GUISkinService::instance()->getXmlSkin()->getUniqueChunk(true, "ttf", XmlAttribute(), fontChunk);
//			std::shared_ptr<XmlChunk> sizeFontChunk = GUISkinService::instance()->getXmlSkin()->getUniqueChunk(true, "size", XmlAttribute(), fontChunk);
//			Font *font = MediaManager::instance()->getMedia<Font>(fileFontChunk->getStringValue(), (void*) sizeFontChunk->getIntValue());
//
//			TextureDisplayer textureDisplayer(font->getTextureID(), TextureDisplayer::DEFAULT_VALUE);
//			textureDisplayer.setPosition(TextureDisplayer::USER_DEFINED_X, TextureDisplayer::USER_DEFINED_Y);
//			textureDisplayer.setSize(20.0, font->getDimensionTexture() + 20.0, 20.0, font->getDimensionTexture() + 20.0);
//			textureDisplayer.initialize(width, height, -1.0, -1.0);
//			textureDisplayer.display();
//			font->release();
		#endif
	}
Ejemplo n.º 7
0
		void Uniform2iv(
			const GLint Location,
			const GLsizei Count,
			const GLint* const Value)
		{
			glUniform2iv(Location, Count, Value);
		}
Ejemplo n.º 8
0
void HZMap::build(){
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glBindTexture(GL_TEXTURE_2D, texture);
    int numLevels = 1 + (int)glm::floor(glm::log2(glm::max((float)width, (float)height)));
    
    int cWidth = width;
    int cHeight = height;
    for (int i = 1; i < numLevels; i++) {
        HZMbuilder->use();
        glUniform2iv(HZMbuilder->getUniform("lastMipSize"),1,
                     glm::value_ptr(glm::ivec2(cWidth,cHeight)));

        cWidth /= 2;
        cHeight /= 2;
        cWidth = (cWidth > 0) ? cWidth : 1;
        cHeight = (cHeight > 0) ? cHeight : 1;
        
        glViewport(0,0,cWidth,cHeight);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, i-1);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, i-1);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture, i);
        
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        
        CHECK_GL_ERRORS();
        CHECK_GL_FBO_COMPLETENESS();
        
        // Render full screen quad
        quad->render(HZMbuilder);
    }
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, numLevels-1);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Ejemplo n.º 9
0
void Shader::setUniform2Array(const char* varname, const int* input, const int count)
{
	GLint loc = getLocation(varname, &locations);
	CHECK_SHADER_VAR(loc,varname);
	glUniform2iv(loc,count,input);
	assert (glGetError() == GL_NO_ERROR);
}
Ejemplo n.º 10
0
	void OGLESRenderEngine::Uniform2iv(GLint location, GLsizei count, GLint const * value)
	{
		bool dirty = false;
		KLAYGE_AUTO(iter_p, uniformi_cache_.find(cur_program_));
		if (iter_p == uniformi_cache_.end())
		{
			dirty = true;
			iter_p = uniformi_cache_.insert(std::make_pair(cur_program_, std::map<GLint, int4>())).first;
		}
		for (GLsizei i = 0; i < count; ++ i)
		{
			KLAYGE_AUTO(iter_v, iter_p->second.find(location + i));
			if (iter_v == iter_p->second.end())
			{
				dirty = true;
				iter_p->second.insert(std::make_pair(location, int4(value[i * 2 + 0], value[i * 2 + 1], 0, 0)));
			}
			else
			{
				if ((iter_v->second.x() != value[i * 2 + 0]) || (iter_v->second.y() != value[i * 2 + 1]))
				{
					dirty = true;
					iter_v->second.x() = value[i * 2 + 0];
					iter_v->second.y() = value[i * 2 + 1];
				}
			}			
		}

		if (dirty)
		{
			glUniform2iv(location, count, value);
		}
	}
Ejemplo n.º 11
0
void
cogl_program_uniform_int (int  uniform_no,
                          int     size,
                          int     count,
                          const int *value)
{
  _COGL_GET_CONTEXT (ctx, NO_RETVAL);

  switch (size)
    {
    case 1:
      glUniform1iv (uniform_no, count, value);
      break;
    case 2:
      glUniform2iv (uniform_no, count, value);
      break;
    case 3:
      glUniform3iv (uniform_no, count, value);
      break;
    case 4:
      glUniform4iv (uniform_no, count, value);
      break;
    default:
      g_warning ("%s called with invalid size parameter", G_STRFUNC);
    }
}
Ejemplo n.º 12
0
inline void Program::Uniform(GLint location, GLsizei count, const glm::ivec2 *value)
{
	GL_ASSERT(m_id > 0);
	GL_ASSERT(location >= 0);

	glUniform2iv(location, count, glm::value_ptr(*value));
}
Ejemplo n.º 13
0
	inline bool CShader::setArray<CVector2i>( const std::string & pName, int count, const CVector2i * v) const
	{
		const GLint iP= getParamLocation(pName);
		if (iP < 0) return false;
		glUniform2iv(iP, static_cast<const GLint>(count), (const GLint*)(v));CHECK_GLERROR("");
		return true;
	}
Ejemplo n.º 14
0
static bool glsl_set_shader_int_vector(ALLEGRO_SHADER *shader,
   const char *name, int num_components, int *i, int num_elems)
{
   ALLEGRO_SHADER_GLSL_S *gl_shader = (ALLEGRO_SHADER_GLSL_S *)shader;
   GLint handle;

   handle = glGetUniformLocation(gl_shader->program_object, name);

   if (handle < 0) {
      ALLEGRO_WARN("No uniform variable '%s' in shader program\n", name);
      return false;
   }

   switch (num_components) {
      case 1:
         glUniform1iv(handle, num_elems, i);
         break;
      case 2:
         glUniform2iv(handle, num_elems, i);
         break;
      case 3:
         glUniform3iv(handle, num_elems, i);
         break;
      case 4:
         glUniform4iv(handle, num_elems, i);
         break;
      default:
         ASSERT(false);
         break;
   }

   return check_gl_error(name);
}
Ejemplo n.º 15
0
/**
 * Sets an uniform vector parameter.
 * \warning uses glGetError();
 * \param name - name of the parameter
 * \param i - an int vector containing up to 4 elements.
 * \return void
 * \author <a href="mailto:[email protected]">Jens Schneider</a>
 * \date Aug.2004
 */
void GLSLProgram::SetUniformVector(const char *name,const int *i) const {
  assert(m_bEnabled);
  CheckGLError();

  GLenum iType;
  GLint iLocation;

  try {
    iLocation = get_uniform_vector(name, m_hProgram, &iType);
  } catch(tuvok::GLError gl) {
    T_ERROR("Error (%d) obtaining uniform %s in '%s' or '%s'.", gl.errno(),
            name, m_sVS.c_str(), m_sFS.c_str());
    return;
  }

  switch (iType) {
    case GL_INT:
    case GL_SAMPLER_1D:
    case GL_SAMPLER_2D:
    case GL_SAMPLER_3D:
    case GL_SAMPLER_CUBE:
    case GL_SAMPLER_1D_SHADOW:
    case GL_SAMPLER_2D_SHADOW:
    case GL_SAMPLER_2D_RECT_ARB:
    case GL_SAMPLER_2D_RECT_SHADOW_ARB:  glUniform1i(iLocation,i[0]); break;

    case GL_INT_VEC2:          glUniform2iv(iLocation,1,(const GLint*)i); break;
    case GL_INT_VEC3:          glUniform3iv(iLocation,1,(const GLint*)i); break;
    case GL_INT_VEC4:          glUniform4iv(iLocation,1,(const GLint*)i); break;
#ifdef GLSL_ALLOW_IMPLICIT_CASTS
    case GL_BOOL:            glUniform1iv(iLocation,1,(const GLint*)i); break;
    case GL_BOOL_VEC2:          glUniform2iv(iLocation,1,(const GLint*)i); break;
    case GL_BOOL_VEC3:          glUniform3iv(iLocation,1,(const GLint*)i); break;
    case GL_BOOL_VEC4:          glUniform4iv(iLocation,1,(const GLint*)i); break;
    case GL_FLOAT:            glUniform1f(iLocation,float(i[0])); break;
    case GL_FLOAT_VEC2:          glUniform2f(iLocation,float(i[0]),float(i[1])); break;
    case GL_FLOAT_VEC3:          glUniform3f(iLocation,float(i[0]),float(i[1]),float(i[2])); break;
    case GL_FLOAT_VEC4:          glUniform4f(iLocation,float(i[0]),float(i[1]),float(i[2]),float(i[3])); break;
#endif
    default:
      T_ERROR("Unknown type (%d) for %s.", iType, name);
      break;
  }
#ifdef GLSL_DEBUG
  CheckGLError("SetUniformVector(%s,int*)",name);
#endif
}
Ejemplo n.º 16
0
void GFXGLShader::setConstantsFromBuffer(GFXGLShaderConstBuffer* buffer)
{
   for(Vector<GFXGLShaderConstHandle*>::iterator i = mValidHandles.begin(); i != mValidHandles.end(); ++i)
   {
      GFXGLShaderConstHandle* handle = *i;
      AssertFatal(handle, "GFXGLShader::setConstantsFromBuffer - Null handle");

      if(handle->mInstancingConstant)
         continue;
      
      // Don't set if the value has not be changed.
      if(dMemcmp(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize()) == 0)
         continue;
         
      // Copy new value into our const buffer and set in GL.
      dMemcpy(mConstBuffer + handle->mOffset, buffer->mBuffer + handle->mOffset, handle->getSize());
      switch(handle->mDesc.constType)
      {
         case GFXSCT_Float:
            glUniform1fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Float2:
            glUniform2fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Float3:
            glUniform3fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Float4:
            glUniform4fv(handle->mLocation, handle->mDesc.arraySize, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Int:
         case GFXSCT_Sampler:
         case GFXSCT_SamplerCube:
            glUniform1iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Int2:
            glUniform2iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Int3:
            glUniform3iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Int4:
            glUniform4iv(handle->mLocation, handle->mDesc.arraySize, (GLint*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Float2x2:
            glUniformMatrix2fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Float3x3:
            glUniformMatrix3fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         case GFXSCT_Float4x4:
            glUniformMatrix4fv(handle->mLocation, handle->mDesc.arraySize, true, (GLfloat*)(mConstBuffer + handle->mOffset));
            break;
         default:
            AssertFatal(0,"");
            break;
      }
   }
}
Ejemplo n.º 17
0
void GLSLProgram::setUniform2iv( const std::string & name, const GLint * value, const GLsizei count )
{
	const GLint loc = getUniformLocation( name );
	assert( value != 0 );
	assert( count != 0 );

	if ( loc != -1 )	glUniform2iv( loc, count, value );
}
Ejemplo n.º 18
0
void mitk::GPGPU::Shader::SetUniform(char *name,int i0,int i1)
{
  GLint i[2];
  i[0]=i0;
  i[1]=i1;
  glUniform2iv(  GetUniformLocation(name) , 1 , i );
  GPGPU_CHECKGLERR << "setting uniform";
}
Ejemplo n.º 19
0
/*!***************************************************************************
 @Function			SetDefaultSemanticValue
 @Input				pszName				name of uniform
 @Input				psDefaultValue      pointer to default value
 @Description		Sets the default value for the uniform semantic.
*****************************************************************************/
void CPVRTPFXEffect::SetDefaultUniformValue(const char *const pszName, const SPVRTSemanticDefaultData *psDefaultValue)
{
	GLint nLocation = glGetUniformLocation(m_uiProgram, pszName);

	switch(psDefaultValue->eType)
	{
		case eDataTypeMat2:
			glUniformMatrix2fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData);
			break;
		case eDataTypeMat3:
			glUniformMatrix3fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData);
			break;
		case eDataTypeMat4:
			glUniformMatrix4fv(nLocation, 1, GL_FALSE, psDefaultValue->pfData);
			break;
		case eDataTypeVec2:
			glUniform2fv(nLocation, 1, psDefaultValue->pfData);
			break;
		case eDataTypeVec3:
			glUniform3fv(nLocation, 1, psDefaultValue->pfData);
			break;
		case eDataTypeVec4:
			glUniform4fv(nLocation, 1, psDefaultValue->pfData);
			break;
		case eDataTypeIvec2:
			glUniform2iv(nLocation, 1, psDefaultValue->pnData);
			break;
		case eDataTypeIvec3:
			glUniform3iv(nLocation, 1, psDefaultValue->pnData);
			break;
		case eDataTypeIvec4:
			glUniform4iv(nLocation, 1, psDefaultValue->pnData);
			break;
		case eDataTypeBvec2:
			glUniform2i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0);
			break;
		case eDataTypeBvec3:
			glUniform3i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0, psDefaultValue->pbData[2] ? 1 : 0);
			break;
		case eDataTypeBvec4:
			glUniform4i(nLocation, psDefaultValue->pbData[0] ? 1 : 0, psDefaultValue->pbData[1] ? 1 : 0, psDefaultValue->pbData[2] ? 1 : 0, psDefaultValue->pbData[3] ? 1 : 0);
			break;
		case eDataTypeFloat:
			glUniform1f(nLocation, psDefaultValue->pfData[0]);
			break;
		case eDataTypeInt:
			glUniform1i(nLocation, psDefaultValue->pnData[0]);
			break;
		case eDataTypeBool:
			glUniform1i(nLocation, psDefaultValue->pbData[0] ? 1 : 0);
			break;

		case eNumDefaultDataTypes:
		case eDataTypeNone:
		default:
			break;
	}
}
Ejemplo n.º 20
0
void GLProgram::setUniformLocationWith2iv(GLint location, GLint* ints, unsigned int numberOfArrays)
{
    bool updated = updateUniformLocation(location, ints, sizeof(int)*2*numberOfArrays);

    if (updated)
    {
        glUniform2iv( (GLint)location, (GLsizei)numberOfArrays, ints );
    }
}
Ejemplo n.º 21
0
bool ShaderProgram::setUniformValue(const std::string& name, const Vector2i& v)
{
  GLint location = static_cast<GLint>(findUniform(name));
  if (location == -1) {
    m_error = "Could not set uniform " + name + ". No such uniform.";
    return false;
  }
  glUniform2iv(location, 1, v.data());
  return true;
}
Ejemplo n.º 22
0
void Shader::setIntN(const std::string &name, const void *data, int count)
{
    int location = glGetUniformLocation(mProgram, name.c_str());
    if(count == 1)
        glUniform1iv(location, 1, (int*)data);
    else if(count == 2)
        glUniform2iv(location, 1, (int*)data);
    else if(count == 3)
        glUniform3iv(location, 1, (int*)data);
    else if(count == 4)
        glUniform4iv(location, 1, (int*)data);
}
Ejemplo n.º 23
0
 void Shader::setUniform<glm::bvec2>(const std::string& name, const glm::bvec2& data) {
   int prev_bound_program;
   glGetIntegerv(GL_CURRENT_PROGRAM, &prev_bound_program);
   if(name_to_location.count(name) == 0) {
     throw Exceptions::InvalidUniformNameException(name);
   }
   if(prev_bound_program != program_object)
     useProgram();
   glUniform2iv(name_to_location[name], 1, glm::value_ptr(glm::ivec2(data)));
   if(prev_bound_program != program_object)
     glUseProgram(prev_bound_program);
 }
void GL3ProgramObjectProvider::set_uniformiv(int location, int size, int count, const int *data)
{
	throw_if_disposed();
	if (location >= 0)
	{
		ProgramObjectStateTracker state_tracker(handle);
		if( size == 1 ) glUniform1iv(location, count, data);	
		else if( size == 2 ) glUniform2iv(location, count, data);	
		else if( size == 3 ) glUniform3iv(location, count, data);	
		else if( size == 4 ) glUniform4iv(location, count, data);	
	}
}
Ejemplo n.º 25
0
 void SpriteShader::SetParameter(const std::string &parameterName, const IntVector2 &value)
 {
     if(pimpl->uniforms.find(parameterName) == pimpl->uniforms.end())
         throw std::runtime_error("Couldn't find the named SpriteEffect parameter: " + parameterName);
     
     auto &uniformData = pimpl->uniforms[parameterName];
     
     if(uniformData.type != GL_INT_VEC2)
         throw std::runtime_error("Type mismatch for named SpriteEffect paramater: " + parameterName);
     
     glUniform2iv(uniformData.location, 1, &value[0]);
 }
	bool COGLES2SLMaterialRenderer::setUniform( int index, const void* data, int count )
	{
		if ((u32)index>=UniformInfo.size())
			return false;
		SUniformInfo& ui = UniformInfo[index];
		if ( ui.location == -1 )
			return false;
		switch ( ui.type )
		{
			case GL_FLOAT:
				glUniform1fv( ui.location, count, static_cast<const GLfloat*>( data ) );
				break;
			case GL_FLOAT_VEC2:
				glUniform2fv( ui.location, count, static_cast<const GLfloat*>( data ) );
				break;
			case GL_FLOAT_VEC3:
				glUniform3fv( ui.location, count, static_cast<const GLfloat*>( data ) );
				break;
			case GL_FLOAT_VEC4:
				glUniform4fv( ui.location, count, static_cast<const GLfloat*>( data ) );
				break;
			case GL_INT:
			case GL_BOOL:
				glUniform1iv( ui.location, count, static_cast<const GLint*>( data ) );
				break;
			case GL_INT_VEC2:
			case GL_BOOL_VEC2:
				glUniform2iv( ui.location, count, static_cast<const GLint*>( data ) );
				break;
			case GL_INT_VEC3:
			case GL_BOOL_VEC3:
				glUniform3iv( ui.location, count, static_cast<const GLint*>( data ) );
				break;
			case GL_INT_VEC4:
			case GL_BOOL_VEC4:
				glUniform4iv( ui.location, count, static_cast<const GLint*>( data ) );
				break;
			case GL_FLOAT_MAT2:
				glUniformMatrix2fv( ui.location, count, false, static_cast<const GLfloat*>( data ) );
				break;
			case GL_FLOAT_MAT3:
				glUniformMatrix3fv( ui.location, count, false, static_cast<const GLfloat*>( data ) );
				break;
			case GL_FLOAT_MAT4:
				glUniformMatrix4fv( ui.location, count, false, static_cast<const GLfloat*>( data ) );
				break;
			default: // sampler
				glUniform1iv( ui.location, count, static_cast<const GLint*>( data ) );
				break;
		}
		return !Driver->testGLError();
	}
Ejemplo n.º 27
0
	void Shader::SendVector(int location, const Vector2i& vector) const
	{
		if (location == -1)
			return;

		if (glProgramUniform2fv)
			glProgramUniform2iv(m_program, location, 1, vector);
		else
		{
			OpenGL::BindProgram(m_program);
			glUniform2iv(location, 1, vector);
		}
	}
Ejemplo n.º 28
0
	void Shader::SendVectorArray(int location, const Vector2i* vectors, unsigned int count) const
	{
		if (location == -1)
			return;

		if (glProgramUniform2iv)
			glProgramUniform2iv(m_program, location, count, reinterpret_cast<const int*>(vectors));
		else
		{
			OpenGL::BindProgram(m_program);
			glUniform2iv(location, count, reinterpret_cast<const int*>(vectors));
		}
	}
Ejemplo n.º 29
0
void GPU_shader_uniform_vector_int(GPUShader *UNUSED(shader), int location, int length, int arraysize, const int *value)
{
	if (location == -1)
		return;

	GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Vector");

	if (length == 1) glUniform1iv(location, arraysize, value);
	else if (length == 2) glUniform2iv(location, arraysize, value);
	else if (length == 3) glUniform3iv(location, arraysize, value);
	else if (length == 4) glUniform4iv(location, arraysize, value);

	GPU_ASSERT_NO_GL_ERRORS("Post Uniform Vector");
}
Ejemplo n.º 30
0
void
program::set_uniform2iv(char const* varname, GLsizei count, GLint* value) const
{
  GLint location = get_uniform_location(varname);

  if (location >= 0) 
  {
#if GPUCAST_GL_DIRECT_STATE_ACCESS
    glProgramUniform2iv(id_, location, count, value);
#else 
    glUniform2iv(location, count, value);
#endif
  }
}