示例#1
0
GrGpuGLShaders::GrGpuGLShaders(const GrGLInterface* gl)
    : GrGpuGL(gl, get_binding_in_use(gl)) {

    GrGLSLGeneration glslGeneration =
        GetGLSLGeneration(this->glBinding(), gl);

    // Enable supported shader-releated caps
    fCaps.fShaderSupport = true;
    fCaps.fSupportPerVertexCoverage = true;
    if (kDesktop_GrGLBinding == this->glBinding()) {
        fCaps.fDualSourceBlendingSupport =
            this->glVersion() >= GR_GL_VER(3,3) ||
            this->hasExtension("GL_ARB_blend_func_extended");
        fCaps.fShaderDerivativeSupport = true;
        // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
        fCaps.fGeometryShaderSupport =
            this->glVersion() >= GR_GL_VER(3,2) &&
            glslGeneration >= k150_GLSLGeneration;
    } else {
        fCaps.fShaderDerivativeSupport =
            this->hasExtension("GL_OES_standard_derivatives");
    }

    GR_GL_GetIntegerv(gl, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttribs);

    fProgramData = NULL;
    fProgramCache = new ProgramCache(gl, glslGeneration);

#if 0
    this->programUnitTest();
#endif
}
示例#2
0
bool CAGPUAdapter::init()
{
	const char* verStr = reinterpret_cast<const char*>(glGetString(GL_VERSION));
	mGPUGLVersion = verStr;
	mGLVersion = GetGLVersionFromString(mGPUGLVersion.c_str());
	mStandard = GetGLStandardInUseFromString(mGPUGLVersion.c_str());
	if (GetGLSLGeneration(mStandard))
		return true;
	return false;
}
示例#3
0
std::string CAGPUAdapter::getGLSLGenerationString()
{
	switch (GetGLSLGeneration()) {
	case k110:
		if (GLES == GetGLStandardInUse()) {
			// ES2s shader language is based on version 1.20 but is version
			// 1.00 of the ES language.
			return "#version 100\n";
		}
		else {
			CCAssert(GL == GetGLStandardInUse(), "");
			return "#version 110\n";
		}
	case k120:
		CCAssert(GL == GetGLStandardInUse(), "");
		return "#version 120\n";
	case k130:
		CCAssert(GL == GetGLStandardInUse(), "");
		return "#version 130\n";
	case k140:
		CCAssert(GL == GetGLStandardInUse(), "");
		return "#version 140\n";
	case k150:
		CCAssert(GL == GetGLStandardInUse(), "");
		return "#version 150\n";
	case k330:
		if (GLES == GetGLStandardInUse()) {
			return "#version 300 es\n";
		}
		else {
			CCAssert(GL == GetGLStandardInUse(), "");
			return "#version 330\n";
		}
	case k310es:
		CCAssert(GLES == GetGLStandardInUse(), "");
		return "#version 310 es\n";
	default:
		CCLOG("CrossApp: ERROR: Unknown GL version.");
		return ""; // suppress warning
	}
}
示例#4
0
bool GrGpuGLShaders::programUnitTest() {

    GrGLSLGeneration glslGeneration =
        GetGLSLGeneration(this->glBinding(), this->glInterface());
    static const int STAGE_OPTS[] = {
        0,
        StageDesc::kNoPerspective_OptFlagBit,
        StageDesc::kIdentity_CoordMapping
    };
    static const int IN_CONFIG_FLAGS[] = {
        StageDesc::kNone_InConfigFlag,
        StageDesc::kSwapRAndB_InConfigFlag,
        StageDesc::kSwapRAndB_InConfigFlag | StageDesc::kMulRGBByAlpha_InConfigFlag,
        StageDesc::kMulRGBByAlpha_InConfigFlag,
        StageDesc::kSmearAlpha_InConfigFlag,
    };
    GrGLProgram program;
    ProgramDesc& pdesc = program.fProgramDesc;

    static const int NUM_TESTS = 512;

    GrRandom random;
    for (int t = 0; t < NUM_TESTS; ++t) {

#if 0
        GrPrintf("\nTest Program %d\n-------------\n", t);
        static const int stop = -1;
        if (t == stop) {
            int breakpointhere = 9;
        }
#endif

        pdesc.fVertexLayout = 0;
        pdesc.fEmitsPointSize = random.nextF() > .5f;
        pdesc.fColorInput = random_int(&random, ProgramDesc::kColorInputCnt);

        pdesc.fColorFilterXfermode = random_int(&random, SkXfermode::kCoeffModesCnt);

        pdesc.fFirstCoverageStage = random_int(&random, GrDrawState::kNumStages);

        pdesc.fVertexLayout |= random_bool(&random) ?
                               GrDrawTarget::kCoverage_VertexLayoutBit :
                               0;

#if GR_GL_EXPERIMENTAL_GS
        pdesc.fExperimentalGS = this->getCaps().fGeometryShaderSupport &&
                                random_bool(&random);
#endif
        pdesc.fOutputPM =  random_int(&random, ProgramDesc::kOutputPMCnt);

        bool edgeAA = random_bool(&random);
        if (edgeAA) {
            bool vertexEdgeAA = random_bool(&random);
            if (vertexEdgeAA) {
                pdesc.fVertexLayout |= GrDrawTarget::kEdge_VertexLayoutBit;
                if (this->getCaps().fShaderDerivativeSupport) {
                    pdesc.fVertexEdgeType = random_bool(&random) ?
                                            GrDrawState::kHairQuad_EdgeType :
                                            GrDrawState::kHairLine_EdgeType;
                } else {
                    pdesc.fVertexEdgeType = GrDrawState::kHairLine_EdgeType;
                }
                pdesc.fEdgeAANumEdges = 0;
            } else {
                pdesc.fEdgeAANumEdges = random_int(&random, 1, this->getMaxEdges());
                pdesc.fEdgeAAConcave = random_bool(&random);
            }
        } else {
            pdesc.fEdgeAANumEdges = 0;
        }

        if (this->getCaps().fDualSourceBlendingSupport) {
            pdesc.fDualSrcOutput = random_int(&random, ProgramDesc::kDualSrcOutputCnt);
        } else {
            pdesc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput;
        }

        for (int s = 0; s < GrDrawState::kNumStages; ++s) {
            // enable the stage?
            if (random_bool(&random)) {
                // use separate tex coords?
                if (random_bool(&random)) {
                    int t = random_int(&random, GrDrawState::kMaxTexCoords);
                    pdesc.fVertexLayout |= StageTexCoordVertexLayoutBit(s, t);
                } else {
                    pdesc.fVertexLayout |= StagePosAsTexCoordVertexLayoutBit(s);
                }
            }
            // use text-formatted verts?
            if (random_bool(&random)) {
                pdesc.fVertexLayout |= kTextFormat_VertexLayoutBit;
            }
            StageDesc& stage = pdesc.fStages[s];
            stage.fOptFlags = STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))];
            stage.fInConfigFlags = IN_CONFIG_FLAGS[random_int(&random, GR_ARRAY_COUNT(IN_CONFIG_FLAGS))];
            stage.fCoordMapping =  random_int(&random, StageDesc::kCoordMappingCnt);
            stage.fFetchMode = random_int(&random, StageDesc::kFetchModeCnt);
            // convolution shaders don't work with persp tex matrix
            if (stage.fFetchMode == StageDesc::kConvolution_FetchMode) {
                stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
            }
            stage.setEnabled(VertexUsesStage(s, pdesc.fVertexLayout));
            switch (stage.fFetchMode) {
            case StageDesc::kSingle_FetchMode:
                stage.fKernelWidth = 0;
                break;
            case StageDesc::kConvolution_FetchMode:
                stage.fKernelWidth = random_int(&random, 2, 8);
                stage.fInConfigFlags &= ~StageDesc::kMulRGBByAlpha_InConfigFlag;
                break;
            case StageDesc::k2x2_FetchMode:
                stage.fKernelWidth = 0;
                stage.fInConfigFlags &= ~StageDesc::kMulRGBByAlpha_InConfigFlag;
                break;
            }
        }
        CachedData cachedData;
        if (!program.genProgram(this->glInterface(),
                                glslGeneration,
                                &cachedData)) {
            return false;
        }
        DeleteProgram(this->glInterface(), &cachedData);
    }
    return true;
}