Edit

kc3-lang/angle/samples/simple_texture_cubemap

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2018-04-16 10:36:39
    Hash : 0cb6dc4c
    Message : Vulkan: Fix texture descriptor set alloc count. We were reserving half the required descriptor sets for our pool. This fixes the counting and ensures we won't regress by adding a test. Also enables the cube map texture sample, and removes an UNIMPLEMENTED warning that was spurious. Bug: angleproject:2318 Change-Id: I371cd7c5b42e1ce980cce7bb0ef04885db72b614 Reviewed-on: https://chromium-review.googlesource.com/1014165 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Luc Ferron <lucferron@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>

  • SimpleTextureCubemap.cpp
  • //
    // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    //            Based on Simple_TextureCubemap.c from
    // Book:      OpenGL(R) ES 2.0 Programming Guide
    // Authors:   Aaftab Munshi, Dan Ginsburg, Dave Shreiner
    // ISBN-10:   0321502795
    // ISBN-13:   9780321502797
    // Publisher: Addison-Wesley Professional
    // URLs:      http://safari.informit.com/9780321563835
    //            http://www.opengles-book.com
    
    #include "SampleApplication.h"
    #include "shader_utils.h"
    #include "texture_utils.h"
    #include "geometry_utils.h"
    
    class SimpleTextureCubemapSample : public SampleApplication
    {
      public:
        SimpleTextureCubemapSample(EGLint displayType)
            : SampleApplication("SimpleTextureCubemap", 1280, 720, 2, 0, displayType)
        {
        }
    
        virtual bool initialize()
        {
            const std::string vs =
                R"(attribute vec4 a_position;
                attribute vec3 a_normal;
                varying vec3 v_normal;
                void main()
                {
                    gl_Position = a_position;
                    v_normal = a_normal;
                })";
    
            const std::string fs =
                R"(precision mediump float;
                varying vec3 v_normal;
                uniform samplerCube s_texture;
                void main()
                {
                    gl_FragColor = textureCube(s_texture, v_normal);
                })";
    
            mProgram = CompileProgram(vs, fs);
            if (!mProgram)
            {
                return false;
            }
    
            // Get the attribute locations
            mPositionLoc = glGetAttribLocation(mProgram, "a_position");
            mNormalLoc = glGetAttribLocation(mProgram, "a_normal");
    
            // Get the sampler locations
            mSamplerLoc = glGetUniformLocation(mProgram, "s_texture");
    
            // Load the texture
            mTexture = CreateSimpleTextureCubemap();
    
            // Generate the geometry data
            CreateSphereGeometry(128, 0.75f, &mSphere);
    
            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glCullFace(GL_BACK);
            glEnable(GL_CULL_FACE);
    
            return true;
        }
    
        virtual void destroy()
        {
            glDeleteProgram(mProgram);
            glDeleteTextures(1, &mTexture);
        }
    
        virtual void draw()
        {
            // Set the viewport
            glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight());
    
            // Clear the color buffer
            glClear(GL_COLOR_BUFFER_BIT);
    
            // Use the program object
            glUseProgram(mProgram);
    
            // Load the vertex position
            glVertexAttribPointer(mPositionLoc, 3, GL_FLOAT, GL_FALSE, 0, mSphere.positions.data());
            glEnableVertexAttribArray(mPositionLoc);
    
            // Load the normal
            glVertexAttribPointer(mNormalLoc, 3, GL_FLOAT, GL_FALSE, 0, mSphere.normals.data());
            glEnableVertexAttribArray(mNormalLoc);
    
            // Bind the texture
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_CUBE_MAP, mTexture);
    
            // Set the texture sampler to texture unit to 0
            glUniform1i(mSamplerLoc, 0);
    
            glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(mSphere.indices.size()),
                           GL_UNSIGNED_SHORT, mSphere.indices.data());
        }
    
      private:
        // Handle to a program object
        GLuint mProgram;
    
        // Attribute locations
        GLint mPositionLoc;
        GLint mNormalLoc;
    
        // Sampler location
        GLint mSamplerLoc;
    
        // Texture handle
        GLuint mTexture;
    
        // Geometry data
        SphereGeometry mSphere;
    };
    
    int main(int argc, char **argv)
    {
        EGLint displayType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
    
        if (argc > 1)
        {
            displayType = GetDisplayTypeFromArg(argv[1]);
        }
    
        SimpleTextureCubemapSample app(displayType);
        return app.run();
    }