void Canvas::SetupShader() { m_shader = std::unique_ptr<sf::Shader>( new sf::Shader ); auto load_result = m_shader->loadFromMemory( "#version 130\n" "in vec2 vertex;\n" "in vec2 texture_coordinate;\n" "out vec2 vertex_texture_coordinate;\n" "void main() {\n" "\tgl_Position = vec4(vertex.xy, 1.f, 1.f);\n" "\tvertex_texture_coordinate = texture_coordinate;\n" "}\n", "#version 130\n" "uniform sampler2D texture0;\n" "in vec2 vertex_texture_coordinate;\n" "out vec4 fragment_color;\n" "void main() {\n" "\tfragment_color = texture(texture0, vertex_texture_coordinate);\n" "}\n" ); if( !load_result ) { non_legacy_supported = false; m_shader.reset(); return; } m_vertex_location = GetAttributeLocation( *m_shader, "vertex" ); m_texture_coordinate_location = GetAttributeLocation( *m_shader, "texture_coordinate" ); m_shader->setParameter( "texture0", m_render_texture->getTexture() ); }
void ApplyPaletteShader::GetLocations() { uTexture = GetUniformLocation("uTexture"); uPalette = GetUniformLocation("uPalette"); vPosition = GetAttributeLocation("vPosition"); vTextureCoordinate = GetAttributeLocation("vTextureCoordinate"); }
void ApplyTransparencyShader::GetLocations() { uOpaqueTex = GetUniformLocation("uOpaqueTex"); uOpaqueDepth = GetUniformLocation("uOpaqueDepth"); uTransparentTex = GetUniformLocation("uTransparentTex"); uTransparentDepth = GetUniformLocation("uTransparentDepth"); uPaletteTex = GetUniformLocation("uPaletteTex"); vPosition = GetAttributeLocation("vPosition"); vTextureCoordinate = GetAttributeLocation("vTextureCoordinate"); }
void DrawLineShader::GetLocations() { uScreenSize = GetUniformLocation("uScreenSize"); vClip = GetAttributeLocation("vClip"); vBounds = GetAttributeLocation("vBounds"); vColour = GetAttributeLocation("vColour"); vDepth = GetAttributeLocation("vDepth"); vVertMat = GetAttributeLocation("vVertMat"); }
/** * Class constructor, loads shaders & gets locations of variables in them */ AssimpLoader::AssimpLoader() { importerPtr = new Assimp::Importer; scene = NULL; isObjectLoaded = false; // shader related setup -- loading, attribute and uniform locations std::string vertexShader = "shaders/modelTextured.vsh"; std::string fragmentShader = "shaders/modelTextured.fsh"; shaderProgramID = LoadShaders(vertexShader, fragmentShader); vertexAttribute = GetAttributeLocation(shaderProgramID, "vertexPosition"); vertexUVAttribute = GetAttributeLocation(shaderProgramID, "vertexUV"); mvpLocation = GetUniformLocation(shaderProgramID, "mvpMat"); textureSamplerLocation = GetUniformLocation(shaderProgramID, "textureSampler"); CheckGLError("AssimpLoader::AssimpLoader"); }
/** fmGetPolicerAttribute * \ingroup policer * * \chips FM3000, FM4000, FM6000, FM10000 * * \desc Get a policer attribute. * * \param[in] sw is the switch on which to operate. * * \param[in] policer is the policer number whose attribute is to be * retrieved. * * \param[in] attr is the policer attribute to get (see * ''Policer Attributes''). * * \param[out] value points to caller-allocated storage where this * function should place the attribute value. * * \return FM_OK if successful. * \return FM_ERR_INVALID_SWITCH if sw is invalid. * \return FM_ERR_INVALID_POLICER if policer is invalid. * \return FM_ERR_INVALID_ARGUMENT if unrecognized attribute. * *****************************************************************************/ fm_status fmGetPolicerAttribute(fm_int sw, fm_int policer, fm_int attr, fm_voidptr value) { void * location; fm_int size; FM_API_PREAMBLE("sw = %d, policer = %d, attr = %d, value = %p\n", sw, policer, attr, (void *) value); if (value == NULL) { err = FM_ERR_INVALID_ARGUMENT; goto ABORT; } err = GetAttributeLocation(sw, policer, attr, &location, &size); if (err == FM_OK) { FM_MEMCPY_S(value, size, location, size); } FM_API_POSTAMBLE; } /* end fmGetPolicerAttribute */
/** * Perform inits and load the triangle's vertices/colors to GLES */ void Triangle::PerformGLInits() { MyGLInits(); //specify 3 vertices of the triangle static const GLfloat vertexBufferData[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; // Generate a vertex buffer and load the vertices into it glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBufferData), vertexBufferData, GL_DYNAMIC_DRAW); //specify colors of the 3 vertices static const GLfloat colorBufferData[] = { 0.0f, 1.0f, 0.0f, //green 0.0f, 1.0f, 0.0f, //green 0.0f, 0.0f, 1.0f //blue }; // Generate a vertex buffer and load the colors into it glGenBuffers(1, &colorBuffer); glBindBuffer(GL_ARRAY_BUFFER, colorBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(colorBufferData), colorBufferData, GL_STATIC_DRAW); // shader related setup std::string vertexShader = "shaders/colorTriangle.vsh"; std::string fragmentShader = "shaders/colorTriangle.fsh"; // compile the vertex and fragment shaders, and link them together shaderProgramID = LoadShaders(vertexShader, fragmentShader); // fetch the locations of "vertexPosition" and "vertexColor" from the shader vertexAttribute = GetAttributeLocation(shaderProgramID, "vertexPosition"); colorAttribute = GetAttributeLocation(shaderProgramID, "vertexColor"); // set parameters that control animation of the triangle triangleVertexDelta = 0; triangleSwapRate = 0.01; // increase this to speedup the animation CheckGLError("Triangle::PerformGLInits"); initsDone = true; }
void DrawLineShader::GetLocations() { uScreenSize = GetUniformLocation("uScreenSize"); uClip = GetUniformLocation("uClip"); uBounds = GetUniformLocation("uBounds"); uColour = GetUniformLocation("uColour"); vIndex = GetAttributeLocation("vIndex"); }
void GLSLProgram::SetAttributeVariable(char* name, int val) { int loc; if ((loc = GetAttributeLocation(name)) >= 0) { this->Use(); glVertexAttrib1i(loc, val); } };
void GLSLProgram::SetAttribute( char* name, float val ) { int loc; if( ( loc = GetAttributeLocation( name ) ) >= 0 ) { this->Use(); glUniform1f( loc, val ); } };
void GLSLProgram::SetAttributeVariable(char* name, float vals[3]) { int loc; if ((loc = GetAttributeLocation(name)) >= 0) { this->Use(); glVertexAttrib3fv(loc, vals); } };
void FillRectShader::GetLocations() { uScreenSize = GetUniformLocation("uScreenSize"); uClip = GetUniformLocation("uClip"); uBounds = GetUniformLocation("uBounds"); uFlags = GetUniformLocation("uFlags"); uColour[0] = GetUniformLocation("uColour[0]"); uColour[1] = GetUniformLocation("uColour[1]"); uSourceFramebuffer = GetUniformLocation("uSourceFramebuffer"); vIndex = GetAttributeLocation("vIndex"); }
/** fmSetPolicerAttribute * \ingroup policer * * \chips FM3000, FM4000, FM6000, FM10000 * * \desc Set a policer attribute. * * \note Some attributes are per-policer, some are per-bank and * some are global. If two policers are given conflicting * values for an attribute with bank-wide scope, the ACL * compiler (''fmCompileACL'') will try to put those policers * in different banks. If there are not enough banks in the * hardware to support all the conflicting attribute values, * the compiler will generate an error. See * ''Policer Attributes'' to determine the scope of each * attribute. * \lb\lb * \param[in] sw is the switch on which to operate. * * \param[in] policer is the policer number whose attribute is to be * set. This argument is ignored for global attributes. * * \param[in] attr is the policer attribute to set (see * ''Policer Attributes''). * * \param[in] value points to the attribute value to set. * * \return FM_OK if successful. * \return FM_ERR_INVALID_SWITCH if sw is invalid. * \return FM_ERR_INVALID_POLICER if policer is invalid. * \return FM_ERR_INVALID_ATTRIB if attempting to set a read-only * attribute. * \return FM_ERR_INVALID_ARGUMENT if unrecognized attribute. * \return FM_ERR_INVALID_VALUE if value points to an invalid value * for the specified attribute. * * *****************************************************************************/ fm_status fmSetPolicerAttribute(fm_int sw, fm_int policer, fm_int attr, const void *value) { void * location; fm_int size; fm_switch *switchPtr; FM_API_PREAMBLE("sw = %d, policer = %d, attr = %d, value = %p\n", sw, policer, attr, (void *) value); if (value == NULL) { err = FM_ERR_INVALID_ARGUMENT; goto ABORT; } err = GetAttributeLocation(sw, policer, attr, &location, &size); if (err == FM_OK) { FM_MEMCPY_S(location, size, value, size); } switchPtr = GET_SWITCH_PTR(sw); if ( (err == FM_OK) && (switchPtr->SetPolicerAttribute != NULL) ) { /* for SWAG */ err = switchPtr->SetPolicerAttribute(sw, policer, attr, value); } FM_API_POSTAMBLE; } /* end fmSetPolicerAttribute */
void DrawRectShader::GetLocations() { uScreenSize = GetUniformLocation("uScreenSize"); uTexture = GetUniformLocation("uTexture"); uPaletteTex = GetUniformLocation("uPaletteTex"); uPeelingTex = GetUniformLocation("uPeelingTex"); uPeeling = GetUniformLocation("uPeeling"); vClip = GetAttributeLocation("vClip"); vTexColourAtlas = GetAttributeLocation("vTexColourAtlas"); vTexColourBounds = GetAttributeLocation("vTexColourBounds"); vTexMaskAtlas = GetAttributeLocation("vTexMaskAtlas"); vTexMaskBounds = GetAttributeLocation("vTexMaskBounds"); vPalettes = GetAttributeLocation("vPalettes"); vFlags = GetAttributeLocation("vFlags"); vColour = GetAttributeLocation("vColour"); vBounds = GetAttributeLocation("vBounds"); vDepth = GetAttributeLocation("vDepth"); vVertMat = GetAttributeLocation("vVertMat"); vVertVec = GetAttributeLocation("vVertVec"); }
void Shader::SetParameterf(std::string name, float val) { glUniform1f(GetAttributeLocation(name), val); }
void Shader::SetParameterMat4(std::string name, float* mat) { glUniformMatrix4fv(GetAttributeLocation(name), 1, GL_FALSE, mat); }
void Shader::SetParameterVec4(std::string name, float x, float y, float z, float w) { glUniform4f(GetAttributeLocation(name), x, y, z, w); }
void Shader::SetParameterVec3(std::string name, float x, float y, float z) { glUniform3f(GetAttributeLocation(name), x, y, z); }
void Shader::SetParameterVec2(std::string name, float x, float y) { glUniform2f(GetAttributeLocation(name), x, y); }
void Shader::SetParameteri(std::string name, int val) { glUniform1i(GetAttributeLocation(name), val); }
NonLegacyRenderer::NonLegacyRenderer() : m_previous_window_size( -1, -1 ), m_last_vertex_count( 0 ), m_last_index_count( 0 ), m_vbo_sync_type( INVALIDATE_ALL ), m_vbo_synced( false ), m_cull( false ), m_use_fbo( false ) { if( IsAvailable() ) { auto load_result = m_shader.loadFromMemory( "#version 130\n" "uniform vec2 viewport_parameters;\n" "in vec2 vertex;\n" "in vec4 color;\n" "in vec2 texture_coordinate;\n" "out vec4 vertex_color;\n" "out vec2 vertex_texture_coordinate;\n" "void main() {\n" "\tmat4 mvp_matrix = mat4(1.f);\n" "\tmvp_matrix[3][0] = -1.f;\n" "\tmvp_matrix[3][1] = 1.f;\n" "\tmvp_matrix[0][0] = viewport_parameters.x;\n" "\tmvp_matrix[1][1] = viewport_parameters.y;\n" "\tmvp_matrix[2][2] = -1.f;\n" "\tgl_Position = mvp_matrix * vec4(vertex.xy, 1.f, 1.f);\n" "\tvertex_color = color;\n" "\tvertex_texture_coordinate = texture_coordinate;\n" "}\n", "#version 130\n" "uniform sampler2D texture0;\n" "in vec4 vertex_color;\n" "in vec2 vertex_texture_coordinate;\n" "out vec4 fragment_color;\n" "void main() {\n" "\tfragment_color = vertex_color * texture(texture0, vertex_texture_coordinate);\n" "}\n" ); if( !load_result ) { shader_supported = false; #if defined( SFGUI_DEBUG ) std::cerr << "Non-legacy renderer unavailable.\n"; #endif return; } m_vertex_location = GetAttributeLocation( m_shader, "vertex" ); m_color_location = GetAttributeLocation( m_shader, "color" ); m_texture_coordinate_location = GetAttributeLocation( m_shader, "texture_coordinate" ); CheckGLError( GLEXT_glGenBuffers( 1, &m_vertex_vbo ) ); CheckGLError( GLEXT_glGenBuffers( 1, &m_color_vbo ) ); CheckGLError( GLEXT_glGenBuffers( 1, &m_texture_vbo ) ); CheckGLError( GLEXT_glGenBuffers( 1, &m_index_vbo ) ); } else { #if defined( SFGUI_DEBUG ) std::cerr << "Non-legacy renderer unavailable.\n"; #endif } }