GLPresenter::GLPresenter(DeckLinkCapture &capture, int w, int h, int hz) : data_size(w*h*2), capture(capture), running(true), fullscreen(false), useVsync(false), rgbFull(false), texId(0), displayList(0), convertUYVY(NULL), buffer(NULL), buffer2(NULL), reqW(w), reqH(h), reqHz(hz), frameIndex(0), drawnFrameIndex(0), aspect(16.0/9.0), oneToNScaleFactor(-1.0) { self = this; sprintf(prepend, "#define FRAME_WIDTH %d\n#define FRAME_HEIGHT %d\n", reqW, reqH); RT_ASSERT(glfwInit() == GL_TRUE, "Failed to initalize GLFW."); RT_ASSERT(glfwOpenWindow(w, h, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) == GL_TRUE, "Failed to open GLFW window."); string title("PtBi "); title += VER_STRING; glfwSetWindowTitle(title.c_str()); glfwSetWindowPos(10, 10); dataPointers[0] = malloc(data_size); dataPointers[1] = malloc(data_size); glewInit(); checkExtensions(); ilInit(); glfwDisable(GLFW_AUTO_POLL_EVENTS); glfwSwapInterval(0); glfwSetWindowCloseCallback(closeCallback); glfwSetWindowSizeCallback(resizeCallback); glfwSetMousePosCallback(mousePosCallback); glfwSetKeyCallback(keyCallback); hdc = wglGetCurrentDC(); hrc = wglGetCurrentContext(); initGL(); convertUYVY = new GLFragmentProgram("shaders/uyvy_to_rgb_smooth.glsl", getShaderPrependString()); buffer = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); buffer->setFilterMode(GL_LINEAR); buffer2 = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); buffer2->setFilterMode(GL_LINEAR); scalingManager = new ScalingManager(*this); aaManager = new AAManager(*this); ipManager = new IPManager(*this); keyBinding = new KeyBinding(this); capture.registerDisplayListener(this); hwnd = GetForegroundWindow(); RT_GL_ASSERT("Error during GL initialization."); reshape(reqW, reqH); }
// Test that invalid IDs in CopySubTexture are validated TEST_P(CopyTextureTest, CopySubTextureInvalidTextureIds) { if (!checkExtensions()) { return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glCopySubTextureCHROMIUM(mTextures[0], 99993, 1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); glCopySubTextureCHROMIUM(99994, mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); glCopySubTextureCHROMIUM(99995, 99996, 1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); }
// Test the destination texture cannot be immutable TEST_P(CopyCompressedTextureTest, Immutable) { if (!checkExtensions() || getClientMajorVersion() < 3) { return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, sizeof(CompressedImageDXT1), CompressedImageDXT1); ASSERT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexStorage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); ASSERT_GL_NO_ERROR(); glCompressedCopyTextureCHROMIUM(mTextures[0], mTextures[1]); EXPECT_GL_ERROR(GL_INVALID_OPERATION); }
// Test that using an offset in CopySubTexture works correctly TEST_P(CopyTextureTest, CopySubTextureOffset) { if (!checkExtensions()) { return; } GLColor rgbaPixels[4 * 4] = {GLColor::red, GLColor::green, GLColor::blue, GLColor::black}; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); GLColor transparentPixels[4 * 4] = {GLColor::transparentBlack, GLColor::transparentBlack, GLColor::transparentBlack, GLColor::transparentBlack}; glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, transparentPixels); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 0, 1, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 1, 0, 1, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); // Check that FB is complete. EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack); EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red); EXPECT_PIXEL_COLOR_EQ(1, 0, GLColor::green); EXPECT_PIXEL_COLOR_EQ(0, 1, GLColor::blue); EXPECT_GL_NO_ERROR(); }
// Test that unmultipying and premultiplying the alpha is the same as doing neither TEST_P(CopyTextureTest, UnmultiplyAndPremultplyAlpha) { if (!checkExtensions()) { return; } GLColor rgbaPixels[4] = {GLColor(255u, 255u, 255u, 255u), GLColor(127u, 127u, 127u, 127u), GLColor(63u, 63u, 63u, 127u), GLColor(255u, 255u, 255u, 0u)}; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgbaPixels); glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, GL_FALSE, GL_TRUE, GL_TRUE); EXPECT_GL_NO_ERROR(); // Check that FB is complete. EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(255, 255, 255, 255), 1.0); EXPECT_PIXEL_COLOR_NEAR(1, 0, GLColor(127, 127, 127, 127), 1.0); EXPECT_PIXEL_COLOR_NEAR(0, 1, GLColor(63, 63, 63, 127), 1.0); EXPECT_PIXEL_COLOR_NEAR(1, 1, GLColor(255, 255, 255, 0), 1.0); EXPECT_GL_NO_ERROR(); }
// Test that only 2D textures are valid TEST_P(CopyCompressedTextureTest, BindingPoints) { if (!checkExtensions()) { return; } glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[0]); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); for (GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++) { glCompressedTexImage2D(face, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, sizeof(CompressedImageDXT1), CompressedImageDXT1); } ASSERT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[1]); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); ASSERT_GL_NO_ERROR(); glCompressedCopyTextureCHROMIUM(mTextures[0], mTextures[1]); EXPECT_GL_ERROR(GL_INVALID_VALUE); }
// Test validation of texture IDs TEST_P(CopyCompressedTextureTest, InvalidTextureIds) { if (!checkExtensions()) { return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, sizeof(CompressedImageDXT1), CompressedImageDXT1); ASSERT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); ASSERT_GL_NO_ERROR(); glCompressedCopyTextureCHROMIUM(mTextures[0], 99993); EXPECT_GL_ERROR(GL_INVALID_VALUE); glCompressedCopyTextureCHROMIUM(99994, mTextures[1]); EXPECT_GL_ERROR(GL_INVALID_VALUE); glCompressedCopyTextureCHROMIUM(99995, 99996); EXPECT_GL_ERROR(GL_INVALID_VALUE); glCompressedCopyTextureCHROMIUM(mTextures[0], mTextures[1]); EXPECT_GL_NO_ERROR(); }
// Test that uncompressed textures generate errors when copying TEST_P(CopyCompressedTextureTest, InternalFormatNotSupported) { if (!checkExtensions()) { return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::red); ASSERT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); ASSERT_GL_NO_ERROR(); // Check that the GL_RGBA format reports an error. glCompressedCopyTextureCHROMIUM(mTextures[0], mTextures[1]); EXPECT_GL_ERROR(GL_INVALID_OPERATION); }
// Test that invalid dimensions in CopySubTexture are validated TEST_P(CopyTextureTest, CopySubTextureDimension) { if (!checkExtensions()) { return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); // xoffset < 0 glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], -1, 1, 0, 0, 1, 1, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); // x < 0 glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 1, 1, -1, 0, 1, 1, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); // xoffset + width > dest_width glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 2, 2, 0, 0, 2, 2, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); // x + width > source_width glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 1, 1, 2, 2, false, false, false); EXPECT_GL_ERROR(GL_INVALID_VALUE); }
// Test to ensure that the basic functionality of the extension works. TEST_P(CopyTextureTest, BasicCopySubTexture) { if (!checkExtensions()) { return; } GLColor pixels = GLColor::red; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); // Check that FB is complete. EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); EXPECT_GL_NO_ERROR(); }
void hrCache::setContext(const QGLContext *context) { if (context->isValid()) { hr_glCompressedTexImage2DARB = (pfn_glCompressedTexImage2DARB)context->getProcAddress(QLatin1String("glCompressedTexImage2DARB")); if (!hr_glCompressedTexImage2DARB) { qWarning("hrCache: glCompressed* functions not found"); } checkExtensions(); } else { qFatal("hrCache: invalid context"); } }
// Test to ensure that the basic functionality of the extension works. TEST_P(CopyCompressedTextureTest, Basic) { if (!checkExtensions()) { return; } if (!extensionEnabled("GL_EXT_texture_compression_dxt1")) { std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available." << std::endl; return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, sizeof(CompressedImageDXT1), CompressedImageDXT1); ASSERT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glCompressedCopyTextureCHROMIUM(mTextures[0], mTextures[1]); ASSERT_GL_NO_ERROR(); // Load texture. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, mTextures[1]); GLint textureLoc = glGetUniformLocation(mProgram, "u_texture"); glUseProgram(mProgram); glUniform1i(textureLoc, 0); // Draw. drawQuad(mProgram, "a_position", 0.5f); EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, CompressedImageColor); ASSERT_GL_NO_ERROR(); }
// Test that CopyTexture cannot redefine an immutable texture and CopySubTexture can copy data to // immutable textures TEST_P(CopyTextureTest, ImmutableTexture) { if (!checkExtensions()) { return; } if (getClientMajorVersion() < 3 && (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8"))) { std::cout << "Test skipped due to missing ES3 or GL_EXT_texture_storage or GL_OES_rgb8_rgba8" << std::endl; return; } GLColor pixels = GLColor::red; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8_OES, 1, 1); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], 0); EXPECT_GL_NO_ERROR(); // Should generate an error when the texture is redefined glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); EXPECT_GL_ERROR(GL_INVALID_OPERATION); // Should succeed when using CopySubTexture glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); // Check that FB is complete. EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); EXPECT_GL_NO_ERROR(); }
bool init(int argc, char *argv[]){ setDataDir(argc, argv); initGLFW(); ogle::initGLEW(); bool found_extensions = checkExtensions(); if (!found_extensions) return false; ogle::Debug::init(); initGLSettings(); createParticles(); createBufferObject(); return true; }
// Test to ensure that the basic functionality of the extension works. TEST_P(CopyTextureTest, BasicCopyTexture) { if (!checkExtensions()) { return; } GLColor pixels = GLColor::red; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels); glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); EXPECT_GL_NO_ERROR(); EXPECT_PIXEL_COLOR_EQ(0, 0, pixels); }
// Test to ensure that the destination texture is redefined if the properties are different. TEST_P(CopyTextureTest, RedefineDestinationTexture) { if (!checkExtensions()) { return; } GLColor pixels[4] = {GLColor::red, GLColor::red, GLColor::red, GLColor::red}; glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, 1, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); EXPECT_GL_NO_ERROR(); // GL_INVALID_OPERATION due to "intrinsic format" != "internal format". glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); EXPECT_GL_ERROR(GL_INVALID_OPERATION); // GL_INVALID_VALUE due to bad dimensions. glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); EXPECT_GL_ERROR(GL_INVALID_VALUE); // If the dest texture has different properties, glCopyTextureCHROMIUM() // redefines them. glCopyTextureCHROMIUM(mTextures[0], mTextures[1], GL_RGBA, GL_UNSIGNED_BYTE, false, false, false); EXPECT_GL_NO_ERROR(); // glTexSubImage2D() succeeds because mTextures[1] is redefined into 2x2 // dimension and GL_RGBA format. glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); EXPECT_GL_NO_ERROR(); // Check that FB is complete. EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); EXPECT_PIXEL_COLOR_EQ(1, 1, pixels[3]); EXPECT_GL_NO_ERROR(); }
/* Initializes opengl states */ void glutWidget::initOpenGL() { glewExperimental = GL_TRUE; GLenum err = glewInit(); //initialize GLEW - this enables us to use extensions if(err != GLEW_OK) { std::cout << "ERROR: Loading GLEW failed." << std::endl; exit(-1); } checkExtensions(); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //default "empty"/background color is set to white glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); makeShaders(); //load data of fragment and vertex programs/shaders - compile shaders srand(time(NULL)); color = rand() % 100 + 1; }
void hrRender::initializeGL() { checkExtensions(); hrCache& cache = hrCache::Get(); cache.setContext(context()); glViewport(0, 0, width()*devicePixelRatio(), height()*devicePixelRatio()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width()*devicePixelRatio(), height()*devicePixelRatio(), 0, -1.0, 1.0); // Make sure depth testing and lighting are disabled for 2D rendering glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_DITHER); glShadeModel(GL_FLAT); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); }
// Check that invalid internal formats return errors. TEST_P(CopyTextureTest, InternalFormatNotSupported) { if (!checkExtensions()) { return; } glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); EXPECT_GL_NO_ERROR(); std::vector<GLint> unsupportedDestFormats; unsupportedDestFormats.push_back(GL_ALPHA); unsupportedDestFormats.push_back(GL_LUMINANCE); unsupportedDestFormats.push_back(GL_LUMINANCE_ALPHA); if (!extensionEnabled("GL_EXT_texture_format_BGRA8888")) { unsupportedDestFormats.push_back(GL_BGRA_EXT); } // Check unsupported format reports an error. for (GLint unsupportedDestFormat : unsupportedDestFormats) { glCopyTextureCHROMIUM(mTextures[0], mTextures[1], unsupportedDestFormat, GL_UNSIGNED_BYTE, false, false, false); EXPECT_GL_ERROR(GL_INVALID_OPERATION); } for (GLint unsupportedDestFormat : unsupportedDestFormats) { glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, unsupportedDestFormat, 1, 1, 0, unsupportedDestFormat, GL_UNSIGNED_BYTE, nullptr); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); EXPECT_GL_ERROR(GL_INVALID_OPERATION); } }
/* Initializes opengl states */ void glutWidget::initOpenGL() { glewExperimental = GL_TRUE; GLenum err = glewInit(); //initialize GLEW - this enables us to use extensions if(err != GLEW_OK) { std::cout << "ERROR: Loading GLEW failed." << std::endl; exit(-1); } checkExtensions(); glClearColor(1, 1, 1, 0); //default "empty"/background color is set to white glEnable(GL_DEPTH_TEST); CBitmap skybox("skybox.bmp"); //read bitmap image glGenTextures(1, &m_texture); //allocate 1 texture glUniform1i(skybox_texture, 0); //pass texture location to vertex shader glBindTexture(GL_TEXTURE_2D, skybox_texture); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, skybox.GetWidth(), skybox.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, skybox.GetBits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); //specify texture coordinate treatment glBindTexture(GL_TEXTURE_2D, 0); CBitmap streets("streets.bmp"); //read bitmap image glGenTextures(1, &street_texture); //allocate 1 texture glUniform1i(street_texture, 0); //pass texture location to vertex shader glBindTexture(GL_TEXTURE_2D, street_texture); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, streets.GetWidth(), streets.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, streets.GetBits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //specify texture coordinate treatment glBindTexture(GL_TEXTURE_2D, 0); //bind default texture to be active CBitmap car("car.bmp"); //read bitmap image glGenTextures(1, &car_texture); //allocate 1 texture glUniform1i(car_texture, 0); //pass texture location to vertex shader glBindTexture(GL_TEXTURE_2D, car_texture); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, car.GetWidth(), car.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, car.GetBits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //specify texture coordinate treatment glBindTexture(GL_TEXTURE_2D, 0); //bind default texture to be active CBitmap structure("structure.bmp"); //read bitmap image glGenTextures(1, &structure_texture); //allocate 1 texture glUniform1i(structure_texture, 0); //pass texture location to vertex shader glBindTexture(GL_TEXTURE_2D, structure_texture); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, structure.GetWidth(), structure.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, structure.GetBits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //specify texture coordinate treatment glBindTexture(GL_TEXTURE_2D, 0); //bind default texture to be active CBitmap wall("wall.bmp"); //read bitmap image glGenTextures(1, &wall_texture); //allocate 1 texture glUniform1i(wall_texture, 0); //pass texture location to vertex shader glBindTexture(GL_TEXTURE_2D, wall_texture); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wall.GetWidth(), wall.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, wall.GetBits()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //specify texture coordinate treatment glBindTexture(GL_TEXTURE_2D, 0); //bind default texture to be active makeShaders(); //load data of fragment and vertex programs/shaders - compile shaders glMatrixMode(GL_PROJECTION); glLoadIdentity(); //initializes projection matrix with identity gluPerspective(60,(float)m_width/(float)m_height,0.1,1000); //set up projection mode (field of view, aspect ratio, near and far clipping plane) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //initializes modelview matrix with identity glEnable(GL_CULL_FACE); }
GLPresenter::GLPresenter(DeckLinkCapture &capture, int w, int h, int hz) : data_size(w*h*capture.getBytesPerPixel()), capture(capture), running(true), fullscreen(false), useVsync(false), rgbFull(false), texId(0), displayList(0), initialConvert(NULL), buffer(NULL), buffer2(NULL), reqW(w), reqH(h), reqHz(hz), captureBufferW(reqW / (4 / capture.getBytesPerPixel())), frameIndex(0), drawnFrameIndex(0), aspect(16.0/9.0), oneToNScaleFactor(-1.0), frameProcTimes(300) { self = this; sprintf(prepend, "#version 410 compatibility \n#define FRAME_WIDTH %d \n#define FRAME_HEIGHT %d \n", reqW, reqH); RT_ASSERT(glfwInit() == GL_TRUE, "Failed to initalize GLFW."); RT_ASSERT(glfwOpenWindow(w, h, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) == GL_TRUE, "Failed to open GLFW window."); string title("PtBi "); title += VER_STRING; glfwSetWindowTitle(title.c_str()); glfwSetWindowPos(10, 10); dataPointers[0] = malloc(data_size); dataPointers[1] = malloc(data_size); glewInit(); checkExtensions(); ilInit(); glfwDisable(GLFW_AUTO_POLL_EVENTS); glfwSwapInterval(0); glfwSetWindowCloseCallback(closeCallback); glfwSetWindowSizeCallback(resizeCallback); glfwSetMousePosCallback(mousePosCallback); glfwSetKeyCallback(keyCallback); hdc = wglGetCurrentDC(); hrc = wglGetCurrentContext(); initGL(); switch(capture.getPixelFormat()) { case CapturePixelFormat::YUV: initialConvert = new GLFragmentProgram("shaders/uyvy_to_rgb_smooth.glsl", getShaderPrependString()); break; case CapturePixelFormat::ARGB8: initialConvert = new GLFragmentProgram("shaders/argb_input.glsl", getShaderPrependString()); break; case CapturePixelFormat::BGRA8: initialConvert = new GLFragmentProgram("shaders/bgra_input.glsl", getShaderPrependString()); break; default: RT_ASSERT(false, "Unsupported pixel type."); } buffer = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); buffer->setFilterMode(GL_LINEAR); buffer2 = new GLRenderTexture(getW(), getH(), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE); buffer2->setFilterMode(GL_LINEAR); scalingManager = new ScalingManager(*this); aaManager = new AAManager(*this); ipManager = new IPManager(*this); keyBinding = new KeyBinding(this); capture.registerDisplayListener(this); hwnd = GetForegroundWindow(); RT_GL_ASSERT("Error during GL initialization."); reshape(reqW, reqH); graphicsReportText = std::make_shared<StaticText>("", 25.0f,440.0f); Console::get().add(graphicsReportText); }
// Test validation of compressed formats TEST_P(CopyCompressedTextureTest, InternalFormat) { if (!checkExtensions()) { return; } struct Data { GLint format; const uint8_t *data; GLsizei dataSize; Data() : Data(GL_NONE, nullptr, 0) {} Data(GLint format, const uint8_t *data, GLsizei dataSize) : format(format), data(data), dataSize(dataSize) { } }; std::vector<Data> supportedFormats; if (extensionEnabled("GL_AMD_compressed_ATC_texture")) { supportedFormats.push_back( Data(GL_ATC_RGB_AMD, CompressedImageATC, sizeof(CompressedImageATC))); supportedFormats.push_back(Data(GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, CompressedImageATCIA, sizeof(CompressedImageATCIA))); } if (extensionEnabled("GL_EXT_texture_compression_dxt1")) { supportedFormats.push_back(Data(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, CompressedImageDXT1, sizeof(CompressedImageDXT1))); } if (extensionEnabled("GL_ANGLE_texture_compression_dxt5")) { supportedFormats.push_back(Data(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, CompressedImageDXT5, sizeof(CompressedImageDXT5))); } if (extensionEnabled("GL_OES_compressed_ETC1_RGB8_texture")) { supportedFormats.push_back( Data(GL_ETC1_RGB8_OES, CompressedImageETC1, sizeof(CompressedImageETC1))); } for (const auto &supportedFormat : supportedFormats) { glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glCompressedTexImage2D(GL_TEXTURE_2D, 0, supportedFormat.format, 4, 4, 0, supportedFormat.dataSize, supportedFormat.data); ASSERT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glCompressedCopyTextureCHROMIUM(mTextures[0], mTextures[1]); ASSERT_GL_NO_ERROR(); } }
// Test validation of internal formats in CopyTexture and CopySubTexture TEST_P(CopyTextureTest, InternalFormat) { if (!checkExtensions()) { return; } std::vector<GLint> sourceFormats; sourceFormats.push_back(GL_ALPHA); sourceFormats.push_back(GL_RGB); sourceFormats.push_back(GL_RGBA); sourceFormats.push_back(GL_LUMINANCE); sourceFormats.push_back(GL_LUMINANCE_ALPHA); std::vector<GLint> destFormats; destFormats.push_back(GL_RGB); destFormats.push_back(GL_RGBA); if (extensionEnabled("GL_EXT_texture_format_BGRA8888")) { sourceFormats.push_back(GL_BGRA_EXT); destFormats.push_back(GL_BGRA_EXT); } // Test with glCopyTexture for (GLint sourceFormat : sourceFormats) { for (GLint destFormat : destFormats) { glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, sourceFormat, 1, 1, 0, sourceFormat, GL_UNSIGNED_BYTE, nullptr); EXPECT_GL_NO_ERROR(); glCopyTextureCHROMIUM(mTextures[0], mTextures[1], destFormat, GL_UNSIGNED_BYTE, false, false, false); EXPECT_GL_NO_ERROR(); } } // Test with glCopySubTexture for (GLint sourceFormat : sourceFormats) { for (GLint destFormat : destFormats) { glBindTexture(GL_TEXTURE_2D, mTextures[0]); glTexImage2D(GL_TEXTURE_2D, 0, sourceFormat, 1, 1, 0, sourceFormat, GL_UNSIGNED_BYTE, nullptr); EXPECT_GL_NO_ERROR(); glBindTexture(GL_TEXTURE_2D, mTextures[1]); glTexImage2D(GL_TEXTURE_2D, 0, destFormat, 1, 1, 0, destFormat, GL_UNSIGNED_BYTE, nullptr); EXPECT_GL_NO_ERROR(); glCopySubTextureCHROMIUM(mTextures[0], mTextures[1], 0, 0, 0, 0, 1, 1, false, false, false); EXPECT_GL_NO_ERROR(); } } }