blob: fea05de0d1f63d8e32f2626a35ca8c6eb9584ba3 [file] [log] [blame]
/*
* Mesa 3-D graphics library
*
* Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
* Copyright (C) 2009-2010 VMware, Inc. All Rights Reserved.
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* \file uniforms.c
* Functions related to GLSL uniform variables.
* \author Brian Paul
*/
/**
* XXX things to do:
* 1. Check that the right error code is generated for all _mesa_error() calls.
* 2. Insert FLUSH_VERTICES calls in various places
*/
#include "main/glheader.h"
#include "main/context.h"
#include "main/shaderobj.h"
#include "main/uniforms.h"
#include "main/enums.h"
#include "ir_uniform.h"
#include "glsl_types.h"
#include "program/program.h"
/**
* Update the vertex/fragment program's TexturesUsed array.
*
* This needs to be called after glUniform(set sampler var) is called.
* A call to glUniform(samplerVar, value) causes a sampler to point to a
* particular texture unit. We know the sampler's texture target
* (1D/2D/3D/etc) from compile time but the sampler's texture unit is
* set by glUniform() calls.
*
* So, scan the program->SamplerUnits[] and program->SamplerTargets[]
* information to update the prog->TexturesUsed[] values.
* Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
* TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
* We'll use that info for state validation before rendering.
*/
void
_mesa_update_shader_textures_used(struct gl_shader_program *shProg,
struct gl_program *prog)
{
GLuint s;
struct gl_shader *shader =
shProg->_LinkedShaders[_mesa_program_enum_to_shader_stage(prog->Target)];
assert(shader);
memcpy(prog->SamplerUnits, shader->SamplerUnits, sizeof(prog->SamplerUnits));
memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
for (s = 0; s < MAX_SAMPLERS; s++) {
if (prog->SamplersUsed & (1 << s)) {
// LunarG - mask out the set value, which resides in upper 16-bits
GLuint unit = shader->SamplerUnits[s] & 0xFFFF;
GLuint tgt = shader->SamplerTargets[s];
assert(unit < Elements(prog->TexturesUsed));
assert(tgt < NUM_TEXTURE_TARGETS);
prog->TexturesUsed[unit] |= (1 << tgt);
}
}
}