void setMultipleThicknessParams( const ThicknessLocations& m_thicknessLocations, bool bOrder, float order, float step,
                                                    bool bOneNormal, float* normal, bool bOneColor, ODCOLORREF color )
{
    glUniform1i( m_thicknessLocations.u_bOrder, bOrder );
    glUniform1f( m_thicknessLocations.u_Step, step );
    glUniform1f( m_thicknessLocations.u_Order, order );

    glUniform1i( m_thicknessLocations.u_bOneNormal, bOneNormal );
    glUniform3f( m_thicknessLocations.u_Normal, normal[0], normal[1], normal[3] );

    glUniform1i( m_thicknessLocations.u_bOrder, bOneColor );
    float col[4];
    col[0] = ODGETRED( color );
    col[1] = ODGETGREEN( color );
    col[2] = ODGETBLUE( color );
    col[3] = ODGETALPHA( color );
    glUniform1fv( m_thicknessLocations.u_Color, 4, col );
}
Beispiel #2
0
// Set the shader uniforms for the frame
void Lighting::Update_Lights(Camera& camera, const glm::mat4& view) const
{
	glUniform4fv(camera.Shader_Location("V_Lights", true), 8, &positions[0][0]);
	glUniform3fv(camera.Shader_Location("F_Light_Colors", true), 8, &colors[0][0]);
	glm::vec4 world_directions[8];
	for (int i = 0; i < number_of_lights; ++i)
	{
		world_directions[i] = directions[i];
		if (directions[i].w < 0.5)
		{
			world_directions[i] = view * world_directions[i];
		}
	}
	glUniform4fv(camera.Shader_Location("V_Lamp_Directions", true), 8, &world_directions[0][0]);
	glUniform1fv(camera.Shader_Location("F_Lamp_Angles", true), 8, &angles[0]);
	glUniform3f(camera.Shader_Location("F_Ambient", true), ambient.r, ambient.g, ambient.b);
	glUniform1i(camera.Shader_Location("F_Number_Of_Lights", true), number_of_lights);
}
Beispiel #3
0
void
SetUniformValues(GLuint program, struct uniform_info uniforms[])
{
    GLuint i;

    for (i = 0; uniforms[i].name; i++) {
        uniforms[i].location
            = glGetUniformLocation(program, uniforms[i].name);

        switch (uniforms[i].type) {
        case GL_INT:
        case GL_SAMPLER_1D:
        case GL_SAMPLER_2D:
        case GL_SAMPLER_3D:
        case GL_SAMPLER_CUBE:
        case GL_SAMPLER_2D_RECT_ARB:
            assert(uniforms[i].value[0] >= 0.0F);
            glUniform1i(uniforms[i].location,
                        (GLint) uniforms[i].value[0]);
            break;
        case GL_FLOAT:
            glUniform1fv(uniforms[i].location, 1, uniforms[i].value);
            break;
        case GL_FLOAT_VEC2:
            glUniform2fv(uniforms[i].location, 1, uniforms[i].value);
            break;
        case GL_FLOAT_VEC3:
            glUniform3fv(uniforms[i].location, 1, uniforms[i].value);
            break;
        case GL_FLOAT_VEC4:
            glUniform4fv(uniforms[i].location, 1, uniforms[i].value);
            break;
        default:
            if (strncmp(uniforms[i].name, "gl_", 3) == 0) {
                /* built-in uniform: ignore */
            }
            else {
                fprintf(stderr,
                        "Unexpected uniform data type in SetUniformValues\n");
                abort();
            }
        }
    }
}
//-----------------------------------------------------------------------------
// set shader uniform value to float array
void mgGL33Services::setShaderUniform(
  const char* shaderName,             // name of shader
  const char* varName,                // variable name
  int count,                          // size of array
  const float* values)                // array of floats
{
  DWORD value;
  if (!m_shaders.lookup(shaderName, value))
    throw new mgErrorMsg("glShader", "shaderName", "%s", (const char*) shaderName);

  CHECK_THREAD();
  mgShaderHandle shader = (mgShaderHandle) value;

  GLint index = glGetUniformLocation(shader, (const GLchar*) varName);
  if (index == -1)
    return; // throw new mgException("setShaderUniform %s.%s not found", (const char*) shaderName, (const char*) varName);

  glUniform1fv(index, count, (const GLfloat*) values);
}
Beispiel #5
0
void display()
{
    glViewport(0, 0, Window.Size.x, Window.Size.y);
    //clear back buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    if (Window.WireFrame)
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    else
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glBindVertexArray(VertexArrayName);


    // Update the transformation matrix
    glm::mat4 Projection = glm::perspective(40.0f, 4.0f / 3.0f, 0.1f, 100.0f);
    glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y-8));
    glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y + 45.0f, glm::vec3(1.f, 0.f, 0.f));
    glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x + 45.0f, glm::vec3(0.f, 1.f, 0.f));
    glm::mat4 Model = glm::mat4(1.0f); // object sapce and world space are the same here
    glm::mat4 matMVP = Projection * View * Model;
    glm::mat4 matView = View * Model;

    glUseProgram(ProgramName);
    glUniformMatrix4fv(UniformMVP, 1, GL_FALSE, &matMVP[0][0]);
    glUniformMatrix4fv(UniformView, 1, GL_FALSE, &matView[0][0]);
    glUniform1fv(UniformWeights, 256, &weights[0]);


    glPatchParameteri(GL_PATCH_VERTICES, 16);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, PatchIndicesBufferName);
    glDrawElements(GL_PATCHES, PatchIndicesCount, GL_UNSIGNED_INT, 0);

    if (Window.DrawInputMesh)
    {
        glUseProgram(ProgramName2);
        glUniformMatrix4fv(UniformMVP2, 1, GL_FALSE, &matMVP[0][0]);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, FaceIndicesBufferName);
        glDrawElements(GL_LINES, FaceIndicesCount*2, GL_UNSIGNED_INT, 0);
    }

    amd::checkError("display");
    amd::swapBuffers();
}
Beispiel #6
0
void GLWidget3D::paintEvent(QPaintEvent *event) {
	// OpenGLで描画
	makeCurrent();

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	glUseProgram(renderManager.program);
	renderManager.updateShadowMap(this, light_dir, light_mvpMatrix);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);

	// Model view projection行列をシェーダに渡す
	glUniformMatrix4fv(glGetUniformLocation(renderManager.program, "mvpMatrix"),  1, GL_FALSE, &camera.mvpMatrix[0][0]);
	glUniformMatrix4fv(glGetUniformLocation(renderManager.program, "mvMatrix"),  1, GL_FALSE, &camera.mvMatrix[0][0]);

	// pass the light direction to the shader
	glUniform1fv(glGetUniformLocation(renderManager.program, "lightDir"), 3, &light_dir[0]);
	
	drawScene(0);

	// OpenGLの設定を元に戻す
	glShadeModel(GL_FLAT);
	glDisable(GL_CULL_FACE);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);

	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	// QPainterで描画
	QPainter painter(this);
	painter.setOpacity(0.5);
	for (int i = 0; i < parametriclsystem::NUM_LAYERS; ++i) {
		painter.drawImage(0, 0, sketch[i]);
	}
	painter.end();

	glEnable(GL_DEPTH_TEST);
}
Beispiel #7
0
void aa::uniform_variable::set(aa::vector<float> &v)
{
	switch(v.size())
	{
		case 1:
			glUniform1fv(id, 1, v.get_raw_ptr());
			break;
		case 2:
			glUniform2fv(id, 1, v.get_raw_ptr());
			break;
		case 3:
			glUniform3fv(id, 1, v.get_raw_ptr());
			break;
		case 4:
			glUniform4fv(id, 1, v.get_raw_ptr());
			break;
			//error
	}
}
Beispiel #8
0
static void
texture_paint(struct ctx *context, GLuint *textures, GLuint nmemb, const struct wlc_geometry *geometry, struct paint *settings)
{
   const GLfloat vertices[8] = {
      geometry->origin.x + geometry->size.w, geometry->origin.y,
      geometry->origin.x, geometry->origin.y,
      geometry->origin.x + geometry->size.w, geometry->origin.y + geometry->size.h,
      geometry->origin.x, geometry->origin.y + geometry->size.h,
   };

   const GLfloat coords[8] = {
      1, 0,
      0, 0,
      1, 1,
      0, 1
   };

   set_program(context, settings->program);

   if (settings->dim > 0.0f) {
      GL_CALL(glUniform1fv(context->program->uniforms[UNIFORM_DIM], 1, &settings->dim));
   }

   for (GLuint i = 0; i < nmemb; ++i) {
      if (!textures[i])
         break;

      GL_CALL(glActiveTexture(GL_TEXTURE0 + i));
      GL_CALL(glBindTexture(GL_TEXTURE_2D, textures[i]));

      if (settings->filter || !wlc_size_equals(&context->resolution, &context->mode)) {
         GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
         GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
      } else {
         GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
         GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
      }
   }

   GL_CALL(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices));
   GL_CALL(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, coords));
   GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
}
Beispiel #9
0
void blur(PHsurface *sources, PHsurface *dests, int count, float offset, Direction dir)
{
    GLint loc;
    int p;


	// set up the filter
    glUseProgram(filterProg);
    loc = glGetUniformLocation(filterProg, "source");
    glUniform1i(loc, 0);
    loc = glGetUniformLocation(filterProg, "coefficients");
    glUniform1fv(loc, KERNEL_SIZE, kernel);
    loc = glGetUniformLocation(filterProg, "offsetx");
    glUniform1f(loc, 0);
    loc = glGetUniformLocation(filterProg, "offsety");
    glUniform1f(loc, 0);
    if (dir == HORIZONTAL)
        loc = glGetUniformLocation(filterProg, "offsetx");


    // perform the blurring
    for (p = 0; p < count; p++)
    {
        float offset2;
		
		if (dir == HORIZONTAL)
			offset2 = offset / (float)sources[p].width;

		if (dir == VERTICAL)
			offset2 = offset / (float)sources[p].height;

        glUniform1f(loc, offset2);
        phBindSurface(dests + p, false);
		GL_Bind(sources[p].texture);

		glBegin(GL_QUADS);
        glTexCoord2i(0, 0); glVertex2i(-1, -1);
		glTexCoord2i(0, 1); glVertex2i(-1, 1);
		glTexCoord2i(1, 1); glVertex2i(1, 1);
        glTexCoord2i(1, 0); glVertex2i(1, -1);
        glEnd();
    }
}
Beispiel #10
0
XprBool xprGpuProgramUniform1fv(XprGpuProgram* self, XprHashCode hash, size_t count, const float* value)
{
	XprGpuProgramUniform* uniform;
	XprGpuProgramImpl* impl = (XprGpuProgramImpl*)self;

	if(nullptr == self)
		return XprFalse;

	if(0 == (self->flags & XprGpuProgram_Inited)) {
		//xprDbgStr("XprGpuProgram is not inited!\n");
		return XprFalse;
	}

	HASH_FIND_INT(impl->cache, &hash, uniform);
	if(nullptr == uniform)
		return XprFalse;

	glUniform1fv(uniform->loc, count, value);
	return XprTrue;
}
Beispiel #11
0
int
shader_set_param_float(const struct ShaderParam *p, size_t count, float *f)
{
	assert(p != NULL);
	assert(f != NULL);

#ifdef DEBUG
	if (p->type != GL_FLOAT) {
		errf("shader param %s is not of float type", p->name);
		return 0;
	} else if (count > p->size) {
		errf("shader param %s value size too big", p->name);
		return 0;
	}
#endif

	glUniform1fv(p->loc, count, f);

	HANDLE_GL_ERROR(p->name);
}
Beispiel #12
0
bool SGLShaderProgram::set_uniformv(std::string name,const GLfloat values[],GLsizei cnt)
{
	int loc = glGetUniformLocation(ID, name.c_str());
	if(loc != -1) switch(cnt)
	{
		case 1:glUniform1fv(loc, cnt,values);break;
		case 2:glUniform2fv(loc, cnt,values);break;
		case 3:glUniform3fv(loc, cnt,values);break;
		case 4:glUniform4fv(loc, cnt,values);break;
		default:
			SGLprintError("Ung�ltige Dimension %d f�r die Uniforme %s",cnt,name.c_str());
			return false;
	}
	else 
	{
		SGLprintError("Die Uniforme %s ist nicht verf�gbar",name.c_str());
		return false;
	}
	return SGLSpace::printErrors();
}
Beispiel #13
0
void pointLight::passPointLights(int posLocation, int colorLocation, int powerLocation)
{
	if(pointLights.size() > 0)
	{
		std::vector<glm::vec3> positions;
		std::vector<glm::vec3> colors;
		std::vector<float> powers;

		for(int i =0; i< pointLights.size(); i++)
		{
			positions.push_back(pointLights[i]->getParent()->getTrans()->getPos());
			colors.push_back(pointLights[i]->getColor());
			powers.push_back(pointLights[i]->getPower());
		}

		glUniform3fv(posLocation, pointLights.size(), &positions[0][0]);
		glUniform3fv(colorLocation, pointLights.size(), &colors[0][0]);
		glUniform1fv(powerLocation, pointLights.size(), &powers[0]);
	}
}
void Cc3dProgram::passUnifoValueNfv(string unifoName,const GLfloat*array,int arrayLen){
    assert(arrayLen>=1&&arrayLen<=4);
    switch (arrayLen) {
        case 1:
            glUniform1fv(m_unifoMap[unifoName],1,array);
            break;
        case 2:
            glUniform2fv(m_unifoMap[unifoName],1,array);
            break;
        case 3:
            glUniform3fv(m_unifoMap[unifoName],1,array);
            break;
        case 4:
            glUniform4fv(m_unifoMap[unifoName],1,array);
            break;
        default:
            assert(false);
            break;
    }
    
}
Beispiel #15
0
void nuiUniformDesc::Apply() const
{
  total++;

//  if (!(total % 10000))
//    NGL_OUT("Uniform stats: %d on %d applied (%d skipped) %f cache hit\n", applied, total, skipped, (float)skipped/(float)total);

  if (!mChanged)
  {
    skipped++;
    return;
  }
  applied++;

  mChanged = false;

  switch (mType)
  {
    case GL_FLOAT:              glUniform1fv(mLocation, mCount, mValues.mpFloats);  break;
    case GL_FLOAT_VEC2:         glUniform2fv(mLocation, mCount, mValues.mpFloats);  break;
    case GL_FLOAT_VEC3:         glUniform3fv(mLocation, mCount, mValues.mpFloats);  break;
    case GL_FLOAT_VEC4:         glUniform4fv(mLocation, mCount, mValues.mpFloats);  break;

    case GL_INT:                glUniform1iv(mLocation, mCount, mValues.mpInts);  break;
    case GL_INT_VEC2:           glUniform2iv(mLocation, mCount, mValues.mpInts);  break;
    case GL_INT_VEC3:           glUniform3iv(mLocation, mCount, mValues.mpInts);  break;
    case GL_INT_VEC4:           glUniform4iv(mLocation, mCount, mValues.mpInts);  break;
    case GL_UNSIGNED_INT:       glUniform1iv(mLocation, mCount, mValues.mpInts);  break;

    case GL_FLOAT_MAT2:         glUniformMatrix2fv(mLocation, mCount, GL_FALSE, mValues.mpFloats);  break;
    case GL_FLOAT_MAT3:         glUniformMatrix3fv(mLocation, mCount, GL_FALSE, mValues.mpFloats);  break;
    case GL_FLOAT_MAT4:         glUniformMatrix4fv(mLocation, mCount, GL_FALSE, mValues.mpFloats);  break;

    case GL_SAMPLER_2D:         glUniform1iv(mLocation, mCount, mValues.mpInts);  break;
    case GL_SAMPLER_CUBE:       glUniform1iv(mLocation, mCount, mValues.mpInts);  break;

    default:
      NGL_ASSERT(0);
  }
}
Beispiel #16
0
void SetupHDRProg()
{
    glUseProgram(hdrResolve);

    // Set projection matrix
    glUniformMatrix4fv(glGetUniformLocation(hdrResolve, "pMatrix"), 
        1, GL_FALSE, transformPipeline.GetProjectionMatrix());

    // Set MVP matrix
    glUniformMatrix4fv(glGetUniformLocation(hdrResolve, "mvMatrix"), 
        1, GL_FALSE, transformPipeline.GetModelViewMatrix());

    // Set user controled uniforms
    glUniform1fv(glGetUniformLocation(hdrResolve, "exposure"), 1, &exposure);

    // Set texture uniforms
    glUniform1i(glGetUniformLocation(hdrResolve, "origImage"), 0);
    glUniform1i(glGetUniformLocation(hdrResolve, "sampleWeightSampler"), 1);

    // Setup MS sepcific uniforms
    glUniform1i(glGetUniformLocation(hdrResolve, "sampleCount"), sampleCount);
    glUniform1i(glGetUniformLocation(hdrResolve, "useWeightedResolve"), useWeightedResolve);

    // Now setup the right textures
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, hdrTextures[0]);

    // Check if sample weight buffer needs to be updated
    if (sampleCount != lastSampleCount)
    {
        glBindBuffer(GL_TEXTURE_BUFFER_ARB, sampleWeightBuf);
        void *data = glMapBufferRange(GL_TEXTURE_BUFFER_ARB, 0, sizeof(float)*8,
                         (GL_MAP_WRITE_BIT |GL_MAP_INVALIDATE_RANGE_BIT));
        memcpy(data, (void*)sampleWeights[sampleCount],sizeof(float)*8);
        glUnmapBuffer(GL_TEXTURE_BUFFER_ARB);
        lastSampleCount = sampleCount;
    }

    gltCheckErrors(hdrResolve);
} 
Beispiel #17
0
void GradientShader::updateUniforms()
{
	if (loaded && camSet)
	{
		glUseProgram(programID);

		GLint MVPUniform = glGetUniformLocation(programID, "MVPMatrix");
		GLint StopCountUniform = glGetUniformLocation(programID, "stopCount");
		GLint ValuesUniform = glGetUniformLocation(programID, "values");
		GLint ColorsUniform = glGetUniformLocation(programID, "colors");

		GLint stopCount = gradientStops.size();

		if (stopCount > 1)
		{

			qSort(gradientStops.begin(), gradientStops.end(), StopIsLessThan);
			GLfloat stopValues[stopCount];
			GLfloat colorValues[stopCount*4];
			for (int i=0; i<gradientStops.size(); ++i)
			{
				stopValues[i] = getValueFromStop(gradientStops[i].first);
				colorValues[4*i+0] = gradientStops[i].second.red() / 255.0;
				colorValues[4*i+1] = gradientStops[i].second.green() / 255.0;
				colorValues[4*i+2] = gradientStops[i].second.blue() / 255.0;
				colorValues[4*i+3] = gradientStops[i].second.alpha() / 255.0;
			}

			glUniformMatrix4fv(MVPUniform, 1, GL_FALSE, camera->getMVP());
			glUniform1i(StopCountUniform, stopCount);
			glUniform1fv(ValuesUniform, stopCount, stopValues);
			glUniform4fv(ColorsUniform, stopCount, colorValues);
		}
			uniformsSet = true;

	} else {
		uniformsSet = false;
	}
}
	//-----------------------------------------------------------------------
	void GLSLLinkProgram::updatePassIterationUniforms(GpuProgramParametersSharedPtr params)
	{
		if (params->hasPassIterationNumber())
		{
			size_t index = params->getPassIterationNumberIndex();

			GLUniformReferenceIterator currentUniform = mGLUniformReferences.begin();
			GLUniformReferenceIterator endUniform = mGLUniformReferences.end();

			// Need to find the uniform that matches the multi pass entry
			for (;currentUniform != endUniform; ++currentUniform)
			{
				// Get the index in the parameter real list
				if (index == currentUniform->mConstantDef->physicalIndex)
				{
					OGRE_CHECK_GL_ERROR(glUniform1fv(currentUniform->mLocation, 1, params->getFloatPointer(index)));
					// There will only be one multipass entry
					return;
				}
			}
		}
    }
