예제 #1
0
파일: hwdec_vdpau.c 프로젝트: RKalkani/mpv
static void destroy_objects(struct gl_hwdec *hw)
{
    struct priv *p = hw->priv;
    GL *gl = hw->gl;
    struct vdp_functions *vdp = &p->ctx->vdp;
    VdpStatus vdp_st;

    if (p->mapped)
        gl->VDPAUUnmapSurfacesNV(1, &p->vdpgl_surface);
    p->mapped = false;

    if (p->vdpgl_surface)
        gl->VDPAUUnregisterSurfaceNV(p->vdpgl_surface);
    p->vdpgl_surface = 0;

    glDeleteTextures(1, &p->gl_texture);
    p->gl_texture = 0;

    if (p->vdp_surface != VDP_INVALID_HANDLE) {
        vdp_st = vdp->output_surface_destroy(p->vdp_surface);
        CHECK_VDP_WARNING(p, "Error when calling vdp_output_surface_destroy");
    }
    p->vdp_surface = VDP_INVALID_HANDLE;

    glCheckError(gl, hw->log, "Before uninitializing OpenGL interop");

    if (p->vdpgl_initialized)
        gl->VDPAUFiniNV();

    p->vdpgl_initialized = false;

    glCheckError(gl, hw->log, "After uninitializing OpenGL interop");
}
예제 #2
0
ViewerGL::Implementation::~Implementation()
{
    // always running in the main thread
    assert( qApp && qApp->thread() == QThread::currentThread() );
    _this->makeCurrent();

    if (shaderRGB) {
        shaderRGB->removeAllShaders();
        shaderRGB.reset();
    }
    if (shaderBlack) {
        shaderBlack->removeAllShaders();
        shaderBlack.reset();
    }
    for (int i = 0; i < 2; ++i) {
        displayTextures[i].texture.reset();
    }
    partialUpdateTextures.clear();

    if ( appPTR && appPTR->isOpenGLLoaded() ) {
        glCheckError(GL_GPU);
        for (U32 i = 0; i < this->pboIds.size(); ++i) {
            GL_GPU::glDeleteBuffers(1, &this->pboIds[i]);
        }
        glCheckError(GL_GPU);
        GL_GPU::glDeleteBuffers(1, &this->vboVerticesId);
        GL_GPU::glDeleteBuffers(1, &this->vboTexturesId);
        GL_GPU::glDeleteBuffers(1, &this->iboTriangleStripId);
        glCheckError(GL_GPU);
        GL_GPU::glDeleteTextures(1, &this->checkerboardTextureID);
    }
}
void	Perlin3DViewerWidget::initializeGL()
{

    std::cerr << "FreeFlyCameraWidget::initializeGL" << std::endl;

    FreeFlyCameraWidget::initializeGL();

    ///

    _shader.init();

    glCheckError();

    ///

    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClearDepth(1.0f);

    glCheckError();

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glEnable(GL_LINE_SMOOTH);

    glCheckError();
}
예제 #4
0
ViewerGL::Implementation::~Implementation()
{
    // always running in the main thread
    assert( qApp && qApp->thread() == QThread::currentThread() );
    _this->makeCurrent();

    if (this->shaderRGB) {
        this->shaderRGB->removeAllShaders();
        delete this->shaderRGB;
    }
    if (this->shaderBlack) {
        this->shaderBlack->removeAllShaders();
        delete this->shaderBlack;
    }
    displayTextures[0].reset();
    displayTextures[1].reset();
    partialUpdateTextures.clear();
    glCheckError();
    for (U32 i = 0; i < this->pboIds.size(); ++i) {
        glDeleteBuffers(1, &this->pboIds[i]);
    }
    glCheckError();
    glDeleteBuffers(1, &this->vboVerticesId);
    glDeleteBuffers(1, &this->vboTexturesId);
    glDeleteBuffers(1, &this->iboTriangleStripId);
    glCheckError();
    delete this->textFont;
    glDeleteTextures(1, &this->checkerboardTextureID);
}
예제 #5
0
파일: View3D.cpp 프로젝트: r-chris/displaz
void View3D::initializeGL()
{
    if (glewInit() != GLEW_OK)
    {
        g_logger.error("%s", "Failed to initialize GLEW");
        m_badOpenGL = true;
        return;
    }

    g_logger.info("OpenGL implementation:\n"
                  "  GL_VENDOR    = %s\n"
                  "  GL_RENDERER  = %s\n"
                  "  GL_VERSION   = %s\n"
                  "  GLSL_VERSION = %s\n"
                  "  GLEW_VERSION = %s",
                  (const char*)glGetString(GL_VENDOR),
                  (const char*)glGetString(GL_RENDERER),
                  (const char*)glGetString(GL_VERSION),
                  (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION),
                  (const char*)glewGetString(GLEW_VERSION));

    // GL_CHECK has to be defined for this to actually do something
    glCheckError();

    initCursor(10, 1);
    initAxes();
    initGrid(2.0f);

    glCheckError();

    m_boundingBoxShader.reset(new ShaderProgram());
    m_boundingBoxShader->setShaderFromSourceFile("shaders:bounding_box.glsl");

    m_meshFaceShader.reset(new ShaderProgram());
    m_meshFaceShader->setShaderFromSourceFile("shaders:meshface.glsl");

    m_meshEdgeShader.reset(new ShaderProgram());
    m_meshEdgeShader->setShaderFromSourceFile("shaders:meshedge.glsl");

    m_annotationShader.reset(new ShaderProgram());
    m_annotationShader->setShaderFromSourceFile("shaders:annotation.glsl");

    double dPR = getDevicePixelRatio();
    int w = width() * dPR;
    int h = height() * dPR;

    m_incrementalFramebuffer.init(w, h);

    initializeGLGeometry(0, m_geometries->get().size());

    // FIXME: Do something about this mess.  The shader editor widget needs to
    // be initialized with the default shader, but View3D can only compile
    // shaders after it has a valid OpenGL context.
    PointViewerMainWindow * pv_parent = dynamic_cast<PointViewerMainWindow *>(parentWidget());
    if (pv_parent)
        pv_parent->openShaderFile("shaders:las_points.glsl");

    setFocus();
}
예제 #6
0
CubeMappedTexture::CubeMappedTexture(std::vector< std::string > imageFiles, bool genMipMaps) : TextureBase(GL_TEXTURE_CUBE_MAP) {
    if ( imageFiles.size() != 6 ) {
        throw std::string("CubeMappedTexture: invalid number of images.");
    }
    glCheckError(glGenTextures(1, &TID));
    if ( TID ) {
        glCheckError(glBindTexture(GL_TEXTURE_CUBE_MAP, TID));
        int i = 0;
        for ( auto &fn : imageFiles ) {
            sf::Image data;
            auto fs = loadResource(fn);
            data.loadFromStream(*fs.get());            
            sf::Vector2u size = data.getSize();
            glCheckError(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+(i++), 0, GL_RGBA8, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.getPixelsPtr()));
        }
        if ( genMipMaps ) {
            glCheckError(glGenerateMipmap(GL_TEXTURE_CUBE_MAP));
            glCheckError(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
        } else {
            glCheckError(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
        }
        glCheckError(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
        glCheckError(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
        glCheckError(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
    }
}
예제 #7
0
 void switchTo2D() override {
     if ( !twoD ) {
         twoD = true;
         glCheckError(glBindVertexArray(0));
         glCheckError(glBindBuffer(GL_ARRAY_BUFFER, 0));
         glCheckError(glUseProgram(0));
         glCheckError(glBindTexture(GL_TEXTURE_2D, 0));
         glDepthMask(GL_FALSE);
         T::pushGLStates();
     }
 }
예제 #8
0
파일: texture.cpp 프로젝트: rokuz/DemoScene
bool Texture::initWithData(int32_t format, const uint8_t * buffer,
                           uint32_t width, uint32_t height, bool mipmaps, int pixelFormat)
{
    destroy();

    m_target = GL_TEXTURE_2D;
    m_format = format;
    m_pixelFormat = pixelFormat < 0 ? findPixelFormat(format) : pixelFormat;
    m_width = width;
    m_height = height;
    glGenTextures(1, &m_texture);
    glBindTexture(m_target, m_texture);
    int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1;
    glTexStorage2D(m_target, mipLevels, m_format, m_width, m_height);
    glTexSubImage2D(m_target, 0, 0, 0, m_width, m_height, m_pixelFormat, GL_UNSIGNED_BYTE, buffer);

    setSampling();
    if (mipmaps) generateMipmaps();
    glBindTexture(m_target, 0);

    if (glCheckError())
    {
        destroy();
        return false;
    }

    m_isLoaded = true;
    return m_isLoaded;
}
예제 #9
0
void
ViewerGL::Implementation::drawSelectionRectangle()
{
    {
        GLProtectAttrib<GL_GPU> a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);

        GL_GPU::glEnable(GL_BLEND);
        GL_GPU::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_GPU::glEnable(GL_LINE_SMOOTH);
        GL_GPU::glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);

        GL_GPU::glColor4f(0.5, 0.8, 1., 0.4);
        QPointF btmRight = selectionRectangle.bottomRight();
        QPointF topLeft = selectionRectangle.topLeft();

        GL_GPU::glBegin(GL_POLYGON);
        GL_GPU::glVertex2f( topLeft.x(), btmRight.y() );
        GL_GPU::glVertex2f( topLeft.x(), topLeft.y() );
        GL_GPU::glVertex2f( btmRight.x(), topLeft.y() );
        GL_GPU::glVertex2f( btmRight.x(), btmRight.y() );
        GL_GPU::glEnd();


        GL_GPU::glLineWidth(1.5);

        GL_GPU::glBegin(GL_LINE_LOOP);
        GL_GPU::glVertex2f( topLeft.x(), btmRight.y() );
        GL_GPU::glVertex2f( topLeft.x(), topLeft.y() );
        GL_GPU::glVertex2f( btmRight.x(), topLeft.y() );
        GL_GPU::glVertex2f( btmRight.x(), btmRight.y() );
        GL_GPU::glEnd();

        glCheckError(GL_GPU);
    } // GLProtectAttrib a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
}
void    t_Shader_Perlin3D::init()
{

    // if ( this->isAvailable_shader100() )
        this->prepareShaderProgram( "shaders/test_100.vert.c", "shaders/test_100.frag.c" );

    /**/
    // else // if ( isAvailable_shader150() )
        // this->prepareShaderProgram( "shaders/test_150.vert", "shaders/test_150.frag" );
    //*/


    _location_a_vertex = glGetAttribLocation( _programm_id, "a_vertex" );
    _location_a_color = glGetAttribLocation( _programm_id, "a_color" );
    _location_a_normal = glGetAttribLocation( _programm_id, "a_normal" );

    _location_u_modelviewMatrix = glGetUniformLocationARB( _programm_id, "u_modelviewMatrix" );
    _location_u_projectionMatrix = glGetUniformLocationARB( _programm_id, "u_projectionMatrix" );
    _location_u_mode = glGetUniformLocationARB( _programm_id, "u_mode" );
    _location_u_lightEnabled = glGetUniformLocationARB( _programm_id, "u_lightEnabled" );

    glUniform1i(  _location_u_lightEnabled, 1 );

    glCheckError();
}
예제 #11
0
void idle()
{
	calcFPS();
	glCheckError("idle");

	static Timer t;
	double dt = t.elapsed_time();
	NxSphere person;
	person.center = g_CameraPos;
	person.radius = 2.0f;

	if(IS_KEY_DOWN('w') || IS_KEY_DOWN('W'))
	{
		g_CameraPos += g_CameraForward*g_Speed*dt;
		if(gMyPhysX.getScene()->checkOverlapSphere(person,NX_ALL_SHAPES))
			g_CameraPos -= g_CameraForward*g_Speed*dt;
	}
	if(IS_KEY_DOWN('s') || IS_KEY_DOWN('S'))
	{
		g_CameraPos -= g_CameraForward*g_Speed*dt;
	}
	if(IS_KEY_DOWN('q') || IS_KEY_DOWN('Q'))
		g_CameraPos +=NxVec3(0.0f,1.0f,0.0f)*g_Speed*dt;
	if(IS_KEY_DOWN('e') || IS_KEY_DOWN('E'))
		g_CameraPos -=NxVec3(0.0f,1.0f,0.0f)*g_Speed*dt;
	if(IS_KEY_DOWN('a') || IS_KEY_DOWN('A'))
		g_CameraPos -= g_CameraRight*g_Speed*dt;
	if(IS_KEY_DOWN('d') || IS_KEY_DOWN('D'))
		g_CameraPos += g_CameraRight*g_Speed*dt;

	t.reset();
	glutPostRedisplay();
}
예제 #12
0
	void FrameBuffer::Resize(int width, int height)
	{
		if (m_size.width == width && m_size.height == height)
			return;
		m_size.width = width;
		m_size.height = height;
		auto target = m_enableMSAA ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D;
		glBindTexture(target, m_colorbuffer);
		if (m_enableMSAA)
			glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, m_size.width, m_size.height, GL_TRUE);
		else
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_size.width, m_size.height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
		glBindTexture(target, 0);
		glBindRenderbuffer(GL_RENDERBUFFER, m_depthbuffer);
		if (m_enableMSAA)
			glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, m_size.width, m_size.height);
		else
			glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_size.width, m_size.height); // use a single renderbuffer object for both a depth AND stencil buffer.
		//glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_size.width, m_size.height); // use a single renderbuffer object for both a depth AND stencil buffer.
		glBindRenderbuffer(GL_RENDERBUFFER, 0);

		if (m_enableMSAA)
		{
			glBindTexture(GL_TEXTURE_2D, m_colorbuffer2);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_size.width, m_size.height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
			glBindTexture(GL_TEXTURE_2D, 0);
		}
		glCheckError();
	}
