static void CALLBACK Paint(void) { glViewport(0,0,windW,windH); glDisable(GL_SCISSOR_TEST); glPushAttrib(GL_COLOR_BUFFER_BIT); glColorMask(1,1,1,1); glIndexMask((GLuint)~0); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glPopAttrib(); if(mode1)glShadeModel(GL_SMOOTH); else glShadeModel(GL_FLAT); if(mode2)glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); else glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); Viewport(0,0); Point(); Viewport(0,1); Lines(); Viewport(0,2); LineStrip(); Viewport(0,3); LineLoop(); Viewport(1,0); Bitmap(); Viewport(1,1); TriangleFan(); Viewport(1,2); Triangles(); Viewport(1,3); TriangleStrip(); Viewport(2,0); Rect(); Viewport(2,1); xPolygon(); Viewport(2,2); Quads(); Viewport(2,3); QuadStrip(); glFlush(); if(doubleBuffer)auxSwapBuffers(); }
bool SkNativeSharedGLContext::init(int width, int height) { width = width <= 0 ? 1 : width; height = height <= 0 ? 1 : height; if (fGL) { fGL->unref(); this->destroyGLContext(); } fGL = this->createGLContext(width, height); if (fGL) { const GrGLubyte* temp; GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl()); if (!fGL->validate(bindingInUse) || !fExtensions.init(bindingInUse, fGL)) { fGL = NULL; this->destroyGLContext(); return false; } SK_GL_RET(*this, temp, GetString(GR_GL_VERSION)); const char* versionStr = reinterpret_cast<const char*>(temp); GrGLVersion version = GrGLGetVersionFromString(versionStr); // clear any existing GL erorrs GrGLenum error; do { SK_GL_RET(*this, error, GetError()); } while (GR_GL_NO_ERROR != error); SK_GL(*this, GenFramebuffers(1, &fFBO)); SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); SK_GL(*this, GenTextures(1, &fTextureID)); SK_GL(*this, BindTexture(GR_GL_TEXTURE_2D, fTextureID)); SK_GL(*this, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, width, height, 0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL)); SK_GL(*this, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE)); SK_GL(*this, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE)); SK_GL(*this, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_GL_LINEAR)); SK_GL(*this, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_GL_LINEAR)); SK_GL(*this, FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, GR_GL_TEXTURE_2D, fTextureID, 0)); SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID)); SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID)); // Some drivers that support packed depth stencil will only succeed // in binding a packed format an FBO. However, we can't rely on packed // depth stencil being available. bool supportsPackedDepthStencil; if (kES2_GrGLBinding == bindingInUse) { supportsPackedDepthStencil = this->hasExtension("GL_OES_packed_depth_stencil"); } else { supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || this->hasExtension("GL_EXT_packed_depth_stencil") || this->hasExtension("GL_ARB_framebuffer_object"); } if (supportsPackedDepthStencil) { // ES2 requires sized internal formats for RenderbufferStorage // On Desktop we let the driver decide. GrGLenum format = kES2_GrGLBinding == bindingInUse ? GR_GL_DEPTH24_STENCIL8 : GR_GL_DEPTH_STENCIL; SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, format, width, height)); SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT, GR_GL_RENDERBUFFER, fDepthStencilBufferID)); } else { GrGLenum format = kES2_GrGLBinding == bindingInUse ? GR_GL_STENCIL_INDEX8 : GR_GL_STENCIL_INDEX; SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, format, width, height)); } SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, GR_GL_RENDERBUFFER, fDepthStencilBufferID)); SK_GL(*this, Viewport(0, 0, width, height)); SK_GL(*this, ClearStencil(0)); SK_GL(*this, Clear(GR_GL_STENCIL_BUFFER_BIT)); SK_GL_RET(*this, error, GetError()); GrGLenum status; SK_GL_RET(*this, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); if (GR_GL_FRAMEBUFFER_COMPLETE != status || GR_GL_NO_ERROR != error) { fFBO = 0; fTextureID = 0; fDepthStencilBufferID = 0; fGL->unref(); fGL = NULL; this->destroyGLContext(); return false; } else { return true; } } return false; }
Viewport View::GetBounds() const { return Viewport( std::max(v.l, vp.l), std::max(v.b, vp.b), std::min(v.w, vp.w), std::min(v.h, vp.h) ); }
static void Draw(EGLDisplay dpy, EGLSurface surf) { glViewport(0, 0, windW, windH); glDisable(GL_SCISSOR_TEST); glPushAttrib(GL_COLOR_BUFFER_BIT); glColorMask(1, 1, 1, 1); glIndexMask(~0); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glPopAttrib(); if (mode1) { glShadeModel(GL_SMOOTH); } else { glShadeModel(GL_FLAT); } if (mode2) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } Viewport(0, 0); Point(); Viewport(0, 1); Lines(); Viewport(0, 2); LineStrip(); Viewport(0, 3); LineLoop(); Viewport(1, 0); Bitmap(); Viewport(1, 1); TriangleFan(); Viewport(1, 2); Triangles(); Viewport(1, 3); TriangleStrip(); Viewport(2, 0); Rect(); Viewport(2, 1); PolygonFunc(); Viewport(2, 2); Quads(); Viewport(2, 3); QuadStrip(); glFlush(); if (doubleBuffer) { eglSwapBuffers(dpy, surf); } }
bool SkGLContext::init(int width, int height) { if (fGL) { fGL->unref(); this->destroyGLContext(); } fGL = this->createGLContext(); if (fGL) { fExtensionString = reinterpret_cast<const char*>(SK_GL(*this, GetString(GR_GL_EXTENSIONS))); const char* versionStr = reinterpret_cast<const char*>(SK_GL(*this, GetString(GR_GL_VERSION))); GrGLVersion version = GrGLGetVersionFromString(versionStr); // clear any existing GL erorrs GrGLenum error; do { error = SK_GL(*this, GetError()); } while (GR_GL_NO_ERROR != error); GrGLuint cbID; GrGLuint dsID; GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl()); SK_GL(*this, GenFramebuffers(1, &fFBO)); SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); SK_GL(*this, GenRenderbuffers(1, &cbID)); SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, cbID)); if (kES2_GrGLBinding == bindingInUse) { SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, height)); } else { SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA, width, height)); } SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, GR_GL_RENDERBUFFER, cbID)); SK_GL(*this, GenRenderbuffers(1, &dsID)); SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, dsID)); // Some drivers that support packed depth stencil will only succeed // in binding a packed format an FBO. However, we can't rely on packed // depth stencil being available. bool supportsPackedDepthStencil; if (kES2_GrGLBinding == bindingInUse) { supportsPackedDepthStencil = this->hasExtension("GL_OES_packed_depth_stencil"); } else { supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || this->hasExtension("GL_EXT_packed_depth_stencil") || this->hasExtension("GL_ARB_framebuffer_object"); } if (supportsPackedDepthStencil) { // ES2 requires sized internal formats for RenderbufferStorage // On Desktop we let the driver decide. GrGLenum format = kES2_GrGLBinding == bindingInUse ? GR_GL_DEPTH24_STENCIL8 : GR_GL_DEPTH_STENCIL; SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, format, width, height)); SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT, GR_GL_RENDERBUFFER, dsID)); } else { GrGLenum format = kES2_GrGLBinding == bindingInUse ? GR_GL_STENCIL_INDEX8 : GR_GL_STENCIL_INDEX; SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, format, width, height)); } SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, GR_GL_RENDERBUFFER, dsID)); SK_GL(*this, Viewport(0, 0, width, height)); SK_GL(*this, ClearStencil(0)); SK_GL(*this, Clear(GR_GL_STENCIL_BUFFER_BIT)); error = SK_GL(*this, GetError()); GrGLenum status = SK_GL(*this, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); if (GR_GL_FRAMEBUFFER_COMPLETE != status || GR_GL_NO_ERROR != error) { fFBO = 0; fGL->unref(); fGL = NULL; this->destroyGLContext(); return false; } else { return true; } } return false; }
RendererOGL::RendererOGL(WindowSDL *window, const Graphics::Settings &vs) : Renderer(window, window->GetWidth(), window->GetHeight()) , m_numLights(0) , m_numDirLights(0) //the range is very large due to a "logarithmic z-buffer" trick used //http://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html //http://www.gamedev.net/blog/73/entry-2006307-tip-of-the-day-logarithmic-zbuffer-artifacts-fix/ , m_minZNear(0.0001f) , m_maxZFar(10000000.0f) , m_useCompressedTextures(false) , m_invLogZfarPlus1(0.f) , m_activeRenderTarget(0) , m_activeRenderState(nullptr) , m_matrixMode(MatrixMode::MODELVIEW) { if (!initted) { initted = true; if (!ogl_LoadFunctions()) Error( "Pioneer can not run on your graphics card as it does not appear to support OpenGL 3.3\n" "Please check to see if your GPU driver vendor has an updated driver - or that drivers are installed correctly." ); if (ogl_ext_EXT_texture_compression_s3tc == ogl_LOAD_FAILED) Error( "OpenGL extension GL_EXT_texture_compression_s3tc not supported.\n" "Pioneer can not run on your graphics card as it does not support compressed (DXTn/S3TC) format textures." ); } m_viewportStack.push(Viewport()); const bool useDXTnTextures = vs.useTextureCompression; m_useCompressedTextures = useDXTnTextures; //XXX bunch of fixed function states here! glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); SetMatrixMode(MatrixMode::MODELVIEW); m_modelViewStack.push(matrix4x4f::Identity()); m_projectionStack.push(matrix4x4f::Identity()); SetClearColor(Color4f(0.f, 0.f, 0.f, 0.f)); SetViewport(0, 0, m_width, m_height); if (vs.enableDebugMessages) GLDebug::Enable(); // check enum PrimitiveType matches OpenGL values assert(POINTS == GL_POINTS); assert(LINE_SINGLE == GL_LINES); assert(LINE_LOOP == GL_LINE_LOOP); assert(LINE_STRIP == GL_LINE_STRIP); assert(TRIANGLES == GL_TRIANGLES); assert(TRIANGLE_STRIP == GL_TRIANGLE_STRIP); assert(TRIANGLE_FAN == GL_TRIANGLE_FAN); }
VOID Editor::Run() { // check the window rect RECT wnd_rc; ::GetClientRect(mWnd, &wnd_rc); I32 wnd_width = wnd_rc.right-wnd_rc.left; I32 wnd_height = wnd_rc.bottom-wnd_rc.top; if(wnd_width<=0||wnd_height<=0) return; // get the frame time static U32 system_time = Timer::instance().time(); U32 current_time = Timer::instance().time(); U32 frame_time = current_time - system_time; if(frame_time == 0) return; system_time = current_time; if(mGraphPtr==NULL) return; // reset the render context mGraphPtr->Reset(); // get the window rect Vector4 rect = Vector4(wnd_rc.left, wnd_rc.top, wnd_rc.right, wnd_rc.bottom); // set the viewport mGraphPtr->viewport(rect); ViewportPtr viewport = GNEW(Viewport(rect[0],rect[1],rect[2],rect[3])); CHECK(viewport); mGraphPtr->draw(static_cast<Operation*>(viewport.Ptr())); // set the scissor ScissorPtr scissor = GNEW(Scissor(rect[0],rect[1],rect[2],rect[3])); mGraphPtr->draw(static_cast<Operation*>(scissor.Ptr())); // clear the target and the zbuffer ClearPtr clear = GNEW(Clear(Clear::CT_COLOR|Clear::CT_DEPTH,Vector4(0.5,0.5,0.5,1.0),1.0f)); CHECK(clear); mGraphPtr->draw(static_cast<Operation*>(clear.Ptr())); // make the projection and the view F32 left = -P2U(wnd_width/2)*mScale; F32 right = P2U(wnd_width/2)*mScale; F32 bottom = -P2U(wnd_height/2)*mScale; F32 top = P2U(wnd_height/2)*mScale; F32 znear = -512.0; F32 zfar = 512.0; mGraphPtr->projection(Matrix::makeOrtho(left,right,bottom,top,znear,zfar)); mGraphPtr->view(Matrix::makeTranslate(-mEye)); // draw the map if(mMapPtr) { // update the map Vector3 start(rect[0], rect[1], 0); mGraphPtr->unproject(start, start); Vector3 end(rect[2], rect[3], 0); mGraphPtr->unproject(end, end); mMapPtr->Update(Vector4(start[0], start[1], end[0], end[1])); // draw the map mMapPtr->Draw(mGraphPtr.Ptr()); } // draw the brush if(mBrushPtr) mBrushPtr->Draw(mGraphPtr.Ptr()); // swap the graph buffer mGraphPtr->swap(); // swap buffers eglSwapBuffers(mDisplay, mSurface); }