void GLShader::draw(const DrawCall& drawCall) { if (drawCall.predraw) drawCall.predraw(); /// update uniform for (auto& p : mUniform.t_float) glUniform1f(uniform_loc(p.first), p.second); for (auto& p : mUniform.t_int ) glUniform1i(uniform_loc(p.first), p.second); for (auto& p : mUniform.t_vec2 ) glUniform2fv(uniform_loc(p.first), 1, p.second.data()); for (auto& p : mUniform.t_vec3 ) glUniform3fv(uniform_loc(p.first), 1, p.second.data()); for (auto& p : mUniform.t_vec4 ) glUniform4fv(uniform_loc(p.first), 1, p.second.data()); for (auto& p : mUniform.t_mat2 ) glUniformMatrix2fv(uniform_loc(p.first), 1, GL_FALSE, p.second.data()); for (auto& p : mUniform.t_mat3 ) glUniformMatrix3fv(uniform_loc(p.first), 1, GL_FALSE, p.second.data()); for (auto& p : mUniform.t_mat4 ) glUniformMatrix4fv(uniform_loc(p.first), 1, GL_FALSE, p.second.data()); /// bind buffers for (auto& p : drawCall.buffer) { auto& buffer = *p.second; glBindBuffer(GL_ARRAY_BUFFER, buffer.id); glVertexAttribPointer(attrib_loc(p.first), buffer.dim, buffer.glType, buffer.integral, 0, 0); } glDrawArrays(drawCall.mode, 0, drawCall.count); if (drawCall.postdraw) drawCall.postdraw(); }
void PointLight::draw(const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix, const glm::vec2& invScreenSize ) const { // Store the four variable coefficients of the projection matrix. const glm::vec4 projectionVector = glm::vec4(projectionMatrix[0][0], projectionMatrix[1][1], projectionMatrix[2][2], projectionMatrix[3][2]); const glm::vec3 lightPositionViewSpace = glm::vec3(viewMatrix * glm::vec4(_lightPosition, 1.0f)); // Compute the model matrix to scale the sphere based on the radius. const glm::mat4 modelMatrix = glm::scale(glm::translate(glm::mat4(1.0f), _lightPosition), glm::vec3(_radius)); const glm::mat4 mvp = projectionMatrix * viewMatrix * modelMatrix; const glm::mat3 viewToLight = glm::mat3(glm::inverse(viewMatrix)); glUseProgram(_program->id()); glUniformMatrix4fv(_program->uniform("mvp"), 1, GL_FALSE, &mvp[0][0]); glUniform3fv(_program->uniform("lightPosition"), 1, &lightPositionViewSpace[0]); glUniform3fv(_program->uniform("lightColor"), 1, &_color[0]); glUniform1f(_program->uniform("lightRadius"), _radius); // Projection parameter for position reconstruction. glUniform4fv(_program->uniform("projectionMatrix"), 1, &(projectionVector[0])); // Inverse screen size uniform. glUniform2fv(_program->uniform("inverseScreenSize"), 1, &(invScreenSize[0])); glUniformMatrix3fv(_program->uniform("viewToLight"), 1, GL_FALSE, &viewToLight[0][0]); glUniform1f(_program->uniform("lightFarPlane"), _farPlane); glUniform1i(_program->uniform("castShadow"), _castShadows); // Active screen texture. for(GLuint i = 0;i < _textureIds.size()-1; ++i){ glActiveTexture(GL_TEXTURE0 + i); glBindTexture(GL_TEXTURE_2D, _textureIds[i]); } // Activate the shadow cubemap. if(_castShadows){ glActiveTexture(GLenum(GL_TEXTURE0 + _textureIds.size()-1)); glBindTexture(GL_TEXTURE_CUBE_MAP, _textureIds[_textureIds.size()-1]); } // Select the geometry. GLUtilities::drawMesh(*_sphere); glBindVertexArray(0); glUseProgram(0); }
void Model::DrawFSQuadTex(GLuint &tex, float scale, vec2 offset) { // Activate shader program glUseProgram(material_->shader_id_); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex); glUniform1f(glGetUniformLocation(material_->shader_id_, "scale"), scale); glUniform2fv(glGetUniformLocation(material_->shader_id_, "offset"), 1, value_ptr(offset)); glUniform1i(material_->shader_uniforms_->tex_diff, 0); // Bind and draw VAO Draw(0); // Unbind and deactivate textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); // Deactivate shader program glUseProgram(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; } } } }
void render_sun_lamp(struct lamp *lamp, mat4 clip_from_view, mat4 view_from_world, mat4 lamp_transform) { static int prog = 0; static int uni_viewport; static int uni_lamp_direction; static int uni_lamp_color; static const vec3 lamp_direction_init = { 0, 0, 1 }; vec2 viewport; vec3 lamp_direction_world; vec3 lamp_direction_view; vec3 lamp_direction; vec3 lamp_color; if (!prog) { prog = compile_shader(quad_vert_src, sun_frag_src); uni_viewport = glGetUniformLocation(prog, "viewport"); uni_lamp_direction = glGetUniformLocation(prog, "lamp_direction"); uni_lamp_color = glGetUniformLocation(prog, "lamp_color"); } viewport[0] = fbo_w; viewport[1] = fbo_h; mat_vec_mul_n(lamp_direction_world, lamp_transform, lamp_direction_init); mat_vec_mul_n(lamp_direction_view, view_from_world, lamp_direction_world); vec_normalize(lamp_direction, lamp_direction_view); vec_scale(lamp_color, lamp->color, lamp->energy); glUseProgram(prog); glUniform2fv(uni_viewport, 1, viewport); glUniform3fv(uni_lamp_direction, 1, lamp_direction); glUniform3fv(uni_lamp_color, 1, lamp_color); draw_fullscreen_quad(); }
void Vessel::DrawWorld() { if (myPlayer) { camera.position = myPlayer->pos; glm::mat4 viewMat(1.0f); camera.GenerateView(viewMat); glUseProgram(floorProgram.program); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, floorProgram.texture); glUniformMatrix4fv(floorProgram.viewMat, 1, false, glm::value_ptr(viewMat)); glUniform1i(floorProgram.textureLoc, 0); DrawFloor(); glUseProgram(coloredVertexProgram.program); glm::vec4 color(0.5f, 0.5f, 0.5f, 1.0f); glUniform4fv(coloredVertexProgram.color, 1, glm::value_ptr(color)); glUniformMatrix4fv(coloredVertexProgram.viewMat, 1, false, glm::value_ptr(viewMat)); DrawWalls(); glDisable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glUseProgram(shadowProgram.program); glUniform2fv(shadowProgram.playerPos, 1, glm::value_ptr(camera.position)); glUniformMatrix4fv(shadowProgram.viewMat, 1, false, glm::value_ptr(viewMat)); DrawShadows(); glEnable(GL_CULL_FACE); glDisable(GL_BLEND); } }
void Shader::Uniform::apply() { switch (type) { case FLOAT: glUniform1f(loc, get<float>()); break; case VEC2: glUniform2fv(loc, 1, glm::value_ptr(get<glm::vec2>())); break; case VEC3: glUniform3fv(loc, 1, glm::value_ptr(get<glm::vec3>())); break; case VEC4: glUniform4fv(loc, 1, glm::value_ptr(get<glm::vec4>())); break; case MAT4: glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(get<glm::mat4>())); break; case TEXTURE: glBindTexture(GL_TEXTURE_2D, get<unsigned int>()); glUniform1i(loc, 0); break; } }
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; } }
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; }
void program_object::set_uniform(const_actives_map_iterator it, const GLfloat* value) { const actives& u = it->second; ASSERT_LOG(value != NULL, "set_uniform(): value is NULL"); switch(u.type) { case GL_FLOAT: { glUniform1f(u.location, *value); break; } case GL_FLOAT_VEC2: { glUniform2fv(u.location, u.num_elements, value); break; } case GL_FLOAT_VEC3: { glUniform3fv(u.location, u.num_elements, value); break; } case GL_FLOAT_VEC4: { glUniform4fv(u.location, u.num_elements, value); break; } case GL_FLOAT_MAT2: { glUniformMatrix2fv(u.location, u.num_elements, GL_FALSE, value); break; } case GL_FLOAT_MAT3: { glUniformMatrix3fv(u.location, u.num_elements, GL_FALSE, value); break; } case GL_FLOAT_MAT4: { glUniformMatrix4fv(u.location, u.num_elements, GL_FALSE, value); break; } default: ASSERT_LOG(false, "Unhandled uniform type: " << it->second.type); } }
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; }
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; } } } } }
void Water::animate(map<string, GLint>& params){ float time = glutGet(GLUT_ELAPSED_TIME) / 1000.0; glUniformMatrix4fv(params["uniform_m"], 1, GL_FALSE, glm::value_ptr(model)); glUniform1f(params["uniform_time"], time); glm::mat4 v_inv = glm::inverse(camera->getView()); glUniformMatrix4fv(params["uniform_v_inv"], 1, GL_FALSE, glm::value_ptr(v_inv)); glm::mat3 m_3x3_inv_transp = glm::transpose(glm::inverse(glm::mat3(model))); glUniformMatrix3fv(params["uniform_m_3x3_inv_transp"], 1, GL_FALSE, glm::value_ptr(m_3x3_inv_transp)); glUniform1i(params["uniform_nsin"], 10); glUniform1i(params["uniform_type"], type); glm::vec2 direction = glm::vec2(0.0, 1.0); glUniform2fv(params["uniform_direction"], 1, glm::value_ptr(direction)); glUniform1f(params["uniform_mS"], 0.6); glUniform1f(params["uniform_ratio"], 0.015); glUniform1ui(params["uniform_useed"], seed); glUniform1f(params["uniform_mw"], 2.0); glUniform1f(params["uniform_vdir"], 3.141592/4); glUniform1i(params["uniform_k"], k); glUniform1f(params["uniform_q"], q); glUniform1f(params["uniform_decay"], decaying); glUniform1f(params["uniform_circular"], circ); glUniformMatrix4fv(params["uniform_mvp"], 1, GL_FALSE, glm::value_ptr(mvp)); }
void draw(){ if( redraw ){ glClearColor(0.0, 0.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); resolution[0] = (float)WIDTH; resolution[1] = (float)HEIGHT; GLuint uloc; uloc = glGetUniformLocation( shader1->shaderprogram, "resolution" ); glUniform2fv(uloc, 1, resolution ); uloc = glGetUniformLocation( shader1->shaderprogram, "light_dir" ); glUniform3fv(uloc, 1, light_dir ); uloc = glGetUniformLocation( shader1->shaderprogram, "natoms" ); glUniform1iv(uloc, 1, &natoms ); uloc = glGetUniformLocation( shader1->shaderprogram, "atoms" ); glUniform4fv(uloc, natoms, atoms ); uloc = glGetUniformLocation( shader1->shaderprogram, "coefs" ); glUniform4fv(uloc, natoms, coefs ); glEnableVertexAttribArray(0); object1->draw(); SDL_GL_SwapWindow(window); redraw = false; } }
void ConsoleInfo::draw() { if(!fontManager || !inited || !m_isVisible) return; drawBackground(); drawCursor(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); TextShaderDescription *shader = renderer.shaderManager()->getTextShader(); glUseProgram(shader->program); glUniform1i(shader->sampler, 0); GLfloat screenSize[2] = { static_cast<GLfloat>(screen_info.w), static_cast<GLfloat>(screen_info.h) }; glUniform2fv(shader->screenSize, 1, screenSize); const int x = 8; int y = m_cursorY + m_lineHeight; size_t n = 0; for(const Line& line : m_lines) { GLfloat *col = fontManager->GetFontStyle(line.styleId)->real_color; y += m_lineHeight; std::copy(col, col + 4, m_font->gl_font_color); glf_render_str(m_font, static_cast<GLfloat>(x), static_cast<GLfloat>(y), line.text.c_str()); ++n; if(n >= m_visibleLines) break; } GLfloat *col = fontManager->GetFontStyle(FontStyle::ConsoleInfo)->real_color; std::copy(col, col + 4, m_font->gl_font_color); glf_render_str(m_font, static_cast<GLfloat>(x), static_cast<GLfloat>(m_cursorY) + m_lineHeight, m_editingLine.c_str()); }
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; } }
static int find_and_pass_uniforms(SceneData* sceneData, SceneObject* so, GLuint program) { GLint num; GLint size_i; GLenum type_i; char name_i[MAX_NAME_LENGTH]; GLint location_i; Uniform* uniform = NULL; void* data = NULL; char texKey[KEYSIZE]; GLuint textureHandle; size_t textureIndex = 0; uint i; glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &num); for (i = 0; i < num; i++) { glGetActiveUniform(program, i, MAX_NAME_LENGTH, NULL, &size_i, &type_i, name_i); location_i = glGetUniformLocation(program, name_i); if ( -1 == location_i) { log_message ("error: could not find name: [%s] in shader program.", name_i); return -1; } uniform = hashmap_find(name_i, so->uniforms); if ( !uniform ) { log_message ("error: could not find [%s] in scene object's uniform map", name_i); return -1; } data = uniform->data; switch (type_i) { case GL_BOOL: if ( 1 == size_i ) glUniform1i(location_i, ((GLint*)data)[0]); else glUniform1iv(location_i, size_i, ((const GLint*)data)); break; case GL_BOOL_VEC2: if ( 1 == size_i ) glUniform2i(location_i, ((GLint*)data)[0], ((GLint*)data)[1]); else glUniform2iv(location_i, size_i, ((const GLint*)data)); break; case GL_BOOL_VEC3: if ( 1 == size_i ) glUniform3i(location_i, ((GLint*)data)[0], ((GLint*)data)[1], ((GLint*)data)[2]); else glUniform3iv(location_i, size_i, ((const GLint*)data)); break; case GL_BOOL_VEC4: if ( 1 == size_i ) glUniform4i(location_i, ((GLint*)data)[0], ((GLint*)data)[1], ((GLint*)data)[2], ((GLint*)data)[3]); else glUniform4iv(location_i, size_i, ((const GLint*)data)); break; case GL_INT: if ( 1 == size_i ) glUniform1i(location_i, (GLint)data); else glUniform1iv(location_i, size_i, ((const GLint*)data)); break; case GL_INT_VEC2: if ( 1 == size_i ) glUniform2i(location_i, ((GLint*)data)[0], ((GLint*)data)[1]); else glUniform2iv(location_i, size_i, ((const GLint*)data)); break; case GL_INT_VEC3: if ( 1 == size_i ) glUniform3i(location_i, ((GLint*)data)[0], ((GLint*)data)[1], ((GLint*)data)[2]); else glUniform3iv(location_i, size_i, ((const GLint*)data)); break; case GL_INT_VEC4: if ( 1 == size_i ) glUniform4i(location_i, ((GLint*)data)[0], ((GLint*)data)[1], ((GLint*)data)[2], ((GLint*)data)[3]); else glUniform4iv(location_i, size_i, ((const GLint*)data)); break; case GL_FLOAT: if ( 1 == size_i ) glUniform1f(location_i, ((GLfloat*)data)[0]); else glUniform1fv(location_i, size_i, ((const GLfloat*)data)); break; case GL_FLOAT_VEC2: if ( 1 == size_i ) glUniform2f(location_i, ((GLfloat*)data)[0], ((GLfloat*)data)[1]); else glUniform2fv(location_i, size_i, ((const GLfloat*)data)); break; case GL_FLOAT_VEC3: if ( 1 == size_i ) glUniform3f(location_i, ((GLfloat*)data)[0], ((GLfloat*)data)[1], ((GLfloat*)data)[2]); else glUniform3fv(location_i, size_i, ((const GLfloat*)data)); break; case GL_FLOAT_VEC4: if ( 1 == size_i ) glUniform4f(location_i, ((GLfloat*)data)[0], ((GLfloat*)data)[1], ((GLfloat*)data)[2], ((GLfloat*)data)[3]); else glUniform4fv(location_i, size_i, ((const GLfloat*)data)); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(location_i, size_i, GL_FALSE, (const GLfloat*)data); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(location_i, size_i, GL_FALSE, (const GLfloat*)data); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(location_i, size_i, GL_FALSE, (const GLfloat*)data); break; case GL_SAMPLER_2D: snprintf( texKey, KEYSIZE, "%p", uniform ); textureHandle = (GLuint)hashmap_find ( texKey, sceneData->mapTexture2Handle ); if ( !textureHandle ) { log_message ( "error: could not bind texture. handle not found"); return -1; } if (textureIndex > 7) { log_message ( "error: cannot use more than 8 texture units per scene object" ); return -1; } glActiveTexture(get_texture_unit(textureIndex)); glBindTexture (GL_TEXTURE_2D, textureHandle); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, uniform->sampleMode ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, uniform->sampleMode ); glUniform1i ( location_i, textureIndex ); textureIndex++; break; case GL_SAMPLER_CUBE: log_message ( "error: cube maps are not supported" ); break; } } return 0; }
void COpenGL::Render(SSurface Src) { SSurface Dst; RECT dstRect; unsigned int newFilterScale; GLenum error; if(!initDone) return; //create a new draw surface if the filter scale changes //at least factor 2 so we can display unscaled hi-res images newFilterScale = max(2,max(GetFilterScale(GUI.ScaleHiRes),GetFilterScale(GUI.Scale))); if(newFilterScale!=filterScale) { ChangeDrawSurfaceSize(newFilterScale); } if(pboFunctionsLoaded) { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, drawBuffer); Dst.Surface = (unsigned char *)glMapBuffer(GL_PIXEL_UNPACK_BUFFER,GL_READ_WRITE); } else { Dst.Surface = noPboBuffer; } Dst.Height = quadTextureSize; Dst.Width = quadTextureSize; Dst.Pitch = quadTextureSize * 2; RenderMethod (Src, Dst, &dstRect); if(!Settings.AutoDisplayMessages) { WinSetCustomDisplaySurface((void *)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale)); S9xDisplayMessages ((uint16*)Dst.Surface, Dst.Pitch/2, dstRect.right-dstRect.left, dstRect.bottom-dstRect.top, GetFilterScale(CurrentScale)); } if(pboFunctionsLoaded) glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); if(afterRenderHeight != dstRect.bottom || afterRenderWidth != dstRect.right) { afterRenderHeight = dstRect.bottom; afterRenderWidth = dstRect.right; ChangeRenderSize(0,0); } glBindTexture(GL_TEXTURE_2D,drawTexture); glPixelStorei(GL_UNPACK_ROW_LENGTH, quadTextureSize); glTexSubImage2D (GL_TEXTURE_2D,0,0,0,dstRect.right-dstRect.left,dstRect.bottom-dstRect.top,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,pboFunctionsLoaded?0:noPboBuffer); if(pboFunctionsLoaded) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); if (shader_type != OGL_SHADER_NONE) { if(shader_type == OGL_SHADER_GLSL) { GLint location; float inputSize[2] = { (float)afterRenderWidth, (float)afterRenderHeight }; RECT windowSize; GetClientRect(hWnd,&windowSize); float outputSize[2] = {(float)(GUI.Stretch?windowSize.right:afterRenderWidth), (float)(GUI.Stretch?windowSize.bottom:afterRenderHeight) }; float textureSize[2] = { (float)quadTextureSize, (float)quadTextureSize }; float frameCnt = (float)++frameCount; location = glGetUniformLocation (shaderProgram, "rubyInputSize"); glUniform2fv (location, 1, inputSize); location = glGetUniformLocation (shaderProgram, "rubyOutputSize"); glUniform2fv (location, 1, outputSize); location = glGetUniformLocation (shaderProgram, "rubyTextureSize"); glUniform2fv (location, 1, textureSize); } else if(shader_type == OGL_SHADER_CG) { xySize inputSize = { (float)afterRenderWidth, (float)afterRenderHeight }; RECT windowSize, displayRect; GetClientRect(hWnd,&windowSize); xySize xywindowSize = { (double)windowSize.right, (double)windowSize.bottom }; //Get maximum rect respecting AR setting displayRect=CalculateDisplayRect(windowSize.right,windowSize.bottom,windowSize.right,windowSize.bottom); xySize viewportSize = { (double)(displayRect.right - displayRect.left), (double)(displayRect.bottom - displayRect.top) }; xySize textureSize = { (double)quadTextureSize, (double)quadTextureSize }; cgShader->Render(drawTexture, textureSize, inputSize, viewportSize, xywindowSize); } } if(GUI.BilinearFilter) { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays (GL_QUADS, 0, 4); glFlush(); SwapBuffers(hDC); }
//-------------------------------------------------------------- void ofShader::setUniform2fv(const string & name, const float* v, int count) const{ if(bLoaded) { int loc = getUniformLocation(name); if (loc != -1) glUniform2fv(loc, count, v); } }
static void gl_glsl_set_params(void *data, void *shader_data, unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, unsigned out_width, unsigned out_height, unsigned frame_count, const void *_info, const void *_prev_info, const void *_feedback_info, const void *_fbo_info, unsigned fbo_info_cnt) { unsigned i; GLfloat buffer[512]; struct glsl_attrib attribs[32]; float input_size[2], output_size[2], texture_size[2]; unsigned texunit = 1; const struct shader_uniforms *uni = NULL; size_t size = 0; size_t attribs_size = 0; const struct video_tex_info *info = (const struct video_tex_info*)_info; const struct video_tex_info *prev_info = (const struct video_tex_info*)_prev_info; const struct video_tex_info *feedback_info = (const struct video_tex_info*)_feedback_info; const struct video_tex_info *fbo_info = (const struct video_tex_info*)_fbo_info; struct glsl_attrib *attr = (struct glsl_attrib*)attribs; glsl_shader_data_t *glsl = (glsl_shader_data_t*)shader_data; if (!glsl) return; uni = (const struct shader_uniforms*)&glsl->uniforms[glsl->active_idx]; if (glsl->prg[glsl->active_idx].id == 0) return; input_size [0] = (float)width; input_size [1] = (float)height; output_size[0] = (float)out_width; output_size[1] = (float)out_height; texture_size[0] = (float)tex_width; texture_size[1] = (float)tex_height; if (uni->input_size >= 0) glUniform2fv(uni->input_size, 1, input_size); if (uni->output_size >= 0) glUniform2fv(uni->output_size, 1, output_size); if (uni->texture_size >= 0) glUniform2fv(uni->texture_size, 1, texture_size); if (uni->frame_count >= 0 && glsl->active_idx) { unsigned modulo = glsl->shader->pass[glsl->active_idx - 1].frame_count_mod; if (modulo) frame_count %= modulo; glUniform1i(uni->frame_count, frame_count); } if (uni->frame_direction >= 0) glUniform1i(uni->frame_direction, state_manager_frame_is_reversed() ? -1 : 1); /* Set lookup textures. */ for (i = 0; i < glsl->shader->luts; i++) { if (uni->lut_texture[i] < 0) continue; /* Have to rebind as HW render could override this. */ glActiveTexture(GL_TEXTURE0 + texunit); glBindTexture(GL_TEXTURE_2D, glsl->lut_textures[i]); glUniform1i(uni->lut_texture[i], texunit); texunit++; } if (glsl->active_idx) { /* Set original texture. */ if (uni->orig.texture >= 0) { /* Bind original texture. */ glActiveTexture(GL_TEXTURE0 + texunit); glUniform1i(uni->orig.texture, texunit); glBindTexture(GL_TEXTURE_2D, info->tex); texunit++; } if (uni->orig.texture_size >= 0) glUniform2fv(uni->orig.texture_size, 1, info->tex_size); if (uni->orig.input_size >= 0) glUniform2fv(uni->orig.input_size, 1, info->input_size); /* Pass texture coordinates. */ if (uni->orig.tex_coord >= 0) { attr->loc = uni->orig.tex_coord; attr->size = 2; attr->offset = (GLsizei)(size * sizeof(GLfloat)); attribs_size++; attr++; buffer[size ] = info->coord[0]; buffer[size + 1] = info->coord[1]; buffer[size + 2] = info->coord[2]; buffer[size + 3] = info->coord[3]; buffer[size + 4] = info->coord[4]; buffer[size + 5] = info->coord[5]; buffer[size + 6] = info->coord[6]; buffer[size + 7] = info->coord[7]; size += 8; } /* Set feedback texture. */ if (uni->feedback.texture >= 0) { /* Bind original texture. */ glActiveTexture(GL_TEXTURE0 + texunit); glUniform1i(uni->feedback.texture, texunit); glBindTexture(GL_TEXTURE_2D, feedback_info->tex); texunit++; } if (uni->feedback.texture_size >= 0) glUniform2fv(uni->feedback.texture_size, 1, feedback_info->tex_size); if (uni->feedback.input_size >= 0) glUniform2fv(uni->feedback.input_size, 1, feedback_info->input_size); /* Pass texture coordinates. */ if (uni->feedback.tex_coord >= 0) { attr->loc = uni->feedback.tex_coord; attr->size = 2; attr->offset = (GLsizei)(size * sizeof(GLfloat)); attribs_size++; attr++; buffer[size ] = feedback_info->coord[0]; buffer[size + 1] = feedback_info->coord[1]; buffer[size + 2] = feedback_info->coord[2]; buffer[size + 3] = feedback_info->coord[3]; buffer[size + 4] = feedback_info->coord[4]; buffer[size + 5] = feedback_info->coord[5]; buffer[size + 6] = feedback_info->coord[6]; buffer[size + 7] = feedback_info->coord[7]; size += 8; } /* Bind FBO textures. */ for (i = 0; i < fbo_info_cnt; i++) { if (uni->pass[i].texture) { glActiveTexture(GL_TEXTURE0 + texunit); glBindTexture(GL_TEXTURE_2D, fbo_info[i].tex); glUniform1i(uni->pass[i].texture, texunit); texunit++; } if (uni->pass[i].texture_size >= 0) glUniform2fv(uni->pass[i].texture_size, 1, fbo_info[i].tex_size); if (uni->pass[i].input_size >= 0) glUniform2fv(uni->pass[i].input_size, 1, fbo_info[i].input_size); if (uni->pass[i].tex_coord >= 0) { attr->loc = uni->pass[i].tex_coord; attr->size = 2; attr->offset = (GLsizei)(size * sizeof(GLfloat)); attribs_size++; attr++; buffer[size ] = fbo_info[i].coord[0]; buffer[size + 1] = fbo_info[i].coord[1]; buffer[size + 2] = fbo_info[i].coord[2]; buffer[size + 3] = fbo_info[i].coord[3]; buffer[size + 4] = fbo_info[i].coord[4]; buffer[size + 5] = fbo_info[i].coord[5]; buffer[size + 6] = fbo_info[i].coord[6]; buffer[size + 7] = fbo_info[i].coord[7]; size += 8; } } } /* Set previous textures. Only bind if they're actually used. */ for (i = 0; i < PREV_TEXTURES; i++) { if (uni->prev[i].texture >= 0) { glActiveTexture(GL_TEXTURE0 + texunit); glBindTexture(GL_TEXTURE_2D, prev_info[i].tex); glUniform1i(uni->prev[i].texture, texunit); texunit++; } if (uni->prev[i].texture_size >= 0) glUniform2fv(uni->prev[i].texture_size, 1, prev_info[i].tex_size); if (uni->prev[i].input_size >= 0) glUniform2fv(uni->prev[i].input_size, 1, prev_info[i].input_size); /* Pass texture coordinates. */ if (uni->prev[i].tex_coord >= 0) { attr->loc = uni->prev[i].tex_coord; attr->size = 2; attr->offset = (GLsizei)(size * sizeof(GLfloat)); attribs_size++; attr++; buffer[size ] = prev_info[i].coord[0]; buffer[size + 1] = prev_info[i].coord[1]; buffer[size + 2] = prev_info[i].coord[2]; buffer[size + 3] = prev_info[i].coord[3]; buffer[size + 4] = prev_info[i].coord[4]; buffer[size + 5] = prev_info[i].coord[5]; buffer[size + 6] = prev_info[i].coord[6]; buffer[size + 7] = prev_info[i].coord[7]; size += 8; } } if (size) gl_glsl_set_attribs(glsl, glsl->vbo[glsl->active_idx].vbo_secondary, &glsl->vbo[glsl->active_idx].buffer_secondary, &glsl->vbo[glsl->active_idx].size_secondary, buffer, size, attribs, attribs_size); glActiveTexture(GL_TEXTURE0); /* #pragma parameters. */ for (i = 0; i < glsl->shader->num_parameters; i++) { int location = glGetUniformLocation( glsl->prg[glsl->active_idx].id, glsl->shader->parameters[i].id); glUniform1f(location, glsl->shader->parameters[i].current); } /* Set state parameters. */ if (glsl->state_tracker) { static struct state_tracker_uniform state_info[GFX_MAX_VARIABLES]; static unsigned cnt = 0; if (glsl->active_idx == 1) cnt = state_tracker_get_uniform(glsl->state_tracker, state_info, GFX_MAX_VARIABLES, frame_count); for (i = 0; i < cnt; i++) { int location = glGetUniformLocation( glsl->prg[glsl->active_idx].id, state_info[i].id); glUniform1f(location, state_info[i].value); } } }
void GLPrimitiveRenderer::drawTexturedRect3D(const PrimVertex& v0,const PrimVertex& v1,const PrimVertex& v2,const PrimVertex& v3,float viewMat[16],float projMat[16], bool useRGBA) { assert(glGetError()==GL_NO_ERROR); glUseProgram(m_data->m_shaderProg); glUniformMatrix4fv(m_data->m_viewmatUniform, 1, false, viewMat); glUniformMatrix4fv(m_data->m_projMatUniform, 1, false, projMat); assert(glGetError()==GL_NO_ERROR); glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer); glBindVertexArray(m_data->m_vertexArrayObject); bool useFiltering = false; if (useFiltering) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } PrimVertex vertexData[4] = { v0,v1,v2,v3 }; glBufferSubData(GL_ARRAY_BUFFER, 0,4 * sizeof(PrimVertex), vertexData); assert(glGetError()==GL_NO_ERROR); PrimVec2 p( 0.f,0.f);//?b?0.5f * sinf(timeValue), 0.5f * cosf(timeValue) ); if (useRGBA) { p.p[0] = 1.f; p.p[1] = 1.f; } glUniform2fv(m_data->m_positionUniform, 1, (const GLfloat *)&p); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); assert(glGetError()==GL_NO_ERROR); glEnableVertexAttribArray(m_data->m_positionAttribute); assert(glGetError()==GL_NO_ERROR); glEnableVertexAttribArray(m_data->m_colourAttribute); assert(glGetError()==GL_NO_ERROR); glEnableVertexAttribArray(m_data->m_textureAttribute); glVertexAttribPointer(m_data->m_positionAttribute, 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)0); glVertexAttribPointer(m_data->m_colourAttribute , 4, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)sizeof(PrimVec4)); glVertexAttribPointer(m_data->m_textureAttribute , 2, GL_FLOAT, GL_FALSE, sizeof(PrimVertex), (const GLvoid *)(sizeof(PrimVec4)+sizeof(PrimVec4))); assert(glGetError()==GL_NO_ERROR); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_indexBuffer); //glDrawArrays(GL_TRIANGLE_FAN, 0, 4); int indexCount = 6; assert(glGetError()==GL_NO_ERROR); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0); assert(glGetError()==GL_NO_ERROR); glBindVertexArray(0); assert(glGetError()==GL_NO_ERROR); glBindBuffer(GL_ARRAY_BUFFER, 0); assert(glGetError()==GL_NO_ERROR); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); assert(glGetError()==GL_NO_ERROR); //glDisableVertexAttribArray(m_data->m_textureAttribute); assert(glGetError()==GL_NO_ERROR); glUseProgram(0); assert(glGetError()==GL_NO_ERROR); }
void CC3GLSLUniform::setGLValue() { switch (_type) { case GL_FLOAT: glUniform1fv(_location, _size, (const GLfloat*)m_glVarValue); //LogGLErrorTrace(@"glUniform1fv(%i, %i, %.3f) setting %@", _location, _size, *(GLfloat*)_glVarValue, self.name); break; case GL_FLOAT_VEC2: glUniform2fv(_location, _size, (const GLfloat*)m_glVarValue); //LogGLErrorTrace(@"glUniform2fv(%i, %i, %@) setting %@", _location, _size, NSStringFromCGPoint(*(CGPoint*)_glVarValue), self.name); break; case GL_FLOAT_VEC3: glUniform3fv(_location, _size, (const GLfloat*)m_glVarValue); //LogGLErrorTrace(@"glUniform3fv(%i, %i, %@) setting %@", _location, _size, NSStringFromCC3Vector(*(CC3Vector*)_glVarValue), self.name); break; case GL_FLOAT_VEC4: glUniform4fv(_location, _size, (const GLfloat*)m_glVarValue); //LogGLErrorTrace(@"glUniform4fv(%i, %i, %@) setting %@", _location, _size, NSStringFromCC3Vector4(*(CC3Vector4*)_glVarValue), self.name); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(_location, _size, GL_FALSE, (const GLfloat*)m_glVarValue); // LogGLErrorTrace(@"glUniformMatrix2fv(%i, %i, GL_FALSE, %@) setting %@", _location, _size, NSStringFromCC3Vector4(*(CC3Vector4*)_glVarValue), self.name); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(_location, _size, GL_FALSE, (const GLfloat*)m_glVarValue); // LogGLErrorTrace(@"glUniformMatrix3fv(%i, %i, GL_FALSE, %@) setting %@", _location, _size, NSStringFromCC3Matrix3x3((CC3Matrix3x3*)_glVarValue), self.name); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(_location, _size, GL_FALSE, (const GLfloat*)m_glVarValue); // LogGLErrorTrace(@"glUniformMatrix4fv(%i, %i, GL_FALSE, %@) setting %@", _location, _size, NSStringFromCC3Matrix4x4((CC3Matrix4x4*)_glVarValue), self.name); break; case GL_INT: case GL_SAMPLER_2D: case GL_SAMPLER_CUBE: case GL_BOOL: glUniform1iv(_location, _size, (const GLint*)m_glVarValue); // LogGLErrorTrace(@"glUniform1iv(%i, %i, %i) setting %@", _location, _size, *(GLint*)_glVarValue, self.name); break; case GL_INT_VEC2: case GL_BOOL_VEC2: glUniform2iv(_location, _size, (const GLint*)m_glVarValue); // LogGLErrorTrace(@"glUniform2iv(%i, %i, %@) setting %@", _location, _size, NSStringFromCC3IntPoint(*(CC3IntPoint*)_glVarValue), self.name); break; case GL_INT_VEC3: case GL_BOOL_VEC3: glUniform3iv(_location, _size, (const GLint*)m_glVarValue); // LogGLErrorTrace(@"glUniform3iv(%i, %i, %@) setting %@", _location, _size, NSStringFromCC3IntVector(*(CC3IntVector*)_glVarValue), self.name); break; case GL_INT_VEC4: case GL_BOOL_VEC4: glUniform4iv(_location, _size, (const GLint*)m_glVarValue); // LogGLErrorTrace(@"glUniform4iv(%i, %i, %@) setting %@", _location, _size, NSStringFromCC3IntVector4(*(CC3IntVector4*)_glVarValue), self.name); break; default: CCAssert(false, "could not set GL engine state value because uniform type is not understood"/*, self, NSStringFromGLEnum(_type)*/); break; } }
void shader::bind() const { if(!is_valid()) { log_error(GL_NO_ERROR, "vertex_buffer::bind - shader program is not valid."); } glUseProgram(m_program_id); check_and_log_error("shader::bind - failed to use program."); // Constants { for(const auto &upload : m_pending_upload) { const constant_type type = (constant_type)std::get<UPLOAD_TYPE>(upload); const uint32_t index = std::get<UPLOAD_INDEX>(upload); const uint32_t number_of_elements = std::get<UPLOAD_NUM_ELEMENTS>(upload); const void *data = &(m_pending_upload_data.at(std::get<UPLOAD_START_INDEX>(upload))); switch(type) { case(constant_type::FLOAT): glUniform1fv(index, number_of_elements, (GLfloat*)data); break; case(constant_type::VEC2): glUniform2fv(index, number_of_elements, (GLfloat*)data); break; case(constant_type::VEC3): glUniform3fv(index, number_of_elements, (GLfloat*)data); break; case(constant_type::VEC4): glUniform4fv(index, number_of_elements, (GLfloat*)data); break; case(constant_type::INT): glUniform1iv(index, number_of_elements, (GLint*)data); break; case(constant_type::IVEC2): glUniform2iv(index, number_of_elements, (GLint*)data); break; case(constant_type::IVEC3): glUniform3iv(index, number_of_elements, (GLint*)data); break; case(constant_type::IVEC4): glUniform4iv(index, number_of_elements, (GLint*)data); break; case(constant_type::BOOL): glUniform1iv(index, number_of_elements, (GLint*)data); break; case(constant_type::BVEC2): glUniform2iv(index, number_of_elements, (GLint*)data); break; case(constant_type::BVEC3): glUniform3iv(index, number_of_elements, (GLint*)data); break; case(constant_type::BVEC4): glUniform4iv(index, number_of_elements, (GLint*)data); break; case(constant_type::MAT2): glUniformMatrix2fv(index, number_of_elements, GL_FALSE, (GLfloat*)data); break; case(constant_type::MAT3): glUniformMatrix3fv(index, number_of_elements, GL_FALSE, (GLfloat*)data); break; case(constant_type::MAT4): glUniformMatrix4fv(index, number_of_elements, GL_FALSE, (GLfloat*)data); break; default: assert(false); // Why did you get here? }; } m_pending_upload.clear(); m_pending_upload_data.clear(); } // Constants // Textures { const std::size_t number_of_textures = std::min<std::size_t>(m_pending_texture_data.size(), static_cast<std::size_t>(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)); for(std::size_t i = 0; i < number_of_textures; ++i) { const auto &tex = m_pending_texture_data.at(i); glActiveTexture(GL_TEXTURE0 + tex.index); check_and_log_error("shader::bind - applying active texture."); glBindTexture(tex.target, tex.texture_id); check_and_log_error("shader::bind - binding texture."); glTexParameteri(tex.target, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(tex.target, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(tex.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(tex.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); check_and_log_error("shader::bind - setting texParaeteri."); } m_pending_texture_data.clear(); } }
void uniform_2fv(gl::int_t location, gl::sizei_t count, const gl::float_t * value) { glUniform2fv(location, count, value); }
void rglUniform2fv(GLint location, GLsizei count, const GLfloat *value) { glUniform2fv(location, count, value); }
void kore::BindUniform::doExecute(void) const { if(!_componentUniform) { Log::getInstance()->write("[ERROR] Uniform binding undefined"); return; } GLerror::gl_ErrorCheckStart(); _renderManager-> useShaderProgram(_shaderUniform->shader->getProgramLocation()); switch (_componentUniform->type) { case GL_FLOAT: glUniform1fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_VEC2: glUniform2fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_VEC3: glUniform3fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_VEC4: glUniform4fv(_shaderUniform->location, _componentUniform->size, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_DOUBLE: glUniform1d(_shaderUniform->location, *static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_VEC2: glUniform2dv(_shaderUniform->location, _componentUniform->size, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_VEC3: glUniform3dv(_shaderUniform->location, _componentUniform->size, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_VEC4: glUniform4dv(_shaderUniform->location, _componentUniform->size, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_BOOL: case GL_INT: glUniform1i(_shaderUniform->location, *static_cast<GLint*>(_componentUniform->data)); break; case GL_BOOL_VEC2: case GL_INT_VEC2: glUniform2iv(_shaderUniform->location, _componentUniform->size, static_cast<GLint*>(_componentUniform->data)); break; case GL_BOOL_VEC3: case GL_INT_VEC3: glUniform3iv(_shaderUniform->location, _componentUniform->size, static_cast<GLint*>(_componentUniform->data)); break; case GL_BOOL_VEC4: case GL_INT_VEC4: glUniform4iv(_shaderUniform->location, _componentUniform->size, static_cast<GLint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT: glUniform1ui(_shaderUniform->location, *static_cast<GLuint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT_VEC2: glUniform2uiv(_shaderUniform->location, _componentUniform->size, static_cast<GLuint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT_VEC3: glUniform3uiv(_shaderUniform->location, _componentUniform->size, static_cast<GLuint*>(_componentUniform->data)); break; case GL_UNSIGNED_INT_VEC4: glUniform4uiv(_shaderUniform->location, _componentUniform->size, static_cast<GLuint*>(_componentUniform->data)); break; case GL_FLOAT_MAT2: glUniformMatrix2fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT3: glUniformMatrix3fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT4: glUniformMatrix4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT2x3: glUniformMatrix2x3fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT2x4: glUniformMatrix2x4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT3x2: glUniformMatrix3x2fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT3x4: glUniformMatrix3x4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT4x2: glUniformMatrix4x2fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_FLOAT_MAT4x3: glUniformMatrix3x4fv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLfloat*>(_componentUniform->data)); break; case GL_DOUBLE_MAT2: glUniformMatrix2dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT3: glUniformMatrix3dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT4: glUniformMatrix4dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT2x3: glUniformMatrix2x3dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT2x4: glUniformMatrix2x4dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT3x2: glUniformMatrix3x2dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT3x4: glUniformMatrix3x4dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT4x2: glUniformMatrix4x2dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; case GL_DOUBLE_MAT4x3: glUniformMatrix4x3dv(_shaderUniform->location, _componentUniform->size, GL_FALSE, static_cast<GLdouble*>(_componentUniform->data)); break; // Note(dlazarek): Currently, we handle texture-bindings outside of // Uniform-bindigs for sorting and performance-reasons. 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_CUBE_SHADOW: case GL_SAMPLER_1D_ARRAY: case GL_SAMPLER_2D_ARRAY: case GL_SAMPLER_1D_ARRAY_SHADOW: case GL_SAMPLER_2D_ARRAY_SHADOW: case GL_SAMPLER_2D_MULTISAMPLE: case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_SAMPLER_BUFFER: case GL_SAMPLER_2D_RECT: case GL_SAMPLER_2D_RECT_SHADOW: case GL_INT_SAMPLER_1D: case GL_INT_SAMPLER_2D: case GL_INT_SAMPLER_3D: case GL_INT_SAMPLER_CUBE: case GL_INT_SAMPLER_1D_ARRAY: case GL_INT_SAMPLER_2D_ARRAY: case GL_INT_SAMPLER_2D_MULTISAMPLE: case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_INT_SAMPLER_BUFFER: case GL_INT_SAMPLER_2D_RECT: case GL_UNSIGNED_INT_SAMPLER_1D: case GL_UNSIGNED_INT_SAMPLER_2D: case GL_UNSIGNED_INT_SAMPLER_3D: case GL_UNSIGNED_INT_SAMPLER_CUBE: case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_UNSIGNED_INT_SAMPLER_BUFFER: case GL_UNSIGNED_INT_SAMPLER_2D_RECT: //glActiveTexture(GL_TEXTURE0 + _componentUniform->texUnit); //glProgramUniform1i(_shaderID, _shaderUniform->location, _componentUniform->texUnit); kore::Log::getInstance()->write("[ERROR] sampler type was adressed" "as uniform"); break; /* break; case GL_IMAGE_1D: break; case GL_IMAGE_2D: break; case GL_IMAGE_3D: break; case GL_IMAGE_2D_RECT: break; case GL_IMAGE_CUBE: break; case GL_IMAGE_BUFFER: break; case GL_IMAGE_1D_ARRAY: break; case GL_IMAGE_2D_ARRAY: break; case GL_IMAGE_2D_MULTISAMPLE: break; case GL_IMAGE_2D_MULTISAMPLE_ARRAY: break; case GL_INT_IMAGE_1D: break; case GL_INT_IMAGE_2D: break; case GL_INT_IMAGE_3D: break; case GL_INT_IMAGE_2D_RECT: break; case GL_INT_IMAGE_CUBE: break; case GL_INT_IMAGE_BUFFER: break; case GL_INT_IMAGE_1D_ARRAY: break; case GL_INT_IMAGE_2D_ARRAY: break; case GL_INT_IMAGE_2D_MULTISAMPLE: break; case GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY: break; case GL_UNSIGNED_INT_IMAGE_1D: break; case GL_UNSIGNED_INT_IMAGE_2D: break; case GL_UNSIGNED_INT_IMAGE_3D: break; case GL_UNSIGNED_INT_IMAGE_2D_RECT: break; case GL_UNSIGNED_INT_IMAGE_CUBE: break; case GL_UNSIGNED_INT_IMAGE_BUFFER: break; case GL_UNSIGNED_INT_IMAGE_1D_ARRAY: break; case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: break; case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: break; case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: break; */ default: kore::Log::getInstance()->write("[ERROR] Unknown uniform binding\n"); break; } GLerror::gl_ErrorCheckFinish("BindUniformOperation: " + _shaderUniform->name); }
static GLboolean test() { GLboolean pass = GL_TRUE; /* Prepare the shaders */ GLint prog = setup_shaders(); GLint uPixelSize = glGetUniformLocation(prog, "pixelSize"); GLint uTexUnit = glGetUniformLocation(prog, "texUnit"); GLuint scratchTex; int i; /* Pixel sizes in texture coordinates for the horizontal and vertical passes */ const float horizontal[2] = { 1.0 / piglit_width, 0 }; const float vertical[2] = { 0, 1.0 / piglit_height }; /* Texture and vertex coordinates */ const float tc[] = { 0,1, 1,1, 0,0, 0,0, 1,1, 1,0 }; const float vc[] = { -1,1, 1,1, -1,-1, -1,-1, 1,1, 1,-1 }; /* Draw the rectangle that we're going to blur */ piglit_draw_rect(-.5, -.5, 1, 1); /* Create a scratch texture */ glGenTextures(1, &scratchTex); glBindTexture(GL_TEXTURE_2D, scratchTex); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, piglit_width, piglit_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0); glUseProgram(prog); glUniform1i(uTexUnit, 0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, tc); glVertexPointer(2, GL_FLOAT, 0, vc); /* Horizontal pass */ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, piglit_width, piglit_height); glUniform2fv(uPixelSize, 1, horizontal); glDrawArrays(GL_TRIANGLES, 0, 6); /* Vertical pass */ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, piglit_width, piglit_height); glUniform2fv(uPixelSize, 1, vertical); glDrawArrays(GL_TRIANGLES, 0, 6); /* Clean up */ glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &scratchTex); glDeleteProgram(prog); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); assert(glGetError() == 0); /* Test the sides */ for (i = 0; i < 26; i++) { float color[3]; color[0] = expected_edge[i] / 255.; color[1] = color[0]; color[2] = color[0]; pass = piglit_probe_pixel_rgb(50, 12 + i, color) && pass; pass = piglit_probe_pixel_rgb(50, piglit_height - 13 - i, color) && pass; pass = piglit_probe_pixel_rgb(12 + i, 50, color) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 13 - i, 50, color) && pass; } /* Test the corners */ for (i = 0; i < 22; i++) { float color[3]; color[0] = expected_corner[i] / 255.; color[1] = color[0]; color[2] = color[0]; pass = piglit_probe_pixel_rgb(16 + i, 16 + i, color) && pass; pass = piglit_probe_pixel_rgb(16 + i, piglit_height - 17 - i, color) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 17 - i, 16 + i, color) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 17 - i, piglit_height - 17 - i, color) && pass; } return pass; }
static void _glamor_tile(PixmapPtr pixmap, PixmapPtr tile, int x, int y, int width, int height, int tile_x, int tile_y) { ScreenPtr screen = pixmap->drawable.pScreen; glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); int x1 = x; int x2 = x + width; int y1 = y; int y2 = y + height; int tile_x1 = tile_x; int tile_x2 = tile_x + width; int tile_y1 = tile_y; int tile_y2 = tile_y + height; float vertices[8]; float source_texcoords[8]; GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale; glamor_pixmap_private *src_pixmap_priv; glamor_pixmap_private *dst_pixmap_priv; float wh[4]; src_pixmap_priv = glamor_get_pixmap_private(tile); dst_pixmap_priv = glamor_get_pixmap_private(pixmap); glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv); pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale); glamor_make_current(glamor_priv); glUseProgram(glamor_priv->tile_prog); glamor_pixmap_fbo_fix_wh_ratio(wh, src_pixmap_priv); glUniform2fv(glamor_priv->tile_wh, 1, wh); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glamor_set_repeat_normalize_tcoords (src_pixmap_priv, RepeatNormal, src_xscale, src_yscale, tile_x1, tile_y1, tile_x2, tile_y2, glamor_priv->yInverted, source_texcoords); glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), source_texcoords); glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE); glamor_set_normalize_vcoords(dst_pixmap_priv, dst_xscale, dst_yscale, x1, y1, x2, y2, glamor_priv->yInverted, vertices); glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), vertices); glEnableVertexAttribArray(GLAMOR_VERTEX_POS); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE); glDisableVertexAttribArray(GLAMOR_VERTEX_POS); glamor_priv->state = RENDER_STATE; glamor_priv->render_idle_cnt = 0; }
void shader::uniform(const char* name, const math::vec2& v) const { glUniform2fv(uniform(name), 1, math::toGl(v)); }