예제 #13
0
////////////////////////////////Main Function//////////////////////////////////////////
int main(int argc, char* argv[])
{
	Timer t;

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH | GLUT_MULTISAMPLE);
	glutInitWindowPosition(SCREEN_WIDTH/8,SCREEN_HEIGHT/8);
	glutInitWindowSize(3*SCREEN_WIDTH/4,3*SCREEN_HEIGHT/4);
	glutCreateWindow(argv[0]);

	init();

	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(getkey);
	glutMouseFunc(Mouse);
	glutMotionFunc(MouseMotion);
	glutIdleFunc(idle);

	glCheckError("main");
	printf("Total time used for loading scene is: %f\n",t.elapsed_time());
	// Initialize physics scene and start the application main loop if scene was created
	if (InitNx())
	{
		atexit(ExitNx);
		glutMainLoop();
	}
	return 0;
}
예제 #14
0
static void destroy_objects(struct gl_hwdec *hw)
{
    struct priv *p = hw->priv;
    GL *gl = hw->gl;
    struct vdp_functions *vdp = &p->ctx->vdp;
    VdpStatus vdp_st;

    if (p->mapped)
        gl->VDPAUUnmapSurfacesNV(1, &p->vdpgl_surface);
    p->mapped = false;

    if (p->vdpgl_surface)
        gl->VDPAUUnregisterSurfaceNV(p->vdpgl_surface);
    p->vdpgl_surface = 0;

    glDeleteTextures(1, &p->gl_texture);
    p->gl_texture = 0;

    if (p->vdp_surface != VDP_INVALID_HANDLE) {
        vdp_st = vdp->output_surface_destroy(p->vdp_surface);
        CHECK_VDP_WARNING(p, "Error when calling vdp_output_surface_destroy");
    }
    p->vdp_surface = VDP_INVALID_HANDLE;

    glCheckError(gl, hw->log, "Before uninitializing OpenGL interop");

    gl->VDPAUFiniNV();

    // If the GL/vdpau state is not initialized, above calls raises an error.
    while (1) {
        if (gl->GetError() == GL_NO_ERROR)
            break;
    }
}
 void onDraw(int nTime)
 {
   float fTime = nTime / 1000.0f;
   sys::info << "app::COGLDev42PCFShadowMapApp::onDraw(nTime) > " << fTime << sys::endl;
   
   CEventManager::getInstance()->trigger(new CUpdateEvent(fTime)); // must
   
   /////////////////////////////////////////////////////
   
   //pObjectP->mPosition = math::vec3(0.0f, sin(fTime) * 3.0f, 0.0f);
   pPointLight->mPosition = math::vec3(sin(fTime) * 1.5f, 2.0f, cos(fTime) * 1.5f);
   pObject1->mPosition = math::vec3(pObject1->mPosition.x, sin(fTime) * 3.0f + 5.0f, cos(fTime) * 3.0f + 1.0f);
   
   /////////////////////////////////////////////////////
   
   pRenderer->setCamera(pCamera);
   pRenderer->addLight(pSpotLight);
   pRenderer->addLight(pDirectLight);
   pRenderer->addLight(pPointLight);
   pRenderer->addDrawable(pObjectB, ogl::EDrawOptions::NOSHADOWCAST);
   pRenderer->addDrawable(pObject0);
   pRenderer->addDrawable(pObject1);
   pRenderer->render();
   
   glCheckError();
   
   // CApp::exit();
 }
