Created
August 12, 2022 06:54
-
-
Save anatawa12/6fd75182296019b01dd5da0fbaefa26c to your computer and use it in GitHub Desktop.
The test to know which format of texture is accepted by OpenVR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GL_RED: ovr error: VROverlayError_InvalidTexture | |
GL_RG: ovr error: VROverlayError_InvalidTexture | |
GL_RGB: ovr error: VROverlayError_InvalidTexture | |
GL_RGBA: successfull | |
GL_R8: successfull | |
GL_R8_SNORM: successfull | |
GL_R16: successfull | |
GL_R16_SNORM: successfull | |
GL_RG8: successfull | |
GL_RG8_SNORM: successfull | |
GL_RG16: successfull | |
GL_RG16_SNORM: successfull | |
GL_R3_G3_B2: successfull | |
GL_RGB4: successfull | |
GL_RGB5: successfull | |
GL_RGB8: successfull | |
GL_RGB8_SNORM: successfull | |
GL_RGB10: successfull | |
GL_RGB12: successfull | |
GL_RGB16_SNORM: successfull | |
GL_RGBA2: successfull | |
GL_RGBA4: successfull | |
GL_RGB5_A1: successfull | |
GL_RGBA8: successfull | |
GL_RGBA8_SNORM: successfull | |
GL_RGB10_A2: successfull | |
GL_RGB10_A2UI: gl error: invalid operation | |
GL_RGBA12: successfull | |
GL_RGBA16: successfull | |
GL_SRGB8: successfull | |
GL_SRGB8_ALPHA8: successfull | |
GL_R16F: successfull | |
GL_RG16F: successfull | |
GL_RGB16F: successfull | |
GL_RGBA16F: successfull | |
GL_R32F: successfull | |
GL_RG32F: successfull | |
GL_RGB32F: successfull | |
GL_RGBA32F: successfull | |
GL_R11F_G11F_B10F: successfull | |
GL_RGB9_E5: successfull | |
GL_R8I: gl error: invalid operation | |
GL_R8UI: gl error: invalid operation | |
GL_R16I: gl error: invalid operation | |
GL_R16UI: gl error: invalid operation | |
GL_R32I: gl error: invalid operation | |
GL_R32UI: gl error: invalid operation | |
GL_RG8I: gl error: invalid operation | |
GL_RG8UI: gl error: invalid operation | |
GL_RG16I: gl error: invalid operation | |
GL_RG16UI: gl error: invalid operation | |
GL_RG32I: gl error: invalid operation | |
GL_RG32UI: gl error: invalid operation | |
GL_RGB8I: gl error: invalid operation | |
GL_RGB8UI: gl error: invalid operation | |
GL_RGB16I: gl error: invalid operation | |
GL_RGB16UI: gl error: invalid operation | |
GL_RGB32I: gl error: invalid operation | |
GL_RGB32UI: gl error: invalid operation | |
GL_RGBA8I: gl error: invalid operation | |
GL_RGBA8UI: gl error: invalid operation | |
GL_RGBA16I: gl error: invalid operation | |
GL_RGBA16UI: gl error: invalid operation | |
GL_RGBA32I: gl error: invalid operation | |
GL_RGBA32UI: gl error: invalid operation | |
GL_COMPRESSED_RED: successfull | |
GL_COMPRESSED_RG: successfull | |
GL_COMPRESSED_RGB: successfull | |
GL_COMPRESSED_RGBA: successfull | |
GL_COMPRESSED_SRGB: successfull | |
GL_COMPRESSED_SRGB_ALPHA: successfull | |
GL_COMPRESSED_RED_RGTC1: successfull | |
GL_COMPRESSED_SIGNED_RED_RGTC1: successfull | |
GL_COMPRESSED_RG_RGTC2: successfull | |
GL_COMPRESSED_SIGNED_RG_RGTC2: successfull | |
GL_COMPRESSED_RGBA_BPTC_UNORM: successfull | |
GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM: successfull | |
GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT: successfull | |
GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT: successfull |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by anatawa12 on 8/12/22. | |
// | |
#include <GL/glew.h> | |
#include <openvr.h> | |
#include <SDL.h> | |
#include <iostream> | |
#include <vector> | |
#pragma clang diagnostic push | |
int main(int argc, char **argv) { | |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
SDL_Window *window = SDL_CreateWindow( | |
"ovr texture test", | |
0, 0, | |
256, 256, | |
SDL_WINDOW_OPENGL); | |
if (!window) { | |
std::cerr << "sdl error: " << SDL_GetError() << std::endl; | |
return 1; | |
} | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); | |
SDL_GLContext context = SDL_GL_CreateContext(window); | |
if (!context) { | |
std::cerr << "sdl error: " << SDL_GetError() << std::endl; | |
return 1; | |
} | |
glewExperimental = true; | |
glewInit(); | |
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
{ | |
vr::HmdError err; | |
vr::VR_Init(&err, vr::EVRApplicationType::VRApplication_Overlay); | |
if (!vr::VROverlay()) { | |
std::cerr << "error: " << vr::VR_GetVRInitErrorAsEnglishDescription(err) << std::endl; | |
return 1; | |
} | |
} | |
if (SDL_Init(SDL_INIT_VIDEO)) { | |
std::cerr << "sdl error: " << SDL_GetError() << std::endl; | |
return 1; | |
} | |
vr::VROverlayHandle_t overlay_handle; | |
vr::VROverlayError overlay_err; | |
overlay_err = vr::VROverlay()->CreateOverlay("com.anatawa12.ovr_tex_limit", "ovr_tex_limit", &overlay_handle); | |
if (overlay_err != vr::VROverlayError_None){ | |
std::cerr << "overlay error: " << vr::VROverlay()->GetOverlayErrorNameFromEnum(overlay_err) << std::endl; | |
return 1; | |
} | |
vr::VROverlay()->SetOverlayWidthInMeters(overlay_handle, 2); | |
vr::VROverlay()->SetOverlayAlpha(overlay_handle, 0.7); | |
GLuint texture; | |
glGenTextures(1, &texture); | |
glBindTexture(GL_TEXTURE_2D, texture); | |
std::vector<int8_t> tex_data(256 * 256 * 4); | |
for (int i = 0; i < tex_data.size(); i += 4) { | |
tex_data[i + 0] = 0x08; | |
tex_data[i + 1] = 0x04; | |
tex_data[i + 2] = 0x0C; | |
tex_data[i + 3] = 0x0F; | |
} | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
GLenum err; | |
if ((err = glGetError())) { | |
std::cerr << "gl error: " << gluErrorString(err) << std::endl; | |
return 1; | |
} | |
struct named { | |
GLenum format; | |
const char *name; | |
}; | |
#pragma ide diagnostic ignored "OCUnusedMacroInspection" // used in tex_formats.txt | |
#define texture_format(definition) { definition, #definition }, | |
#pragma clang diagnostic pop | |
std::vector<named> texture_formats = { | |
#include "tex_formats.txt" | |
}; | |
vr::Texture_t vr_texture = {}; | |
vr_texture.handle = (void *)(uintptr_t)texture; | |
vr_texture.eType = vr::TextureType_OpenGL; | |
vr_texture.eColorSpace = vr::ColorSpace_Auto; | |
for (const auto &item: texture_formats) | |
{ | |
glTexImage2D(GL_TEXTURE_2D, 0, item.format, 256, 256, 0, GL_RGBA, GL_BYTE, tex_data.data()); | |
if ((err = glGetError())) { | |
std::cout << item.name << ": gl error: " << gluErrorString(err) << std::endl; | |
continue; | |
} | |
while(glGetError()); // clear error | |
overlay_err = vr::VROverlay()->SetOverlayTexture(overlay_handle, &vr_texture); | |
if (overlay_err != vr::VROverlayError_None) { | |
std::cout << item.name << ": ovr error: " << vr::VROverlay()->GetOverlayErrorNameFromEnum(overlay_err) << std::endl; | |
continue; | |
} | |
std::cout << item.name << ": successfull" << std::endl; | |
} | |
vr::VR_Shutdown(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// base formats | |
//texture_format(GL_DEPTH_STENCIL) | |
texture_format(GL_RED) | |
texture_format(GL_RG) | |
texture_format(GL_RGB) | |
texture_format(GL_RGBA) | |
// Sized formats | |
texture_format(GL_R8) | |
texture_format(GL_R8_SNORM) | |
texture_format(GL_R16) | |
texture_format(GL_R16_SNORM) | |
texture_format(GL_RG8) | |
texture_format(GL_RG8_SNORM) | |
texture_format(GL_RG16) | |
texture_format(GL_RG16_SNORM) | |
texture_format(GL_R3_G3_B2) | |
texture_format(GL_RGB4) | |
texture_format(GL_RGB5) | |
texture_format(GL_RGB8) | |
texture_format(GL_RGB8_SNORM) | |
texture_format(GL_RGB10) | |
texture_format(GL_RGB12) | |
texture_format(GL_RGB16_SNORM) | |
texture_format(GL_RGBA2) | |
texture_format(GL_RGBA4) | |
texture_format(GL_RGB5_A1) | |
texture_format(GL_RGBA8) | |
texture_format(GL_RGBA8_SNORM) | |
texture_format(GL_RGB10_A2) | |
texture_format(GL_RGB10_A2UI) | |
texture_format(GL_RGBA12) | |
texture_format(GL_RGBA16) | |
texture_format(GL_SRGB8) | |
texture_format(GL_SRGB8_ALPHA8) | |
texture_format(GL_R16F) | |
texture_format(GL_RG16F) | |
texture_format(GL_RGB16F) | |
texture_format(GL_RGBA16F) | |
texture_format(GL_R32F) | |
texture_format(GL_RG32F) | |
texture_format(GL_RGB32F) | |
texture_format(GL_RGBA32F) | |
texture_format(GL_R11F_G11F_B10F) | |
texture_format(GL_RGB9_E5) | |
texture_format(GL_R8I) | |
texture_format(GL_R8UI) | |
texture_format(GL_R16I) | |
texture_format(GL_R16UI) | |
texture_format(GL_R32I) | |
texture_format(GL_R32UI) | |
texture_format(GL_RG8I) | |
texture_format(GL_RG8UI) | |
texture_format(GL_RG16I) | |
texture_format(GL_RG16UI) | |
texture_format(GL_RG32I) | |
texture_format(GL_RG32UI) | |
texture_format(GL_RGB8I) | |
texture_format(GL_RGB8UI) | |
texture_format(GL_RGB16I) | |
texture_format(GL_RGB16UI) | |
texture_format(GL_RGB32I) | |
texture_format(GL_RGB32UI) | |
texture_format(GL_RGBA8I) | |
texture_format(GL_RGBA8UI) | |
texture_format(GL_RGBA16I) | |
texture_format(GL_RGBA16UI) | |
texture_format(GL_RGBA32I) | |
texture_format(GL_RGBA32UI) | |
// Compressed formats | |
texture_format(GL_COMPRESSED_RED) | |
texture_format(GL_COMPRESSED_RG) | |
texture_format(GL_COMPRESSED_RGB) | |
texture_format(GL_COMPRESSED_RGBA) | |
texture_format(GL_COMPRESSED_SRGB) | |
texture_format(GL_COMPRESSED_SRGB_ALPHA) | |
texture_format(GL_COMPRESSED_RED_RGTC1) | |
texture_format(GL_COMPRESSED_SIGNED_RED_RGTC1) | |
texture_format(GL_COMPRESSED_RG_RGTC2) | |
texture_format(GL_COMPRESSED_SIGNED_RG_RGTC2) | |
texture_format(GL_COMPRESSED_RGBA_BPTC_UNORM) | |
texture_format(GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM) | |
texture_format(GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT) | |
texture_format(GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment