/* * Copyright © 2010-2012 Linaro Limited * * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark. * * glmark2 is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * glmark2. If not, see <http://www.gnu.org/licenses/>. * * Authors: * Alexandros Frantzis (glmark2) * Jesse Barker (glmark2) */ #include <cmath> #include <climits> #include <numeric> #include "scene.h" #include "mat.h" #include "options.h" #include "stack.h" #include "vec.h" #include "log.h" #include "program.h" #include "shader-source.h" #include "util.h" #include "texture.h" SceneEffect2D::SceneEffect2D(Canvas &pCanvas) : … { … } SceneEffect2D::~SceneEffect2D() { … } /* * Calculates the offset of the coefficient with index i * from the center of the kernel matrix. Note that we are * using the standard OpenGL texture coordinate system * (x grows rightwards, y grows upwards). */ static LibMatrix::vec2 calc_offset(unsigned int i, unsigned int width, unsigned int height) { … } /** * Creates a fragment shader implementing 2D image convolution. * * In the mathematical definition of 2D convolution, the kernel/filter (2D * impulse response) is essentially mirrored in both directions (that is, * rotated 180 degrees) when being applied on a 2D block of data (eg pixels). * * Most image manipulation programs, however, use the term kernel/filter to * describe a 180 degree rotation of the 2D impulse response. This is more * intuitive from a human understanding perspective because this rotated matrix * can be regarded as a stencil that can be directly applied by just "placing" * it on the image. * * In order to be compatible with image manipulation programs, we will * use the same definition of kernel/filter (180 degree rotation of impulse * response). This also means that we don't need to perform the (implicit) * rotation of the kernel in our convolution implementation. * * @param canvas the destination Canvas for this shader * @param array the array holding the filter coefficients in row-major * order * @param width the width of the filter * @param width the height of the filter * * @return a string containing the frament source code */ static std::string create_convolution_fragment_shader(Canvas &canvas, std::vector<float> &array, unsigned int width, unsigned int height) { … } /** * Creates a string containing a printout of a kernel matrix. * * @param filter the vector containing the filter coefficients * @param width the width of the filter * * @return the printout */ static std::string kernel_printout(const std::vector<float> &kernel, unsigned int width) { … } /** * Parses a string representation of a matrix and returns it * in row-major format. * * In the string representation, elements are delimited using * commas (',') and rows are delimited using semi-colons (';'). * eg 0,0,0;0,1.0,0;0,0,0 * * @param str the matrix string representation to parse * @param matrix the float vector to populate * @param[out] width the width of the matrix * @param[out] height the height of the matrix * * @return whether parsing succeeded */ static bool parse_matrix(const std::string &str, std::vector<float> &matrix, unsigned int &width, unsigned int &height) { … } /** * Normalizes a convolution kernel matrix. * * @param filter the filter to normalize */ static void normalize(std::vector<float> &kernel) { … } bool SceneEffect2D::load() { … } void SceneEffect2D::unload() { … } bool SceneEffect2D::setup() { … } void SceneEffect2D::teardown() { … } void SceneEffect2D::update() { … } void SceneEffect2D::draw() { … } Scene::ValidationResult SceneEffect2D::validate() { … }