예제 #16
0
void Application3D::loop()
{
    // exit on window close button pressed
    if (glfwWindowShouldClose(getWindow()))
        exit();

    float t = getTime();
    // set matrix
    projection = glm::perspective(float(2.0*atan(getHeight()/1920.f)), getWindowRatio(), 0.1f, 100.f);
    view  = glm::lookAt(
        glm::vec3(20.0*sin(t),20.0*cos(t),20.0),
        glm::vec3(0.0,0.0,0.0),
        glm::vec3(0.0,0.0,1.0)
    );

    // clear
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    shaderProgram.use();    

        // send uniforms
        shaderProgram.setUniform("projection",projection);
        shaderProgram.setUniform("view",view);

        glCheckError(__FILE__,__LINE__);

        glBindVertexArray(vao);

        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
        
        static int inc = 1;
        inc *= 2;
        glCheckError(__FILE__,__LINE__);
            glDrawElements(
                 GL_TRIANGLES,      // mode
                 size*size*2*3,         // count
                 GL_UNSIGNED_INT,   // type
                 NULL               // element array buffer offset
             );

        glBindVertexArray(0);

    shaderProgram.unuse();
}
 bool init()
 {
   sys::info << "ogl::CParticleSystem::init()" << sys::endl;
   
   mFirst     = true;
   mInit      = true;
   mActiveVBO = 0;
   mActiveTBO = 1;
   mTime      = 0;
   mPosition  = math::vec3(0.0f, 0.0f, 0.0f);
   
   _ZEROMEM(mVBOs);
   _ZEROMEM(mTBOs);
   _ZEROMEM(mVAOs);
   
   CParticle particles[mNumParticles];
   _ZEROMEM(particles);
   
   particles[0].mType     = CParticle::LAUNCHER;
   particles[0].mPosition = mPosition;
   particles[0].mVelocity = math::vec3(0.0f, 0.0001f, 0.0f);
   particles[0].mLifetime = 0.0f;
   
   glGenTransformFeedbacks(2, mTBOs);
   glGenBuffers(2, mVBOs);
   
   for(short i = 0; i < 2; i++)
   {
     glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, mTBOs[i]);
     glBindBuffer(GL_ARRAY_BUFFER, mVBOs[i]);
     glBufferData(GL_ARRAY_BUFFER, sizeof(particles), particles, GL_DYNAMIC_DRAW);
     glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mVBOs[i]);
   }
   
   mUpdateProgram->enable();
   mUpdateProgram->setUniform("u_fLauncherLifetime",    100.0f);
   mUpdateProgram->setUniform("u_fPrimaryLifetime",    1000.0f);
   mUpdateProgram->setUniform("u_fSecondaryLifetime",  2500.0f);
   mUpdateProgram->setUniform("u_fTertiaryLifetime",   1500.0f);
   
   mRenderProgram->enable();
   mRenderProgram->setUniform("u_fBillboardSize", 0.1f);
   
   glGenVertexArrays(2, mVAOs);
   glBindVertexArray(mVAOs[0]);
   glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, sizeof(CParticle), (const GLvoid*)((0) * sizeof(GLfloat)));             // type
   glEnableVertexAttribArray(0);
   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(CParticle), (const GLvoid*)((0 + 1) * sizeof(GLfloat)));         // position
   glEnableVertexAttribArray(1);
   glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(CParticle), (const GLvoid*)((0 + 1 + 3) * sizeof(GLfloat)));     // velocity
   glEnableVertexAttribArray(2);
   glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, sizeof(CParticle), (const GLvoid*)((0 + 1 + 3 + 3) * sizeof(GLfloat))); // lifetime
   glEnableVertexAttribArray(3);
   
   glBindVertexArray(mVAOs[1]);
   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(CParticle), (const GLvoid*)((0 + 1) * sizeof(GLfloat)));         // position
   glEnableVertexAttribArray(0);
   
   return glCheckError();