Beispiel #19
0
 void Shader::SendUniform(const Uniform &uniform, void* data, const int32 Handle, const uint32 elementCount)
 {
     if (Handle>-1 && elementCount>0)
     {
         switch(uniform.Type)
         {
             case DataType::Int:
             {
                 GLCHECKER(glUniform1iv(Handle,elementCount,(GLint*)((int32*)data)));
                 break;
             }
             case DataType::Float:
             {
                 GLCHECKER(glUniform1fv(Handle,elementCount,(f32*)data));
                 break;
             }
             case DataType::Vec2:
             {
                 GLCHECKER(glUniform2fv(Handle,elementCount,(f32*)data));
                 break;
             }
             case DataType::Vec3:
             {
                 GLCHECKER(glUniform3fv(Handle,elementCount,(f32*)data));
                 break;
             }
             case DataType::Vec4:
             {
                 GLCHECKER(glUniform4fv(Handle,elementCount,(f32*)data));
                 break;
             }
             case DataType::Matrix:
             {
                 GLCHECKER(glUniformMatrix4fv(Handle,elementCount,false,(f32*)data));
                 break;
             }                    
         }
     }
 }
Beispiel #20
0
void display() {
	glClearColor(0,0,1,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


	glMatrixMode(GL_MODELVIEW);
	mat4 mv; 
	const vec3 center(0.0,0.0,0.0); 

	if (useGlu) mv = glm::lookAt(eye,center,up); 
	else {
		mv = Transform::lookAt(eye,up); 
		mv = glm::transpose(mv); // accounting for row major
	}
	glLoadMatrixf(&mv[0][0]); 

	// Set Light and Material properties for the teapot
	// Lights are transformed by current modelview matrix. 
	// The shader can't do this globally. 
	// So we need to do so manually.  
	transformvec(light_position,light0); 
	transformvec(light_position1,light1); 

	glUniform4fv(light0posn,1,light0); 
	glUniform4fv(light0color,1,light_specular); 
	glUniform4fv(light1posn,1,light1); 
	glUniform4fv(light1color,1,light_specular1); 

	//glUniform4fv(ambient,1,small); 
	//glUniform4fv(diffuse,1,medium); 
	glUniform4fv(ambient,1,small); 
	glUniform4fv(diffuse,1,small); 
	glUniform4fv(specular,1,one); 
	glUniform1fv(shininess,1,high); 
	glUniform1i(islight,true);

	glutSolidTeapot(2);
	glutSwapBuffers();
}
Beispiel #21
0
void GraphicsCore::UpdateBillboardObjectValues(Object3D object)
{
	vec3 up(0.0f, 1.0f, 0.0f);
	
    mat4 Projection = glm::perspective(fov, float(windowWidth) / (float)windowHeight, 0.1f, 200.f); 	
    mat4 Model = glm::translate(object.GetWorldPos());
	mat4 viewMatrix = mCam.GetRotationMatrix() * glm::lookAt(mEye, mTarget, up);
    mat4 ModelView =  viewMatrix * Model; 

	float Size = object.GetSize();;
	
	uint shaderProgHandle = object.GetShaderID();

	uint location = glGetUniformLocation(shaderProgHandle, "ProjectionMatrix");	//gets the UniformLocation from shader.vertex
	if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &Projection[0][0]); }

	location = glGetUniformLocation(shaderProgHandle, "ModelViewMatrix");	//gets the UniformLocation from shader.vertex
	if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &ModelView[0][0]); }

	location = glGetUniformLocation(shaderProgHandle, "Size");	//gets the UniformLocation from shader.vertex
	glUniform1fv(location, 1, &Size);
}
Beispiel #22
0
void Shader::uniform(GLint i, std::vector<GLfloat> fv)
{
    use();
    switch(fv.size())
    {
    case 0:
        throw Error::ShaderNoUniforms;
    case 1:
        glUniform1fv(i, 1, fv.data());
        return;
    case 2:
        glUniform2fv(i, 1, fv.data());
        return;
    case 3:
        glUniform3fv(i, 1, fv.data());
        return;
    case 4:
        glUniform4fv(i, 1, fv.data());
        return;
    default:
        throw Error::ShaderTooMuchUniforms;
    }
}
Beispiel #23
0
static void
Redisplay(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   glUniform1fv(Uniforms[2].location, 1, &Slice);

   glPushMatrix();
   glRotatef(xRot, 1.0f, 0.0f, 0.0f);
   glRotatef(yRot, 0.0f, 1.0f, 0.0f);
   glRotatef(zRot, 0.0f, 0.0f, 1.0f);

   glBegin(GL_POLYGON);
   glTexCoord2f(0, 0);   glVertex2f(-2, -2);
   glTexCoord2f(1, 0);   glVertex2f( 2, -2);
   glTexCoord2f(1, 1);   glVertex2f( 2,  2);
   glTexCoord2f(0, 1);   glVertex2f(-2,  2);
   glEnd();

   glPopMatrix();

   glutSwapBuffers();
}
bool ShaderSet::SetUniform(const char* name, int n, const float* v)
{
    for (unsigned int i = 0; i < UniformInfo.GetSize(); i++)
        if (!strcmp(UniformInfo[i].Name.ToCStr(), name))
        {
            OVR_ASSERT(UniformInfo[i].Location >= 0);
            glUseProgram(Prog);
            switch (UniformInfo[i].Type)
            {
            case 1:   glUniform1fv(UniformInfo[i].Location, n, v); break;
            case 2:   glUniform2fv(UniformInfo[i].Location, n/2, v); break;
            case 3:   glUniform3fv(UniformInfo[i].Location, n/3, v); break;
            case 4:   glUniform4fv(UniformInfo[i].Location, n/4, v); break;
            case 12:  glUniformMatrix3fv(UniformInfo[i].Location, 1, 1, v); break;
            case 16:  glUniformMatrix4fv(UniformInfo[i].Location, 1, 1, v); break;
            default: OVR_ASSERT(0);
            }
            return 1;
        }

    OVR_DEBUG_LOG(("Warning: uniform %s not present in selected shader", name));
    return 0;
}
Beispiel #25
0
void ChOpenGLCloud::Draw(const mat4& projection, const mat4& view) {
    if (GLReturnedError("ChOpenGLCloud::Draw - on entry"))
        return;
    if (this->vertices.size() == 0)
        return;
    glEnable(GL_DEPTH_TEST);
    // compute the mvp matrix and normal matricies
    // mat4 mvp = projection * modelview;
    // mat3 nm = inverse(transpose(mat3(modelview)));

    // Enable the shader
    shader->Use();
    GLReturnedError("ChOpenGLCloud::Draw - after use");
    // Send our common uniforms to the shader
    shader->CommonSetup(value_ptr(projection), value_ptr(view));
    glUniform4fv(color_handle, 1, glm::value_ptr(color));
    glUniform1fv(point_size_handle, 1, &point_size);
    GLReturnedError("ChOpenGLCloud::Draw - after common setup");
    // Bind and draw! (in this case we draw as triangles)
    glBindVertexArray(this->vertex_array_handle);

    glBindBuffer(GL_ARRAY_BUFFER, vertex_data_handle);
    glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(vec3), &this->vertices[0], GL_DYNAMIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertex_element_handle);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertex_indices.size() * sizeof(GLuint), &vertex_indices[0], GL_DYNAMIC_DRAW);

    glDrawElements(GL_POINTS, (GLsizei)this->vertex_indices.size(), GL_UNSIGNED_INT, (void*)0);

    GLReturnedError("ChOpenGLCloud::Draw - after draw");
    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glUseProgram(0);

    if (GLReturnedError("ChOpenGLCloud::Draw - on exit"))
        return;
}
Beispiel #26
0
        bool ShaderOGL::setVertexShaderConstant(uint32_t index, uint32_t size, uint32_t count, const float* value)
        {
            if (index >= vertexShaderConstantLocations.size()) return false;

            RendererOGL::bindProgram(programId);

            GLint location = vertexShaderConstantLocations[index];

            uint32_t components = size / 4;

            switch (components)
            {
                case 1:
                    glUniform1fv(location, static_cast<GLsizei>(count), value);
                    break;
                case 2:
                    glUniform2fv(location, static_cast<GLsizei>(count), value);
                    break;
                case 3:
                    glUniform3fv(location, static_cast<GLsizei>(count), value);
                    break;
                case 4:
                    glUniform4fv(location, static_cast<GLsizei>(count), value);
                    break;
                case 9:
                    glUniformMatrix3fv(location, static_cast<GLsizei>(count), GL_FALSE, value);
                    break;
                case 16:
                    glUniformMatrix4fv(location, static_cast<GLsizei>(count), GL_FALSE, value);
                    break;
                default:
                    log("Unsupported uniform size");
                    return false;
            }

            return true;
        }
