• Cocos2d Opengl2.1 升级到 opengl3.3


    CCGLViewImpl-desktop.cpp

    	//在glfwCreateWindow前插入下面4行
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        ...
        glfwCreateWindow();
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    CCClippingNode.cpp

    	//glGetIntegerv(GL_STENCIL_BITS, &g_sStencilBits);
    	//改为
    	glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &g_sStencilBits);
    
    
    • 1
    • 2
    • 3
    • 4

    CCConfiguration.cpp

    	//glGetString(GL_EXTENSIONS);
    	//改为
    	glGetStringi(GL_EXTENSIONS,i);
    
    • 1
    • 2
    • 3

    CCGL-mac.h

    //#import 
    //改为
    #import <OpenGL/gl3.h>
    
    • 1
    • 2
    • 3

    CCClippingNode.cpp
    添加vao支持,opengl3的draw必须绑定vao,否则会报GL_INVALID_OPERATION错误

            Vec2 vertices[] = {
                Vec2(-1, -1),
                Vec2(1, -1),
                Vec2(1, 1),
                Vec2(-1, 1)
            };
    
            glGenVertexArrays(1, &_vao);
            GL::bindVAO(_vao);
            glGenBuffers(1, &_vbo);
            glBindBuffer(GL_ARRAY_BUFFER, _vbo);
            glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
    
            glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
            glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
    
            GL::bindVAO(0);
            glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    同理,UILayout.cpp,CCLayer.cpp 也需要添加vao支持
    另外,shader需要支持glsl 330
    CCGLProgram.cpp

        const GLchar *sources[] = {
            "#version 330\n",
            (type == GL_FRAGMENT_SHADER ? "out vec4 FragColor;\n" : "\n"),
    
    
    • 1
    • 2
    • 3
    • 4

    顶点着色器中 attribute 改为 in; varying 改为 out

    in vec4 a_position;
    in vec4 a_color;
    in vec2 a_texCoord;
    
    out vec4 v_fragmentColor;
    out vec3 v_texCoord;
    
    void main()
    {
        gl_Position = CC_PMatrix * vec4(a_position.xy,0,a_position.w);
        v_fragmentColor = a_color;
        v_texCoord = vec3(a_texCoord,a_position.z);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    片元着色器中varying改为in;
    texture2D改为texture;
    gl_FragColor改为自定义的FragColor

    in vec4 v_fragmentColor;
    in vec2 v_texCoord;
    
    void main()
    {
        FragColor = v_fragmentColor * texture(CC_Texture0, v_texCoord);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 相关阅读:
    Ubuntu安装Redis
    [BJDCTF2020]ZJCTF,不过如此 preg_replace /e模式漏洞
    Eureka 学习笔记(2)加载eureka-server.properties中的配置
    OpenHarmony UI动画-recyclerview_animators
    线路曲线坐标计算程2
    从零开始Blazor Server(9)--修改Layout
    【Linux】OS和进程概念
    信息反馈平台的设计与实现(一、项目设计)
    SpringCloud-11-搭建Eureka Server 集群
    SpringBoot + Vue实现博文上传+展示+博文列表
  • 原文地址:https://blog.csdn.net/wishes2018/article/details/126406535