예제 #18
0
void reshape(int w,int h)
{
	if(h==0)
		h=1;
	glViewport(0,0,(GLsizei) w,(GLsizei) h);
	g_xy_aspect = (float)w / (float)h;
	glCheckError("reshape");
}
예제 #19
0
파일: texture.cpp 프로젝트: rokuz/DemoScene
void Texture::generateMipmaps()
{
    if (m_target != 0)
    {
        glGenerateMipmap(m_target);
        glCheckError();
    }
}
void	Abstract_GLWidget::initializeGL()
{
    std::cerr << "Abstract_GLWidget::initializeGL" << std::endl;

    glSetup();

    glCheckError();
}
예제 #21
0
void
render()
{
    glUseProgram(m_shaderProgram);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glCheckError();

    glUseProgram(0);
}
예제 #22
0
void
ViewerGL::Implementation::unbindTextureAndReleaseShader(bool useShader)
{
    if (useShader) {
        shaderRGB->release();
    }
    glCheckError(GL_GPU);
    GL_GPU::glBindTexture(GL_TEXTURE_2D, prevBoundTexture);
}
예제 #23
0
void Texture::initialize(const PackedFrameDescription &description, GLint internalFormat, GLenum format, GLenum type, const GLvoid * pData) {
	glCheckBound(target, id);
//	printf("about to glTexImage2D, original internal %s, internal %s, pixel format %s, pixel type %s\n", //
//			getInternalFormatString(description.glPackFormat), //
//			getInternalFormatString(internalFormat), //
//			getPixelFormatString(format), //
//			getPixelTypeString(type));
	glTexImage2D(target, 0, internalFormat, description.width, description.height, 0, format, type, pData);
	glCheckError();
	this->description = description;
}
예제 #24
0
	void FrameBuffer::Unbind()
	{
		if (m_enableMSAA)
		{
			glBindFramebuffer(GL_READ_FRAMEBUFFER, m_framebuffer);
			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer2);
			glBlitFramebuffer(0, 0, m_size.width, m_size.height, 0, 0, m_size.width, m_size.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
		}
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glCheckError();
	}
