示例#1
0
/**
 * \param type bit 0: render OSD, bit 1: render EOSD
 */
static void do_render_osd(int type) {
  if (((type & 1) && osdtexCnt > 0) || ((type & 2) && eosdDispList)) {
    // set special rendering parameters
    if (!scaled_osd) {
      MatrixMode(GL_PROJECTION);
      PushMatrix();
      LoadIdentity();
      Ortho(0, vo_dwidth, vo_dheight, 0, -1, 1);
    }
    Enable(GL_BLEND);
    if ((type & 2) && eosdDispList) {
      BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      CallList(eosdDispList);
    }
    if ((type & 1) && osdtexCnt > 0) {
      Color4ub((osd_color >> 16) & 0xff, (osd_color >> 8) & 0xff, osd_color & 0xff, 0xff - (osd_color >> 24));
      // draw OSD
#ifndef FAST_OSD
      BlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
      CallLists(osdtexCnt, GL_UNSIGNED_INT, osdaDispList);
#endif
      BlendFunc(GL_SRC_ALPHA, GL_ONE);
      CallLists(osdtexCnt, GL_UNSIGNED_INT, osdDispList);
    }
    // set rendering parameters back to defaults
    Disable(GL_BLEND);
    if (!scaled_osd)
      PopMatrix();
    BindTexture(gl_target, 0);
  }
示例#2
0
CMatrixGLES::CMatrixGLES()
{
  for (int i=0; i<(int)MM_MATRIXSIZE; i++)
  {
    m_matrices[i].push_back(new GLfloat[16]);
    MatrixMode((EMATRIXMODE)i);
    LoadIdentity();
  }
  m_matrixMode = (EMATRIXMODE)-1;
  m_pMatrix    = NULL;
}
示例#3
0
static void resize(int x,int y){
  mp_msg(MSGT_VO, MSGL_V, "[gl] Resize: %dx%d\n",x,y);
  if (WinID >= 0) {
    int top = 0, left = 0, w = x, h = y;
    geometry(&top, &left, &w, &h, vo_screenwidth, vo_screenheight);
    Viewport(top, left, w, h);
  } else
  Viewport( 0, 0, x, y );

  MatrixMode(GL_PROJECTION);
  LoadIdentity();
  ass_border_x = ass_border_y = 0;
  if (aspect_scaling() && use_aspect) {
    int new_w, new_h;
    GLdouble scale_x, scale_y;
    aspect(&new_w, &new_h, A_WINZOOM);
    panscan_calc_windowed();
    new_w += vo_panscan_x;
    new_h += vo_panscan_y;
    scale_x = (GLdouble)new_w / (GLdouble)x;
    scale_y = (GLdouble)new_h / (GLdouble)y;
    Scaled(scale_x, scale_y, 1);
    ass_border_x = (vo_dwidth - new_w) / 2;
    ass_border_y = (vo_dheight - new_h) / 2;
  }
  Ortho(0, image_width, image_height, 0, -1,1);

  MatrixMode(GL_MODELVIEW);
  LoadIdentity();

  if (!scaled_osd) {
#ifdef CONFIG_FREETYPE
  // adjust font size to display size
  force_load_font = 1;
#endif
  vo_osd_changed(OSDTYPE_OSD);
  }
  Clear(GL_COLOR_BUFFER_BIT);
  redraw();
}
示例#4
0
文件: Texture.cpp 项目: caidongyun/SE
void RenderableTexture::Setup(bool useStencilBuffer){
	glGenFramebuffers(1, &fbo);
	if (fbo == 0){
		DEBUG_LOG("failed to glGenFramebuffers\n");
		return;
	}
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex->GetID(), 0);

    if (useStencilBuffer){
        GLuint depth_stencil_rb;
        glGenRenderbuffers(1, &depth_stencil_rb);
        glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_rb);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, tex->GetWidth(), tex->GetHeight());
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_rb);
        glBindRenderbuffer(GL_RENDERBUFFER, 0);
    }

    auto result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (result != GL_FRAMEBUFFER_COMPLETE){
        DEBUG_LOG("FBO error!\n");
    }

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
    transform = make_shared<Transform>();
    Begin();
	Viewport(0, 0, tex->GetWidth(), tex->GetHeight());
	MatrixMode(PROJECTION_MATRIX);
	LoadIdentity();
	Ortho(0, tex->GetWidth(), 0, tex->GetHeight(), -1, 1);
	MatrixMode(MODELVIEW_MATRIX);
	LoadIdentity();
	End();
}
示例#5
0
void GrGpuGLFixed::flushProjectionMatrix() {
    float mat[16];
    Gr_bzero(mat, sizeof(mat));

    GrAssert(NULL != fCurrDrawState.fRenderTarget);

    mat[0] = 2.f / fCurrDrawState.fRenderTarget->width();
    mat[5] = -2.f / fCurrDrawState.fRenderTarget->height();
    mat[10] = -1.f;
    mat[15] = 1;

    mat[12] = -1.f;
    mat[13] = 1.f;

    GR_GL(MatrixMode(GR_GL_PROJECTION));
    GR_GL(LoadMatrixf(mat));
}
void GrGpuGL::flushViewMatrix(DrawType type) {
    const GrGLRenderTarget* rt = static_cast<const GrGLRenderTarget*>(this->getDrawState().getRenderTarget());
    SkISize viewportSize;
    const GrGLIRect& viewport = rt->getViewport();
    viewportSize.set(viewport.fWidth, viewport.fHeight);

    const SkMatrix& vm = this->getDrawState().getViewMatrix();

    if (kStencilPath_DrawType == type) {
        if (fHWPathMatrixState.fViewMatrix != vm ||
            fHWPathMatrixState.fRTSize != viewportSize) {
            // rescale the coords from skia's "device" coords to GL's normalized coords,
            // and perform a y-flip.
            SkMatrix m;
            m.setScale(SkIntToScalar(2) / rt->width(), SkIntToScalar(-2) / rt->height());
            m.postTranslate(-SK_Scalar1, SK_Scalar1);
            m.preConcat(vm);

            // GL wants a column-major 4x4.
            GrGLfloat mv[]  = {
                // col 0
                SkScalarToFloat(m[SkMatrix::kMScaleX]),
                SkScalarToFloat(m[SkMatrix::kMSkewY]),
                0,
                SkScalarToFloat(m[SkMatrix::kMPersp0]),

                // col 1
                SkScalarToFloat(m[SkMatrix::kMSkewX]),
                SkScalarToFloat(m[SkMatrix::kMScaleY]),
                0,
                SkScalarToFloat(m[SkMatrix::kMPersp1]),

                // col 2
                0, 0, 0, 0,

                // col3
                SkScalarToFloat(m[SkMatrix::kMTransX]),
                SkScalarToFloat(m[SkMatrix::kMTransY]),
                0.0f,
                SkScalarToFloat(m[SkMatrix::kMPersp2])
            };
            GL_CALL(MatrixMode(GR_GL_PROJECTION));
            GL_CALL(LoadMatrixf(mv));
            fHWPathMatrixState.fViewMatrix = vm;
            fHWPathMatrixState.fRTSize = viewportSize;
        }
    } else if (!fCurrentProgram->fViewMatrix.cheapEqualTo(vm) ||
               fCurrentProgram->fViewportSize != viewportSize) {
        SkMatrix m;
        m.setAll(
            SkIntToScalar(2) / viewportSize.fWidth, 0, -SK_Scalar1,
            0,-SkIntToScalar(2) / viewportSize.fHeight, SK_Scalar1,
            0, 0, SkMatrix::I()[8]);
        m.setConcat(m, vm);

        // ES doesn't allow you to pass true to the transpose param,
        // so do our own transpose
        GrGLfloat mt[]  = {
            SkScalarToFloat(m[SkMatrix::kMScaleX]),
            SkScalarToFloat(m[SkMatrix::kMSkewY]),
            SkScalarToFloat(m[SkMatrix::kMPersp0]),
            SkScalarToFloat(m[SkMatrix::kMSkewX]),
            SkScalarToFloat(m[SkMatrix::kMScaleY]),
            SkScalarToFloat(m[SkMatrix::kMPersp1]),
            SkScalarToFloat(m[SkMatrix::kMTransX]),
            SkScalarToFloat(m[SkMatrix::kMTransY]),
            SkScalarToFloat(m[SkMatrix::kMPersp2])
        };
        fCurrentProgram->fUniformManager.setMatrix3f(
                                            fCurrentProgram->fUniformHandles.fViewMatrixUni,
                                            mt);
        fCurrentProgram->fViewMatrix = vm;
        fCurrentProgram->fViewportSize = viewportSize;
    }
}
示例#7
0
bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {

    bool usingTextures[kNumStages];

    for (int s = 0; s < kNumStages; ++s) {
        usingTextures[s] = VertexUsesStage(s, fGeometrySrc.fVertexLayout);

        if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) {
            unimpl("Fixed pipe doesn't support radial/sweep gradients");
            return false;
        }
    }

    if (GR_GL_SUPPORT_ES1) {
        if (BlendCoefReferencesConstant(fCurrDrawState.fSrcBlend) ||
            BlendCoefReferencesConstant(fCurrDrawState.fDstBlend)) {
            unimpl("ES1 doesn't support blend constant");
            return false;
        }
    }

    if (!flushGLStateCommon(type)) {
        return false;
    }

    if (fDirtyFlags.fRenderTargetChanged) {
        flushProjectionMatrix();
    }

    for (int s = 0; s < kNumStages; ++s) {
        bool wasUsingTexture = VertexUsesStage(s, fHWGeometryState.fVertexLayout);
        if (usingTextures[s] != wasUsingTexture) {
            setTextureUnit(s);
            if (usingTextures[s]) {
                GR_GL(Enable(GR_GL_TEXTURE_2D));
            } else {
                GR_GL(Disable(GR_GL_TEXTURE_2D));
            }
        }
    }

    uint32_t vertColor = (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit);
    uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
                              kColor_VertexLayoutBit);

    if (vertColor != prevVertColor) {
        if (vertColor) {
            GR_GL(ShadeModel(GR_GL_SMOOTH));
            // invalidate the immediate mode color
            fHWDrawState.fColor = GrColor_ILLEGAL;
        } else {
            GR_GL(ShadeModel(GR_GL_FLAT));
        }
    }


    if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
        GR_GL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
                       GrColorUnpackG(fCurrDrawState.fColor),
                       GrColorUnpackB(fCurrDrawState.fColor),
                       GrColorUnpackA(fCurrDrawState.fColor)));
        fHWDrawState.fColor = fCurrDrawState.fColor;
    }

    // set texture environment, decide whether we are modulating by RGB or A.
    for (int s = 0; s < kNumStages; ++s) {
        if (usingTextures[s]) {
            GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
            if (NULL != texture) {
                TextureEnvRGBOperands nextRGBOperand0 =
                    (GrPixelConfigIsAlphaOnly(texture->config())) ?
                        kAlpha_TextureEnvRGBOperand :
                        kColor_TextureEnvRGBOperand;
                if (fHWRGBOperand0[s] != nextRGBOperand0) {
                    setTextureUnit(s);
                    GR_GL(TexEnvi(GR_GL_TEXTURE_ENV,
                                  GR_GL_OPERAND0_RGB,
                                  (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
                                    GR_GL_SRC_ALPHA :
                                    GR_GL_SRC_COLOR));
                    fHWRGBOperand0[s] = nextRGBOperand0;
                }

                if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
                    (fHWDrawState.fSamplerStates[s].getMatrix() !=
                     getSamplerMatrix(s))) {

                    GrMatrix texMat = getSamplerMatrix(s);
                    AdjustTextureMatrix(texture,
                                        GrSamplerState::kNormal_SampleMode,
                                        &texMat);
                    GrGpuMatrix glm;
                    glm.set(texMat);
                    setTextureUnit(s);
                    GR_GL(MatrixMode(GR_GL_TEXTURE));
                    GR_GL(LoadMatrixf(glm.fMat));
                    recordHWSamplerMatrix(s, getSamplerMatrix(s));
                }
            } else {
                GrAssert(!"Rendering with texture vert flag set but no bound texture");
                return false;
            }
        }
    }

    if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
        GrGpuMatrix glm;
        glm.set(fCurrDrawState.fViewMatrix);
        GR_GL(MatrixMode(GR_GL_MODELVIEW));
        GR_GL(LoadMatrixf(glm.fMat));
        fHWDrawState.fViewMatrix =
        fCurrDrawState.fViewMatrix;
    }
    resetDirtyFlags();
    return true;
}
示例#8
0
void CShaderAPIOES2::ResetRenderState(bool bFullReset)
{
    int i;

    if (!IsDeactivated())
    {
        glFrontFace(GL_CW);
        glEnable(GL_CULL_FACE);
        // glCullFace(GL_BACK); // Never changed.
        glDisable(GL_STENCIL_TEST);
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
        glStencilFunc(GL_ALWAYS, 0, 0xffffffff);
        glStencilMask(0xffffffff);
        glDisable(GL_SCISSOR_TEST);
        glDisable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(0.0f, 0.0f);
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
        // glBlendColor(1.0f, 1.0f, 1.0f, 1.0f); // Constant color blending modes are not used.
        // glBlendEquation(GL_FUNC_ADD); // Never changed.
        glActiveTexture(GL_TEXTURE0);
        glClearDepthf(1.0f);
        glClearStencil(0);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    }

    m_CurrentSnapshot = -1;

    m_CachedFastClipProjectionMatrix.Identity();

    m_SceneFogColor[0] = m_SceneFogColor[1] = m_SceneFogColor[2] = 0;
    m_SceneFogMode = MATERIAL_FOG_NONE;

    m_DynamicState.m_ClearColor[0] = m_DynamicState.m_ClearColor[1] =
                                         m_DynamicState.m_ClearColor[2] = m_DynamicState.m_ClearColor[3] = 0;
    m_ClearColorChanged = true;
    m_ClearReverseDepth = false;
    m_ClearStencil = 0;
    m_ZWriteEnable = true;

    StandardConstantChanged(OES2_SHADER_CONST_AMBIENT_LIGHT);

    m_WorldSpaceCameraPosition.Init(0.0f, 0.0f, 0.0f);

    m_DynamicState.m_PixelFogColor[0] = m_DynamicState.m_PixelFogColor[1] = m_DynamicState.m_PixelFogColor[2] = 0.0f;
    m_DynamicState.m_FogStart = 0.0f;
    m_DynamicState.m_FogEnd = 0.0f;
    m_DynamicState.m_FogMaxDensity = 1.0f;
    m_DynamicState.m_FogZ = 1.0f;
    UpdateFogConstant();

    // Shadow state applied in ShaderAPI.
    m_DynamicState.m_CullEnabled = true;
    m_DynamicState.m_FrontFace = GL_CW;
    m_DynamicState.m_DepthBiasEnabled = false;

    m_DynamicState.m_NumBones = 0;

    for (i = HardwareConfig()->Caps().m_NumCombinedSamplers; i-- > 0; )
        m_BoundTextures[i] = INVALID_SHADERAPI_TEXTURE_HANDLE;

    m_PixelShaderLightingChanged = true;
    m_VertexShaderLightingChanged = true;
    for (i = MAX_NUM_LIGHTS; i--; )
        m_DynamicState.m_LightEnable[i] = false;

    for (i = NUM_MATRIX_MODES; i--; )
        m_DynamicState.m_TransformType[i] = TRANSFORM_IS_GENERAL;
    StandardConstantChanged(OES2_SHADER_CONST_MODELVIEWPROJ);
    StandardConstantChanged(OES2_SHADER_CONST_VIEWPROJ);
    StandardConstantChanged(OES2_SHADER_CONST_MODEL);

    m_TransitionTable.UseDefaultState();
    SetDefaultState();

    if (bFullReset)
    {
        SetAnisotropicLevel(1);

        float *pBoneMatrix;
        for (i = 16; i--; )
        {
            pBoneMatrix = m_BoneMatrix[i];
            memset(pBoneMatrix, 0, sizeof(float) * 12);
            pBoneMatrix[0] = 1.0f;
            pBoneMatrix[5] = 1.0f;
            pBoneMatrix[10] = 1.0f;
        }
        MatrixMode(MATERIAL_VIEW);
        LoadIdentity();
        MatrixMode(MATERIAL_PROJECTION);
        LoadIdentity();
    }

    int width, height;
    GetBackBufferDimensions(width, height);
    m_Viewport.Init(0, 0, width, height);
    m_ViewportChanged = true;
    m_ViewportZChanged = true;

    m_ScissorEnabled = m_DynamicState.m_ScissorEnabled = false;
    m_DynamicState.m_ScissorRect.x = m_DynamicState.m_ScissorRect.y =
                                         m_DynamicState.m_ScissorRect.width = m_DynamicState.m_ScissorRect.height = -1;
    m_ScissorRectChanged = true;

    EnableFastClip(false);
    float fakePlane[4];
    int fakePlaneVal = -1;
    fakePlane[0] = fakePlane[1] = fakePlane[2] = fakePlane[3] = *((float *)(&fakePlaneVal));
    SetFastClipPlane(fakePlane);
    m_DynamicState.m_FastClipPlaneChanged = true;

    m_pRenderMesh = NULL;
    MeshMgr()->SetVertexDecl(VERTEX_FORMAT_UNKNOWN);

    SetRenderTarget(SHADER_RENDERTARGET_BACKBUFFER, SHADER_RENDERTARGET_DEPTHBUFFER);

    m_ActiveTexture = SHADER_SAMPLER0;
    m_UnpackAlignment = 4;
}
示例#9
0
void cRendererGLES2::SetShader( cShaderProgram * Shader ) {
	if ( NULL == Shader ) {
		Shader = mShaders[ EEGLES2_SHADER_BASE ];
	}

	if ( mCurShader == Shader ) {
		return;
	}

	DisableClientState( GL_VERTEX_ARRAY );
	DisableClientState( GL_TEXTURE_COORD_ARRAY );
	DisableClientState( GL_COLOR_ARRAY );

	mShaderPrev				= mCurShader;
	mCurShader				= Shader;

	CheckLocalShader();

	mProjectionMatrix_id	= mCurShader->UniformLocation( "dgl_ProjectionMatrix" );
	mModelViewMatrix_id		= mCurShader->UniformLocation( "dgl_ModelViewMatrix" );
	mTexActiveLoc			= mCurShader->UniformLocation( "dgl_TexActive" );
	mClippingEnabledLoc		= mCurShader->UniformLocation( "dgl_ClippingEnabled" );
	mCurActiveTex			= 0;

	Uint32 i;

	for ( i = 0; i < EEGL_ARRAY_STATES_COUNT; i++ ) {
		mAttribsLoc[ i ] = mCurShader->AttributeLocation( EEGLES2_STATES_NAME[ i ] );
	}

	for ( i = 0; i < EE_MAX_PLANES; i++ ) {
		if ( -1 != mClippingEnabledLoc ) {
			mPlanes[ i ] = mCurShader->UniformLocation( EEGLES2_PLANES_NAMENABLED_NAME[ i ] );
		} else {
			mPlanes[ i ] = -1;
		}
	}

	for ( i = 0; i < EE_MAX_TEXTURE_UNITS; i++ ) {
		mTextureUnits[ i ] = mCurShader->AttributeLocation( EEGLES2_TEXTUREUNIT_NAMES[ i ] );
	}

	glUseProgram( mCurShader->Handler() );

	if ( -1 != mAttribsLoc[ EEGL_VERTEX_ARRAY ] )
		EnableClientState( GL_VERTEX_ARRAY );

	if ( -1 != mAttribsLoc[ EEGL_COLOR_ARRAY ] )
		EnableClientState( GL_COLOR_ARRAY );

	if ( -1 != mTextureUnits[ mCurActiveTex ] )
		EnableClientState( GL_TEXTURE_COORD_ARRAY );

	GLenum CM = mCurrentMode;

	MatrixMode( GL_PROJECTION );
	UpdateMatrix();
	MatrixMode( GL_MODELVIEW );
	UpdateMatrix();
	MatrixMode( CM );

	if ( -1 != mTexActiveLoc ) {
		mCurShader->SetUniform( mTexActiveLoc, mTexActive );
	}

	if ( -1 != mClippingEnabledLoc ) {
		mCurShader->SetUniform( mClippingEnabledLoc, 0 );
	}

	for ( i = 0; i < EE_MAX_PLANES; i++ ) {
		if ( -1 != mPlanes[ i ] ) {
			mCurShader->SetUniform( EEGLES2_PLANES_ENABLED_NAME[ i ], 0 );
		}
	}
}