2017-06-19 16:53:38 +00:00
|
|
|
// Copyright 2017 The NXT Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "utils/BackendBinding.h"
|
2017-06-19 16:53:38 +00:00
|
|
|
|
|
|
|
#include "GLFW/glfw3.h"
|
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
namespace opengl {
|
|
|
|
void Init(void* (*getProc)(const char*), nxtProcTable* procs, nxtDevice* device);
|
2017-07-12 00:49:20 +00:00
|
|
|
void HACKCLEAR(nxtDevice device);
|
|
|
|
void InitBackbuffer(nxtDevice device);
|
|
|
|
void CommitBackbuffer(nxtDevice device);
|
2017-06-19 16:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace utils {
|
|
|
|
class OpenGLBinding : public BackendBinding {
|
|
|
|
public:
|
|
|
|
void SetupGLFWWindowHints() override {
|
2017-07-12 16:56:05 +00:00
|
|
|
#if defined(NXT_PLATFORM_APPLE)
|
2017-06-19 16:53:38 +00:00
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#else
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
backend::opengl::Init(reinterpret_cast<void*(*)(const char*)>(glfwGetProcAddress), procs, device);
|
2017-07-12 00:49:20 +00:00
|
|
|
|
|
|
|
backendDevice = *device;
|
|
|
|
backend::opengl::InitBackbuffer(backendDevice);
|
2017-06-19 16:53:38 +00:00
|
|
|
}
|
|
|
|
void SwapBuffers() override {
|
2017-07-12 00:49:20 +00:00
|
|
|
backend::opengl::CommitBackbuffer(backendDevice);
|
2017-06-19 16:53:38 +00:00
|
|
|
glfwSwapBuffers(window);
|
2017-07-12 00:49:20 +00:00
|
|
|
backend::opengl::HACKCLEAR(backendDevice);
|
2017-06-19 16:53:38 +00:00
|
|
|
}
|
2017-07-12 00:49:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nxtDevice backendDevice = nullptr;
|
2017-06-19 16:53:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BackendBinding* CreateOpenGLBinding() {
|
|
|
|
return new OpenGLBinding;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|