예제 #1
0
void GLTransportSurface::draw(const uint32_t texture)
{
    if (!m_vertexHandle)
        bindArrayBuffer();

    if (m_boundTexture != texture) {
        ::glBindTexture(GL_TEXTURE_2D, texture);
        m_boundTexture = texture;
    }

    ::glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
예제 #2
0
void ModernOpenGLGraphics::postInit()
{
    mglGenVertexArrays(1, &mVao);
    mglBindVertexArray(mVao);
    mglGenBuffers(1, &mVbo);
//    logger->log("gen vbo buffer: %u", mVbo);
    bindArrayBuffer(mVbo);
    mglGenBuffers(1, &mEbo);
//    logger->log("gen ebo buffer: %u", mEbo);
    bindElementBuffer(mEbo);

    logger->log("Compiling shaders");
    mProgram = shaders.getSimpleProgram();
    if (!mProgram)
    {
        graphicsManager.logError();
        logger->safeError("Shader creation error. See manaplus.log.");
    }
    mProgramId = mProgram->getProgramId();
    if (!mProgram)
        logger->error("Shaders compilation error.");

    logger->log("Shaders compilation done.");
    mglUseProgram(mProgramId);

    mPosAttrib = mglGetAttribLocation(mProgramId, "position");
    mglEnableVertexAttribArray(mPosAttrib);
    mglVertexAttribIFormat(mPosAttrib, 4, GL_INT, 0);

    mSimpleColorUniform = mglGetUniformLocation(mProgramId, "color");
    mScreenUniform = mglGetUniformLocation(mProgramId, "screen");
    mDrawTypeUniform = mglGetUniformLocation(mProgramId, "drawType");
    mTextureColorUniform = mglGetUniformLocation(mProgramId, "alpha");

    mglUniform1f(mTextureColorUniform, 1.0f);

    mglBindVertexBuffer(0, mVbo, 0, 4 * sizeof(GLint));
    mglVertexAttribBinding(mPosAttrib, 0);
//    mglVertexAttribIPointer(mPosAttrib, 4, GL_INT, 4 * sizeof(GLint), 0);
    mAttributesBinded = mVbo;

    mglUniform2f(mScreenUniform,
                 static_cast<float>(mWidth) / 2.0f,
                 static_cast<float>(mHeight) / 2.0f);
}
예제 #3
0
void GLTransportSurface::initializeShaderProgram()
{
    if (!m_context3D)
        m_context3D = GraphicsContext3D::createForCurrentGLContext();

    vertexArrayObjectSupported = m_context3D->getExtensions()->supports("GL_OES_vertex_array_object");

    TextureMapperShaderProgram::Options options = TextureMapperShaderProgram::Texture;
    m_shaderProgram = TextureMapperShaderProgram::create(m_context3D, options);

    ::glUseProgram(m_shaderProgram->programID());
    ::glUniform1i(m_shaderProgram->samplerLocation(), 0);
    ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    TransformationMatrix flipTransform;
    flipTransform.flipY();
    flipTransform.translate(0, -1);
    m_shaderProgram->setMatrix(m_shaderProgram->textureSpaceMatrixLocation(), flipTransform);

    ::glUniform1f(m_shaderProgram->opacityLocation(), 1.0);

    if (!m_vbo) {
        ::glGenBuffers(1, &m_vbo);
        ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
        ::glBufferData(GL_ARRAY_BUFFER, sizeof(GC3Dfloat) * 8, vertices, GL_STATIC_DRAW);
    }

    // Create and set-up vertex array object.
    if (vertexArrayObjectSupported) {
        m_vertexHandle = m_context3D->getExtensions()->createVertexArrayOES();

        if (m_vertexHandle) {
            m_context3D->getExtensions()->bindVertexArrayOES(m_vertexHandle);
            bindArrayBuffer();
        }
    }

    updateTransformationMatrix();
}
예제 #4
0
Context::Context(const egl::Config *config, int clientVersion, const Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess)
    : mRenderer(renderer),
      mData(clientVersion, mState, mCaps, mTextureCaps, mExtensions, nullptr)
{
    ASSERT(robustAccess == false);   // Unimplemented

    initCaps(clientVersion);
    mState.initialize(mCaps, clientVersion);

    mClientVersion = clientVersion;

    mConfigID = config->configID;
    mClientType = EGL_OPENGL_ES_API;

    mFenceNVHandleAllocator.setBaseHandle(0);

    if (shareContext != NULL)
    {
        mResourceManager = shareContext->mResourceManager;
        mResourceManager->addRef();
    }
    else
    {
        mResourceManager = new ResourceManager(mRenderer);
    }

    mData.resourceManager = mResourceManager;

    // [OpenGL ES 2.0.24] section 3.7 page 83:
    // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
    // and cube map texture state vectors respectively associated with them.
    // In order that access to these initial textures not be lost, they are treated as texture
    // objects all of whose names are 0.

    Texture *zeroTexture2D = new Texture(mRenderer->createTexture(GL_TEXTURE_2D), 0, GL_TEXTURE_2D);
    mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D);

    Texture *zeroTextureCube = new Texture(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), 0, GL_TEXTURE_CUBE_MAP);
    mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube);

    if (mClientVersion >= 3)
    {
        // TODO: These could also be enabled via extension
        Texture *zeroTexture3D = new Texture(mRenderer->createTexture(GL_TEXTURE_3D), 0, GL_TEXTURE_3D);
        mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D);

        Texture *zeroTexture2DArray = new Texture(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), 0, GL_TEXTURE_2D_ARRAY);
        mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray);
    }

    mState.initializeZeroTextures(mZeroTextures);

    // Allocate default FBO
    mFramebufferMap[0] = new Framebuffer(mCaps, mRenderer, 0);

    bindVertexArray(0);
    bindArrayBuffer(0);
    bindElementArrayBuffer(0);

    bindReadFramebuffer(0);
    bindDrawFramebuffer(0);
    bindRenderbuffer(0);

    bindGenericUniformBuffer(0);
    for (unsigned int i = 0; i < mCaps.maxCombinedUniformBlocks; i++)
    {
        bindIndexedUniformBuffer(0, i, 0, -1);
    }

    bindCopyReadBuffer(0);
    bindCopyWriteBuffer(0);
    bindPixelPackBuffer(0);
    bindPixelUnpackBuffer(0);

    // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
    // In the initial state, a default transform feedback object is bound and treated as
    // a transform feedback object with a name of zero. That object is bound any time
    // BindTransformFeedback is called with id of zero
    mTransformFeedbackZero.set(new TransformFeedback(mRenderer->createTransformFeedback(), 0, mCaps));
    bindTransformFeedback(0);

    mHasBeenCurrent = false;
    mContextLost = false;
    mResetStatus = GL_NO_ERROR;
    mResetStrategy = (notifyResets ? GL_LOSE_CONTEXT_ON_RESET_EXT : GL_NO_RESET_NOTIFICATION_EXT);
    mRobustAccess = robustAccess;

    mCompiler = new Compiler(mRenderer->createCompiler(getData()));
}