Поддерживает ли Mac OS OpenGL 3.3?
Пишу приложение на c++ в XCode. Возникли проблемы с шейдерами. Пишет, что версия 330 не поддерживается. Для проверки написал это:
unsigned int major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
unsigned int minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
std::cerr << "OpenGL shader version: " << major << "." << minor << std::endl;
std::cerr << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
В обоих случаях пишет версию 2.1, а мне нужна 3.3
Вот код Window.cpp с инициализацией glfw
#include <iostream>
#include <OpenGL/gl3.h>
#include <GLFW/glfw3.h>
#include "Window.h"
#include <stdio.h>
GLFWwindow* Window::window;
int Window::width = 0;
int Window::height = 0;
int Window::initialize(int width, int height, const char* title){
if(!glfwInit()){
std::cerr << "Error: failed init glfw" << std::endl;
return -1;
}
//print glfw errors
glfwSetErrorCallback(error_callback);
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (window == nullptr){
std::cerr << "Failed to create GLFW Window" << std::endl;
glfwTerminate();
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
//glfwWindowHint(GLFW_SAMPLES, 2);
#ifdef __APPLE__
std::cout << "This is Mac" << std::endl;
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
//OpenGL version
unsigned int major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
unsigned int minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
std::cerr << "OpenGL shader version: " << major << "." << minor << std::endl;
glfwMakeContextCurrent(window);
std::cerr << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
glViewport(0,0, width, height);
Window::width = width;
Window::height = height;
return 0;
}
void Window::error_callback(int error, const char* description){
//error callback
fprintf(stderr, "Error: %s\n", description);
}
void Window::setCursorMode(int mode){
glfwSetInputMode(window, GLFW_CURSOR, mode);
}
void Window::terminate(){
glfwTerminate();
}
bool Window::isShouldClose(){
return glfwWindowShouldClose(window);
}
void Window::setShouldClose(bool flag){
glfwSetWindowShouldClose(window, flag);
}
void Window::swapBuffers(){
glfwSwapBuffers(window);
}
вершинный шейдер: main.glslv
#version 150 core
layout (location = 0) in vec3 v_position;
layout (location = 1) in vec2 v_texCoord;
layout (location = 2) in vec4 v_light;
out vec4 a_color;
out vec2 a_texCoord;
uniform mat4 model;
uniform mat4 projview;
void main(){
vec4 position = projview * model * vec4(v_position, 1.0);
a_color = vec4(v_light.r,v_light.g,v_light.b,1.0f);
a_texCoord = v_texCoord;
a_color.rgb += v_light.a;
a_color.rgb *= 1.0-position.z*0.0025;
//a_color.rgb = pow(a_color.rgb, vec3(1.0/0.7));
gl_Position = position;
}
Фрагментный шейдер: main.glslf
#version 150 core
in vec4 a_color;
in vec2 a_texCoord;
out vec4 f_color;
uniform sampler2D u_texture0;
void main(){
vec4 tex_color = texture(u_texture0, a_texCoord);
if (tex_color.a < 0.5)
discard;
f_color = a_color * tex_color;
}
Ошибки: SHADER::VERTEX: compilation failed ERROR: 0:3: Invalid use of layout 'location' ERROR: 0:4: Invalid use of layout 'location' ERROR: 0:5: Invalid use of layout 'location' ERROR: 0:6: Invalid use of layout 'location' ERROR: 0:15: Use of undeclared identifier 'v_position' ERROR: 0:16: Use of undeclared identifier 'v_light' ERROR: 0:16: Use of undeclared identifier 'v_light' ERROR: 0:16: Use of undeclared identifier 'v_light' ERROR: 0:17: Use of undeclared identifier 'v_texCoord' ERROR: 0:18: Use of undeclared identifier 'v_light' ERROR: 0:19: failed to load shader Program ended with exit code: 1
У меня MacBook Pro 13 mid2018, Intel Iris Plus Graphics 655, macOS Mojave 10.14.16, Xcode 10.3. Возможно ли обновить до OpenGL 3.3?