Beispiel #27
0
    void Shader::SendUniform(const Uniform &uniform, const int32 Handle)
    {
        if (Handle>-1 && uniform.ElementCount>0)
        switch(uniform.Type)
        {
            case DataType::Int:
            {
				GLCHECKER(glUniform1iv(Handle,uniform.ElementCount,(GLint*)((int32*)&uniform.Value[0])));
                break;
            }
            case DataType::Float:
            {
                GLCHECKER(glUniform1fv(Handle,uniform.ElementCount,(f32*)&uniform.Value[0]));
                break;
            }
            case DataType::Vec2:
            {
                GLCHECKER(glUniform2fv(Handle,uniform.ElementCount,(f32*)&uniform.Value[0]));
                break;
            }
            case DataType::Vec3:
            {
                GLCHECKER(glUniform3fv(Handle,uniform.ElementCount,(f32*)&uniform.Value[0]));
                break;
            }
            case DataType::Vec4:
            {
                GLCHECKER(glUniform4fv(Handle,uniform.ElementCount,(f32*)&uniform.Value[0]));
                break;
            }
            case DataType::Matrix:
            {
                GLCHECKER(glUniformMatrix4fv(Handle,uniform.ElementCount,false,(f32*)&uniform.Value[0]));
                break;
            }
        }
    }