예제 #25
0
void FullScreen()
{
	if((glutGet(GLUT_WINDOW_WIDTH)==SCREEN_WIDTH)&&(glutGet(GLUT_WINDOW_HEIGHT)==SCREEN_HEIGHT))
	{
		glutPositionWindow(SCREEN_WIDTH/8,SCREEN_HEIGHT/8);
		glutReshapeWindow(3*SCREEN_WIDTH/4,3*SCREEN_HEIGHT/4);
	}
	else
		glutFullScreen();
	glCheckError("FullScreen");
}
예제 #26
0
void
ViewerGL::Implementation::initializeGL()
{
    // always running in the main thread
    assert( qApp && qApp->thread() == QThread::currentThread() );
    _this->makeCurrent();
    supportsOpenGL = initAndCheckGlExtensions();
    if (!supportsOpenGL) {
        return;
    }
    displayTextures[0].reset( new Texture(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST, GL_CLAMP_TO_EDGE) );
    displayTextures[1].reset( new Texture(GL_TEXTURE_2D, GL_LINEAR, GL_NEAREST, GL_CLAMP_TO_EDGE) );


    // glGenVertexArrays(1, &_vaoId);
    glGenBuffers(1, &this->vboVerticesId);
    glGenBuffers(1, &this->vboTexturesId);
    glGenBuffers(1, &this->iboTriangleStripId);

    glBindBuffer(GL_ARRAY_BUFFER, this->vboTexturesId);
    glBufferData(GL_ARRAY_BUFFER, 32 * sizeof(GLfloat), 0, GL_DYNAMIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, this->vboVerticesId);
    glBufferData(GL_ARRAY_BUFFER, 32 * sizeof(GLfloat), 0, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->iboTriangleStripId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 28 * sizeof(GLubyte), triangleStrip, GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glCheckError();

    initializeCheckerboardTexture(true);

    if (this->supportsGLSL) {
        _this->initShaderGLSL();
        glCheckError();
    }

    glCheckError();
}
예제 #27
0
파일: Texture.cpp 프로젝트: ebrayton/Natron
void fillOrAllocateTextureInternal(const RectI & bounds,
                                   Texture* texture,
                                   const RectI* roiParam,
                                   const unsigned char* originalRAMBuffer,
                                   int target,
                                   int texID,
                                   int format,
                                   int glType)
{
    //GLuint savedTexture;
    //glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&savedTexture);
    {
        GLProtectAttrib<GL> a(GL_ENABLE_BIT);


        if (!texture->getBounds().contains(bounds)) {
            bool ok = texture->ensureTextureHasSize(bounds, originalRAMBuffer);
            assert(ok);
        } else {


            // The bounds of the texture might be different than the bounds of the buffer
            const RectI& texBounds = texture->getBounds();

            int x1, y1, width, height;
            if (roiParam) {
                x1 = roiParam->x1 - texBounds.x1;
                y1 = roiParam->y1 - texBounds.y1;
                width = roiParam->width();
                height = roiParam->height();
            } else {
                x1 = bounds.x1 - texBounds.x1;
                y1 = bounds.y1 - texBounds.y1;
                width = bounds.width();
                height = bounds.height();
            }
            GL::Enable(target);
            GL::BindTexture (target, texID);

            GL::TexSubImage2D(target,
                              0,              // level
                              x1, y1,               // xoffset, yoffset
                              width, height,
                              format,            // format
                              glType,       // type
                              originalRAMBuffer);

            GL::BindTexture (target, 0);
            glCheckError(GL);
        }
    
    } // GLProtectAttrib a(GL_ENABLE_BIT);
}
예제 #28
0
	void FrameBuffer::Bind()
	{
//		GLint defaultFBO;
//		GLint defaultRBO;
//		glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
//		glGetIntegerv(GL_RENDERBUFFER_BINDING, &defaultRBO);
//		assert(defaultFBO == 0);
//		assert(defaultRBO == 0);
		
		assert(m_initialized);
		glCheckError();
		glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
	}
예제 #29
0
파일: Imaging.c 프로젝트: ForrestShi/GLView
void drawGL(int wide, int high, float val, int mode)
{
	static int prevmode = -1;
	typedef void (*procfunc)(V2fT2f *, float);

	typedef struct {
		procfunc func;
		procfunc degen;
	} Filter;

	const Filter filter[] = {
		{ brightness             },
		{ contrast               },
		{ extrapolate, greyscale },
		{ hue                    },
		{ extrapolate, blur      },	// The blur could be exaggerated by downsampling to half size
	};
	#define NUM_FILTERS (sizeof(filter)/sizeof(filter[0]))
	rt_assert(mode < NUM_FILTERS);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrthof(0, wide, 0, high, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glScalef(wide, high, 1);
	
	glBindTexture(GL_TEXTURE_2D, Input.texID);
		
	if (prevmode != mode)
	{
		prevmode = mode;
		if (filter[mode].degen)
		{
			// Cache degenerate image, potentially a different size than the system framebuffer
			glBindFramebufferOES(GL_FRAMEBUFFER_OES, DegenFBO);
			glViewport(0, 0, Degen.wide*Degen.s, Degen.high*Degen.t);
			// The entire framebuffer won't be written to if the image was padded to POT.
			// In this case, clearing is a performance win on TBDR systems.
			glClear(GL_COLOR_BUFFER_BIT);
			glDisable(GL_BLEND);
			filter[mode].degen(fullquad, 1.0);
			glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
		}
	}

	// Render filtered image to system framebuffer
	glViewport(0, 0, wide, high);
	filter[mode].func(flipquad, val);
	glCheckError();
}
 void onDraw(int nTime)
 {
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
   
   float fTime = nTime / 1000.0f;
   sys::info << "app::COGLDev45AmbientOcclusionApp::onDraw(nTime) > " << fTime << sys::endl;
   
   ogl::CCamera* pCamera = pScene->getCamera(app::tags::MAINCAMERA)->getCamera();
   
   pCameraController->setCamera(pCamera);
   
   CEventManager::getInstance()->trigger(new CUpdateEvent(fTime)); // must
   
   ///////////////////////////////////////////////////////////////////////////////////
   
   // 1st render scene to a cube env map using 6 cameras - render at the center of the fustrum
     // on lighting fs render - offset the env texel fetch using Light.Position - Fragment.Position
   
   ///////////////////////////////////////////////////////////////////////////////////
   
   // SELECT entity AS object       FROM scene WHERE object IN fustrum ORDER front_to_back
   // SELECT model_entity AS object FROM scene WHERE object IN fustrum ORDER back_to_front
   
   pRenderer->setCamera(pCamera);
   
   for(app::CSceneObject* pSceneObject : pScene->getObjects())
   {
     ogl::CObject* pObject        = pSceneObject->getObject();
     sys::CDescriptor oDescriptor = pSceneObject->getDescriptor();
     
     if(oDescriptor.hasTag(ogl::tags::MESH))
       pObject->setOrientation(math::quat(fTime * 90.0f, math::Y));
     
     if(oDescriptor.hasTag(ogl::tags::BOX))
       pObject->setPosition(math::vec3(-1.0f, 1.0f, -1.0f));
     
     pRenderer->addObject(pObject, oDescriptor);
   }
   for(app::CSceneLight* pSceneLight : pScene->getLights())
   {
     pRenderer->addLight(pSceneLight->getLight(), pSceneLight->getDescriptor());
   }
   
   pRenderer->render();
   
   glCheckError();
   
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
   
   //CApp::exit(); return;
 }