static int program_set_uniform_number3(lua_State *L) { shader_type *p = (shader_type*)lua_touserdata(L, 1); const char *var = luaL_checkstring(L, 2); bool change = gl_c_shader != p->shader; if (change) tglUseProgramObject(p->shader); // Uniform array if (lua_istable(L, 3)) { int nb = lua_objlen(L, 3); int i; GLfloat is[3*nb]; for (i = 0; i < nb; i++) { lua_rawgeti(L, 3, i + 1); lua_rawgeti(L, -1, 1); is[i*3+0] = lua_tonumber(L, -1); lua_pop(L, 1); lua_rawgeti(L, -1, 2); is[i*3+1] = lua_tonumber(L, -1); lua_pop(L, 1); lua_rawgeti(L, -1, 3); is[i*3+2] = lua_tonumber(L, -1); lua_pop(L, 1); lua_pop(L, 1); } glUniform3fvARB(glGetUniformLocationARB(p->shader, var), nb, is); } else { GLfloat i[3]; i[0] = luaL_checknumber(L, 3); i[1] = luaL_checknumber(L, 4); i[2] = luaL_checknumber(L, 5); glUniform3fvARB(glGetUniformLocationARB(p->shader, var), 1, i); } if (change) tglUseProgramObject(0); return 0; }
/* * sendUniform3fv * * parameter name - char* * parameter count - GLsizei * parameter values - GLfloat* * return - bool */ bool ShaderObject::sendUniform3fv(const char * name, GLsizei count, GLfloat* values) { GLint location = getUniLoc(name); if (location == -1) return false; glUniform3fvARB(location, count, values); return true; } // end sendUniform3fv()
void GPU::Shader::SetUniform( const std::string& name, const void *value ) { UniformMap::iterator uu = m_Uniforms.find( name ); if( uu != m_Uniforms.end() ) { GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB ); glUseProgramObjectARB( m_Id ); Uniform &u = uu->second; switch( u.type ) { case GL_FLOAT: glUniform1fvARB( u.location, u.size, (GLfloat*) value ); break; case GL_FLOAT_VEC2_ARB: glUniform2fvARB( u.location, u.size, (GLfloat*) value ); break; case GL_FLOAT_VEC3_ARB: glUniform3fvARB( u.location, u.size, (GLfloat*) value ); break; case GL_FLOAT_VEC4_ARB: glUniform4fvARB( u.location, u.size, (GLfloat*) value ); break; case GL_INT: glUniform1ivARB( u.location, u.size, (GLint*) value ); break; case GL_INT_VEC2_ARB: glUniform2ivARB( u.location, u.size, (GLint*) value ); break; case GL_INT_VEC3_ARB: glUniform3ivARB( u.location, u.size, (GLint*) value ); break; case GL_INT_VEC4_ARB: glUniform4ivARB( u.location, u.size, (GLint*) value ); break; case GL_BOOL_ARB: glUniform1ivARB( u.location, u.size, (GLint*) value ); break; case GL_BOOL_VEC2_ARB: glUniform2ivARB( u.location, u.size, (GLint*) value ); break; case GL_BOOL_VEC3_ARB: glUniform3ivARB( u.location, u.size, (GLint*) value ); break; case GL_BOOL_VEC4_ARB: glUniform4ivARB( u.location, u.size, (GLint*) value ); break; case GL_FLOAT_MAT2_ARB: glUniformMatrix2fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break; case GL_FLOAT_MAT3_ARB: glUniformMatrix3fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break; case GL_FLOAT_MAT4_ARB: glUniformMatrix4fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break; } glUseProgramObjectARB( activeProgBackup ); } }
bool Shader::sendUniform3fv(char* varname, GLsizei count, GLfloat *value) { GLint loc = GetUniformLocation(varname); if (loc == -1) return false; glUniform3fvARB(loc, count, value); return true; }
bool GlslProgram :: setUniformVector ( const char * name, const Vector3D& value ) { int loc = glGetUniformLocationARB ( program, name ); if ( loc < 0 ) return false; glUniform3fvARB ( loc, 1, value ); return true; }
void Shader::uniform(const std::string& uniformName, const Vector3& value) { GLuint id = glGetUniformLocation(_program, uniformName.c_str()); if (id == -1) { #ifdef DEBUG_SHADERS FLog(FLog::WARNING, _name + " Couldn't get uniform location of " + uniformName); #endif } glUniform3fvARB(id, 1, value.getValuePtr()); }
void BL_Shader::SetUniform(int uniform, const MT_Tuple3& vec) { if ( GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects ) { float value[3]; vec.getValue(value); glUniform3fvARB(uniform, 1, value); } }
void Raycaster::bindShader(const Raycaster::PTransform& pmv,const Raycaster::PTransform& mv,Raycaster::DataItem* dataItem) const { /* Set up the data space transformation: */ glUniform3fvARB(dataItem->mcScaleLoc,1,dataItem->mcScale); glUniform3fvARB(dataItem->mcOffsetLoc,1,dataItem->mcOffset); /* Bind the ray termination texture: */ glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D,dataItem->depthTextureID); glUniform1iARB(dataItem->depthSamplerLoc,0); /* Set the termination matrix: */ glUniformMatrix4fvARB(dataItem->depthMatrixLoc,1,GL_TRUE,pmv.getMatrix().getEntries()); /* Set the depth texture size: */ glUniform2fARB(dataItem->depthSizeLoc,float(dataItem->depthTextureSize[0]),float(dataItem->depthTextureSize[1])); /* Calculate the eye position in model coordinates: */ Point eye=pmv.inverseTransform(PTransform::HVector(0,0,1,0)).toPoint(); glUniform3fvARB(dataItem->eyePositionLoc,1,eye.getComponents()); /* Set the sampling step size: */ glUniform1fARB(dataItem->stepSizeLoc,stepSize*cellSize); }
void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, float *value) { if (location == -1) return; GPU_print_error("Pre Uniform Vector"); if (length == 1) glUniform1fvARB(location, arraysize, value); else if (length == 2) glUniform2fvARB(location, arraysize, value); else if (length == 3) glUniform3fvARB(location, arraysize, value); else if (length == 4) glUniform4fvARB(location, arraysize, value); else if (length == 9) glUniformMatrix3fvARB(location, arraysize, 0, value); else if (length == 16) glUniformMatrix4fvARB(location, arraysize, 0, value); GPU_print_error("Post Uniform Vector"); }
void useShader(shader_type *p, int x, int y, int w, int h, float tx, float ty, float tw, float th, float r, float g, float b, float a) { tglUseProgramObject(p->shader); GLfloat t = cur_frame_tick; glUniform1fvARB(p->p_tick, 1, &t); GLfloat d[4]; d[0] = r; d[1] = g; d[2] = b; d[3] = a; glUniform4fvARB(p->p_color, 1, d); GLfloat c[2]; c[0] = x; c[1] = y; glUniform2fvARB(p->p_mapcoord, 1, c); c[0] = w; c[1] = h; glUniform2fvARB(p->p_texsize, 1, c); d[0] = tx; d[1] = ty; d[2] = tw; d[3] = th; glUniform4fvARB(p->p_texcoord, 1, d); shader_reset_uniform *ru = p->reset_uniforms; while (ru) { switch (ru->kind) { case UNIFORM_NUMBER: glUniform1fvARB(ru->p, 1, &ru->data.number); break; case UNIFORM_VEC2: glUniform2fvARB(ru->p, 1, ru->data.vec2); break; case UNIFORM_VEC3: glUniform3fvARB(ru->p, 1, ru->data.vec3); break; case UNIFORM_VEC4: glUniform4fvARB(ru->p, 1, ru->data.vec4); break; } ru = ru->next; } }
void BL_Shader::SetUniform(int uniform, const float* val, int len) { if ( GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects ) { if (len == 2) glUniform2fvARB(uniform, 1,(GLfloat*)val); else if (len == 3) glUniform3fvARB(uniform, 1,(GLfloat*)val); else if (len == 4) glUniform4fvARB(uniform, 1,(GLfloat*)val); else MT_assert(0); } }
bool ShaderProgram::SetVariable(const char* name, int varDim, const float* values, int count) { if (!_linked) return false; if (_id) { GLint location = glGetUniformLocationARB(_id, name); if (location == -1) return false; switch (varDim) { case 1: glUniform1fvARB(location, count, values); break; case 2: glUniform2fvARB(location, count, values); break; case 3: glUniform3fvARB(location, count, values); break; case 4: glUniform4fvARB(location, count, values); break; default: return false; } return true; } else return false; }
/*! void Joints(Shaderobject shader, String uniform_variable)\n script function to pass the transformed armature joint positions as uniform array to a vertex shader */ void Item_armature::Joints(QObject* _shader, QString var){ if (glwrapper_shader* shader = dynamic_cast<glwrapper_shader*>(_shader)){ float* space = new float[max_bone_id * 3 + 3]; for (QTreeWidgetItemIterator it(this);*it;it++){ if (Item_bone* bone = dynamic_cast<Item_bone*>(*it)){ space[bone->id * 3 + 0] = bone->joint[0]; space[bone->id * 3 + 1] = bone->joint[1]; space[bone->id * 3 + 2] = bone->joint[2]; } } shader->Bind(); int loc = glGetUniformLocationARB(shader->getShaderHandle(),var.toLatin1().constData()); if(loc == -1) return; glUniform3fvARB(loc, max_bone_id + 1, space); delete[] space; } else{ qDebug() << "Item_armature::Joints parameter is not a shader object"; } }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBShaderObjects_nglUniform3fvARB(JNIEnv *env, jclass clazz, jint location, jint count, jobject values, jint values_position, jlong function_pointer) { const GLfloat *values_address = ((const GLfloat *)(*env)->GetDirectBufferAddress(env, values)) + values_position; glUniform3fvARBPROC glUniform3fvARB = (glUniform3fvARBPROC)((intptr_t)function_pointer); glUniform3fvARB(location, count, values_address); }
void BL_Uniform::Apply(class BL_Shader *shader) { #ifdef SORT_UNIFORMS MT_assert(mType > UNI_NONE && mType < UNI_MAX && mData); if (!mDirty) return; switch (mType) { case UNI_FLOAT: { float *f = (float*)mData; glUniform1fARB(mLoc,(GLfloat)*f); break; } case UNI_INT: { int *f = (int*)mData; glUniform1iARB(mLoc, (GLint)*f); break; } case UNI_FLOAT2: { float *f = (float*)mData; glUniform2fvARB(mLoc,1, (GLfloat*)f); break; } case UNI_FLOAT3: { float *f = (float*)mData; glUniform3fvARB(mLoc,1,(GLfloat*)f); break; } case UNI_FLOAT4: { float *f = (float*)mData; glUniform4fvARB(mLoc,1,(GLfloat*)f); break; } case UNI_INT2: { int *f = (int*)mData; glUniform2ivARB(mLoc,1,(GLint*)f); break; } case UNI_INT3: { int *f = (int*)mData; glUniform3ivARB(mLoc,1,(GLint*)f); break; } case UNI_INT4: { int *f = (int*)mData; glUniform4ivARB(mLoc,1,(GLint*)f); break; } case UNI_MAT4: { float *f = (float*)mData; glUniformMatrix4fvARB(mLoc, 1, mTranspose?GL_TRUE:GL_FALSE,(GLfloat*)f); break; } case UNI_MAT3: { float *f = (float*)mData; glUniformMatrix3fvARB(mLoc, 1, mTranspose?GL_TRUE:GL_FALSE,(GLfloat*)f); break; } } mDirty = false; #endif }
// The shader must be activated before void Shader::Uniform(const std::string& ext, const vec3& value) { int id = glGetUniformLocation(m_nProgram, ext.c_str()); glUniform3fvARB(id, 1, value); }
void ProgramUniformGLSL::Set3(const float *pfComponents) { glUniform3fvARB(m_nOpenGLUniformLocation, 1, pfComponents); }
void DiGLShaderParam::Bind() const { if (!mShaderLinker || !mShaderLinker->GetGLHandle()) return; // bind built-in (global) uniforms auto env = Driver->GetShaderEnvironment(); for (auto it = mBuiltinFuncs.begin(); it != mBuiltinFuncs.end(); ++it) { it->second(env, it->first); } // bind custom uniforms for (uint32 i = 0; i < NUM_VARIABLE_TYPES; ++i) { for (auto it = mShaderParams[i].begin(); it != mShaderParams[i].end(); ++it) { const DiAny& data = it->second; if (data.isEmpty()) continue; GLuint location = 0; int samplerUnit = 0; if (i == VARIABLE_SAMPLER2D || i == VARIABLE_SAMPLERCUBE) { auto sampler = mShaderLinker->GetSampler(it->first); if (!sampler) continue; location = sampler->location; samplerUnit = (int)sampler->unit; } else { auto constant = mShaderLinker->GetConstant(it->first); if (!constant) continue; location = constant->location; } switch (i) { case DiShaderParameter::VARIABLE_FLOAT: { float val = any_cast<float>(data); glUniform1fvARB(location, 1, &val); break; } case DiShaderParameter::VARIABLE_FLOAT2: { DiVec2 vec2 = any_cast<DiVec2>(data); glUniform2fvARB(location, 1, vec2.ptr()); break; } case DiShaderParameter::VARIABLE_FLOAT3: { DiVec3 vec3 = any_cast<DiVec3>(data); glUniform3fvARB(location, 1, vec3.ptr()); break; } case DiShaderParameter::VARIABLE_FLOAT4: { DiVec4 vec4 = any_cast<DiVec4>(data); glUniform4fvARB(location, 1, vec4.ptr()); break; } case DiShaderParameter::VARIABLE_MAT4: { DiMat4 vec4 = any_cast<DiMat4>(data); glUniformMatrix4fvARB(location, 1, GL_TRUE, vec4[0]); break; } case DiShaderParameter::VARIABLE_COLOR: { DiColor c = any_cast<DiColor>(data); DiVec4 vec4(c.r,c.g,c.b,c.a); glUniform4fvARB(location, 1, vec4.ptr()); break; } case DiShaderParameter::VARIABLE_FLOAT4_ARRAY: { DiPair<DiVec4*,uint32> v4Arr = any_cast<DiPair<DiVec4*,uint32>>(data); glUniform4fvARB(location, v4Arr.second, v4Arr.first->ptr()); break; } case DiShaderParameter::VARIABLE_SAMPLER2D: case DiShaderParameter::VARIABLE_SAMPLERCUBE: { glUniform1ivARB(location, 1, &samplerUnit); DiTexture* tex = any_cast<DiTexture*>(data); tex->Bind((uint32)samplerUnit); } break; } } } }
void ProgramUniformGLSL::Set(const Vector3 &vVector) { glUniform3fvARB(m_nOpenGLUniformLocation, 1, vVector); }
void ofxShader::setUniformVariable3fv (char const *name, int count, float const *value) { if (loaded) glUniform3fvARB(glGetUniformLocationARB(shader, name), count, value); }
void ccShaderARB::setUniform3fv(const char* uniform, float* val) { int loc = glGetUniformLocationARB(prog,uniform); glUniform3fvARB(loc,1,val); }
void MGLContext::sendUniformVec3(unsigned int fxId, const char * name, float * values, const int count){ GLint uValue = glGetUniformLocationARB((GLhandleARB)fxId, name); if(uValue != -1) glUniform3fvARB(uValue, count, values); }
bool GlslProgram :: setUniformVector ( int loc, const Vector3D& value ) { glUniform3fvARB ( loc, 1, value ); return true; }
ShaderProgram &u3(const char *var, GLfloat *f) { glUniform3fvARB(uniform(var), 1, f); return *this; }
void ofxShader::setUniform3fv (string name, int count, float * value) { if(bLoaded) glUniform3fvARB(glGetUniformLocationARB(shader, name.c_str()), count, value); }
void ProgramUniformGLSL::Set(const Color3 &cColor) { glUniform3fvARB(m_nOpenGLUniformLocation, 1, cColor); }
void ShaderProgramGl::setUniform(const string &name, const Vec3f &value){ assertGl(); glUniform3fvARB(getLocation(name), 1, value.ptr()); assertGl(); }
//----------------------------------------------------------------------- void GLSLLinkProgram::updateUniforms(GpuProgramParametersSharedPtr params, uint16 mask, GpuProgramType fromProgType) { // iterate through uniform reference list and update uniform values GLUniformReferenceIterator currentUniform = mGLUniformReferences.begin(); GLUniformReferenceIterator endUniform = mGLUniformReferences.end(); for (; currentUniform != endUniform; ++currentUniform) { // Only pull values from buffer it's supposed to be in (vertex or fragment) // This method will be called twice, once for vertex program params, // and once for fragment program params. if (fromProgType == currentUniform->mSourceProgType) { const GpuConstantDefinition* def = currentUniform->mConstantDef; if (def->variability & mask) { GLsizei glArraySize = (GLsizei)def->arraySize; // get the index in the parameter real list switch (def->constType) { case GCT_FLOAT1: glUniform1fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_FLOAT2: glUniform2fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_FLOAT3: glUniform3fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_FLOAT4: glUniform4fvARB(currentUniform->mLocation, glArraySize, params->getFloatPointer(def->physicalIndex)); break; case GCT_MATRIX_2X2: glUniformMatrix2fvARB(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); break; case GCT_MATRIX_2X3: if (GLEW_VERSION_2_1) { glUniformMatrix2x3fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_2X4: if (GLEW_VERSION_2_1) { glUniformMatrix2x4fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_3X2: if (GLEW_VERSION_2_1) { glUniformMatrix3x2fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_3X3: glUniformMatrix3fvARB(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); break; case GCT_MATRIX_3X4: if (GLEW_VERSION_2_1) { glUniformMatrix3x4fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_4X2: if (GLEW_VERSION_2_1) { glUniformMatrix4x2fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_4X3: if (GLEW_VERSION_2_1) { glUniformMatrix4x3fv(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); } break; case GCT_MATRIX_4X4: glUniformMatrix4fvARB(currentUniform->mLocation, glArraySize, GL_TRUE, params->getFloatPointer(def->physicalIndex)); break; case GCT_INT1: glUniform1ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_INT2: glUniform2ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_INT3: glUniform3ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_INT4: glUniform4ivARB(currentUniform->mLocation, glArraySize, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_SAMPLER1D: case GCT_SAMPLER1DSHADOW: case GCT_SAMPLER2D: case GCT_SAMPLER2DSHADOW: case GCT_SAMPLER3D: case GCT_SAMPLERCUBE: // samplers handled like 1-element ints glUniform1ivARB(currentUniform->mLocation, 1, (GLint*)params->getIntPointer(def->physicalIndex)); break; case GCT_UNKNOWN: break; } // end switch #if OGRE_DEBUG_MODE checkForGLSLError( "GLSLLinkProgram::updateUniforms", "Error updating uniform", 0 ); #endif } // variability & mask } // fromProgType == currentUniform->mSourceProgType } // end for }
void ofxShader::setUniformVariable3fv (char * name, int count, float * value){ if (bLoaded == true){ glUniform3fvARB(glGetUniformLocationARB(shader, name), count, value); } }
void GLSLShader::SetFloatVector3(GLint variable, GLsizei count, const float *value) { if (variable!=-1) glUniform3fvARB(variable, count, value); }