void Shader::updateShaderParameters(bool forceUpdate) {
    for (int i = 0; i < shaderParameters->size(); i++) {
        ShaderParameter *parameter = shaderParameters->at(i);
        if (parameter->hasValueChanged() || forceUpdate) {
            GLuint location = glGetUniformLocation(program, parameter->parameterName.c_str());
            if (location != -1) {
                switch (parameter->parameterType) {
                case PARAMETER_INT:
                    glUniform1iv(location, parameter->valueSize, (int*) parameter->getValue());
                    break;
                case PARAMETER_FLOAT:
                    glUniform1fv(location, parameter->valueSize, (float*) parameter->getValue());
                    break;
                case PARAMETER_DOUBLE:
                    glUniform1dv(location, parameter->valueSize, (double*) parameter->getValue());
                    break;
                case PARAMETER_VECTOR_2:
                    glUniform2fv(location, parameter->valueSize, (float*) parameter->getValue());
                    break;
                case PARAMETER_VECTOR_3:
                    glUniform3fv(location, parameter->valueSize, (float*) parameter->getValue());
                    break;
                case PARAMETER_VECTOR_4:
                    glUniform4fv(location, parameter->valueSize, (float*) parameter->getValue());
                    break;
                case PARAMETER_MATRIX_3:
                    glUniformMatrix3fv(location, parameter->valueSize, false, (float*) parameter->getValue());
                    break;
                case PARAMETER_MATRIX_4:
                    glUniformMatrix4fv(location, parameter->valueSize, false, (float*) parameter->getValue());
                    break;
                }
            }
        }
    }
}
Beispiel #29
0
	void Shader::BindFloat(const std::string &name, int size, int count, const float *value)
	{
		int id = GetUniformLocation(name);
		if (id == -1) return;

		switch (size)
		{
		case 1:
			glUniform1fv(id, count, value);
			break;
		case 2:
			glUniform2fv(id, count, value);
			break;
		case 3:
			glUniform3fv(id, count, value);
			break;
		case 4:
			glUniform4fv(id, count, value);
			break;
		default:
			FURYW << "Incorrect unfirom size!";
			break;
		}
	}
Beispiel #30
-1
void DGLShader::setUniformFloatArray( const char* uniformName, int elementCount, int arrayLength, float* arrayData )
{
    GLint uniformLocation = glGetUniformLocation( _programID, uniformName );
    if( uniformLocation == -1 )
        return;
    
    if( elementCount == 1 )
        glUniform1fv( uniformLocation, arrayLength, arrayData );
    
    else if( elementCount == 2 )
        glUniform2fv( uniformLocation, arrayLength, arrayData );
    
    else if( elementCount == 3 )
        glUniform3fv( uniformLocation, arrayLength, arrayData );
    
    else if( elementCount == 4 )
        glUniform4fv( uniformLocation, arrayLength, arrayData );
    
    else return;
}