Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
GLES2FrameBufferObject::GLES2FrameBufferObject(GLES2FBOManager *manager, uint fsaa):
    mManager(manager), mNumSamples(fsaa)
{
    GLES2Support* glSupport = getGLES2SupportRef();

    // Generate framebuffer object
    OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &mFB));

    if(glSupport->checkExtension("GL_EXT_debug_label"))
    {
        OGRE_IF_IOS_VERSION_IS_GREATER_THAN(5.0)
        OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_BUFFER_OBJECT_EXT, mFB, 0, ("FBO #" + StringConverter::toString(mFB)).c_str()));
    }

    mNumSamples = 0;
    mMultisampleFB = 0;

    // Check multisampling if supported
    if(glSupport->hasMinGLVersion(3, 0))
    {
        // Check samples supported
        OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mFB));
        GLint maxSamples;
        OGRE_CHECK_GL_ERROR(glGetIntegerv(GL_MAX_SAMPLES_APPLE, &maxSamples));
        OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, 0));
        mNumSamples = std::min(mNumSamples, (GLsizei)maxSamples);
    }

    // Will we need a second FBO to do multisampling?
    if (mNumSamples)
    {
        OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &mMultisampleFB));
        if(glSupport->checkExtension("GL_EXT_debug_label"))
        {
            OGRE_IF_IOS_VERSION_IS_GREATER_THAN(5.0)
            OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_BUFFER_OBJECT_EXT, mMultisampleFB, 0, ("MSAA FBO #" + StringConverter::toString(mMultisampleFB)).c_str()));
        }
    }
    else
    {
        mMultisampleFB = 0;
    }

    // Initialise state
    mDepth.buffer = 0;
    mStencil.buffer = 0;
    for(size_t x = 0; x < OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
    {
        mColour[x].buffer=0;
    }
}
    GLES2HardwareUniformBuffer::GLES2HardwareUniformBuffer(HardwareBufferManagerBase* mgr, 
                                                               size_t bufferSize,
                                                               HardwareBuffer::Usage usage,
                                                               bool useShadowBuffer, const String& name)
    : HardwareUniformBuffer(mgr, bufferSize, usage, useShadowBuffer, name)
    {
        OGRE_CHECK_GL_ERROR(glGenBuffers(1, &mBufferId));

        if (!mBufferId)
        {
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
                        "Cannot create GL uniform buffer",
                        "GLES2HardwareUniformBuffer::GLES2HardwareUniformBuffer");
        }

        OGRE_CHECK_GL_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, mBufferId));

        if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_DEBUG))
        {
            OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_BUFFER_OBJECT_EXT, mBufferId, 0, ("Uniform Buffer #" + StringConverter::toString(mBufferId)).c_str()));
        }

        OGRE_CHECK_GL_ERROR(glBufferData(GL_UNIFORM_BUFFER, mSizeInBytes, NULL,
                                         GLES2HardwareBufferManager::getGLUsage(usage)));

//        std::cerr << "creating uniform buffer = " << mBufferId << std::endl;
    }
EXTERN_C_ENTER

JNIEXPORT void JNICALL Java_org_lwjgl_opengles_EXTDebugLabel_nglLabelObjectEXT(JNIEnv *__env, jclass clazz, jint type, jint object, jint length, jlong labelAddress) {
    glLabelObjectEXTPROC glLabelObjectEXT = (glLabelObjectEXTPROC)tlsGetFunction(400);
    intptr_t label = (intptr_t)labelAddress;
    UNUSED_PARAM(clazz)
    glLabelObjectEXT(type, object, length, label);
}
Ejemplo n.º 4
0
void Texture::set_debug_name(const std::string& debug_name)
{
	_debug_name = debug_name;

#if TARGET_OS_IPHONE
	glLabelObjectEXT(GL_TEXTURE, _id, 0, _debug_name.c_str());
#endif
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
    GLES2FrameBufferObject::GLES2FrameBufferObject(GLES2FBOManager *manager, uint fsaa):
        GLFrameBufferObjectCommon(fsaa), mManager(manager)
    {
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
        GLint oldfb = 0;
        OGRE_CHECK_GL_ERROR(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldfb));
#endif
        GLES2RenderSystem* rs = getGLES2RenderSystem();
        mContext = rs->_getCurrentContext();
        
        // Generate framebuffer object
        OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &mFB));

	   if(rs->getCapabilities()->hasCapability(RSC_DEBUG))
       {
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
           OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mFB)); // to avoid GL_INVALID_OPERATION in glLabelObjectEXT(GL_FRAMEBUFFER,...) on iOS 
#endif
           OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_FRAMEBUFFER, mFB, 0, ("FBO #" + StringConverter::toString(mFB)).c_str()));
       }

        mNumSamples = std::min(mNumSamples, manager->getMaxFSAASamples());

        // Will we need a second FBO to do multisampling?
        if (mNumSamples)
        {
            OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &mMultisampleFB));
            if(rs->getCapabilities()->hasCapability(RSC_DEBUG))
            {
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
                OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mMultisampleFB)); // to avoid GL_INVALID_OPERATION in glLabelObjectEXT(GL_FRAMEBUFFER,...) on iOS 
#endif
                OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_FRAMEBUFFER, mMultisampleFB, 0, ("MSAA FBO #" + StringConverter::toString(mMultisampleFB)).c_str()));
            }
        }
        else
        {
            mMultisampleFB = 0;
        }

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
        OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, oldfb));
#endif
    }
Ejemplo n.º 6
0
void AbstractObject::labelImplementationExt(const GLenum identifier, const GLuint name, const Containers::ArrayView<const char> label) {
    #ifndef CORRADE_TARGET_NACL
    const GLenum type = extTypeFromKhrIdentifier(identifier);
    glLabelObjectEXT(type, name, label.size(), label);
    #else
    static_cast<void>(identifier);
    static_cast<void>(name);
    static_cast<void>(label);
    CORRADE_ASSERT_UNREACHABLE();
    #endif
}
Ejemplo n.º 7
0
void AbstractObject::labelImplementationExt(const GLenum identifier, const GLuint name, const std::string& label) {
    const GLenum type = extTypeFromKhrIdentifier(identifier);
    /** @todo Re-enable when extension loader is available for ES */
    #ifndef MAGNUM_TARGET_GLES
    glLabelObjectEXT(type, name, label.size(), label.data());
    #else
    static_cast<void>(type);
    static_cast<void>(name);
    static_cast<void>(label);
    CORRADE_INTERNAL_ASSERT(false);
    #endif
}
Ejemplo n.º 8
0
    DiGLES2RenderBuffer::DiGLES2RenderBuffer(GLenum format, uint32 width, uint32 height)
        :mRenderbufferID(0),
        mGLFormat(format)
    {
        // Generate render buffer
        CHECK_GL_ERROR(glGenRenderbuffers(1, &mRenderbufferID));

        if (DiGLES2Driver::GLUtil->CheckExtension("GL_EXT_debug_label"))
        {
            DiString name;
            name.SetInt(mRenderbufferID);
            IF_IOS_VERSION_IS_GREATER_THAN(5.0)
            glLabelObjectEXT(GL_PROGRAM_OBJECT_EXT, mRenderbufferID, 0, name.c_str());
        }

        // Bind it to FBO
        CHECK_GL_ERROR(glBindRenderbuffer(GL_RENDERBUFFER, mRenderbufferID));
        CHECK_GL_ERROR(glRenderbufferStorage(GL_RENDERBUFFER, format, width, height));
    }
    void GLES2HardwareVertexBuffer::createBuffer()
    {
        OGRE_CHECK_GL_ERROR(glGenBuffers(1, &mBufferId));
        if(getGLES2SupportRef()->checkExtension("GL_EXT_debug_label"))
        {
            OGRE_IF_IOS_VERSION_IS_GREATER_THAN(5.0)
            OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_BUFFER_OBJECT_EXT, mBufferId, 0, ("Vertex Buffer #" + StringConverter::toString(mBufferId)).c_str()));
        }

        if (!mBufferId)
        {
            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
                        "Cannot create GL ES vertex buffer",
                        "GLES2HardwareVertexBuffer::GLES2HardwareVertexBuffer");
        }
        
		static_cast<GLES2HardwareBufferManagerBase*>(mMgr)->getStateCacheManager()->bindGLBuffer(GL_ARRAY_BUFFER, mBufferId);
        OGRE_CHECK_GL_ERROR(glBufferData(GL_ARRAY_BUFFER, mSizeInBytes, NULL,
                                         GLES2HardwareBufferManager::getGLUsage(mUsage)));
    }
Ejemplo n.º 10
0
    void GLSLESProgramPipeline::compileAndLink()
    {
#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
        GLint linkStatus = 0;
        
        OGRE_CHECK_GL_ERROR(glGenProgramPipelinesEXT(1, &mGLProgramPipelineHandle));
        OGRE_CHECK_GL_ERROR(glBindProgramPipelineEXT(mGLProgramPipelineHandle));

        // Compile and attach Vertex Program
        if(getVertexProgram())
        {
            if(getVertexProgram()->isLinked())
            {
                mLinked |= VERTEX_PROGRAM_LINKED;
            }
            else if(getMicrocodeFromCache(
                    getVertexProgram()->getName(),
                    getVertexProgram()->createGLProgramHandle()))
            {
                getVertexProgram()->setLinked(true);
                mLinked |= VERTEX_PROGRAM_LINKED;
                mTriedToLinkAndFailed = false;
            }
            else
            {
                if(!getVertexProgram()->compile(true)) {
                    LogManager::getSingleton().stream(LML_CRITICAL)
                            << "Vertex Program " << getVertexProgram()->getName()
                            << " failed to compile. See compile log above for details.";
                    mTriedToLinkAndFailed = true;
                    return;
                }
                GLuint programHandle = getVertexProgram()->getGLProgramHandle();

                bindFixedAttributes( programHandle );

                OGRE_CHECK_GL_ERROR(glProgramParameteriEXT(programHandle, GL_PROGRAM_SEPARABLE_EXT, GL_TRUE));
                getVertexProgram()->attachToProgramObject(programHandle);
                OGRE_CHECK_GL_ERROR(glLinkProgram(programHandle));
                OGRE_CHECK_GL_ERROR(glGetProgramiv(programHandle, GL_LINK_STATUS, &linkStatus));
                
                if(linkStatus)
                {
                    getVertexProgram()->setLinked(linkStatus);
                    mLinked |= VERTEX_PROGRAM_LINKED;
                }
                
                mTriedToLinkAndFailed = !linkStatus;
                
                GLSLES::logObjectInfo( getCombinedName() + String("GLSL vertex program result : "), programHandle );

                setSkeletalAnimationIncluded(getVertexProgram()->isSkeletalAnimationIncluded());
            }
        }
        
        // Compile and attach Fragment Program
        if(mFragmentProgram)
        {
            if(mFragmentProgram->isLinked())
            {
                mLinked |= FRAGMENT_PROGRAM_LINKED;
            }
            else if(getMicrocodeFromCache(
                    mFragmentProgram->getName(),
                    mFragmentProgram->createGLProgramHandle()))
            {
                mFragmentProgram->setLinked(true);
                mLinked |= FRAGMENT_PROGRAM_LINKED;
                mTriedToLinkAndFailed = false;
            }
            else
            {
                if(!mFragmentProgram->compile(true)) {
                    LogManager::getSingleton().stream(LML_CRITICAL)
                            << "Fragment Program " << mFragmentProgram->getName()
                            << " failed to compile. See compile log above for details.";
                    mTriedToLinkAndFailed = true;
                    return;
                }

                GLuint programHandle = mFragmentProgram->getGLProgramHandle();
                OGRE_CHECK_GL_ERROR(glProgramParameteriEXT(programHandle, GL_PROGRAM_SEPARABLE_EXT, GL_TRUE));
                mFragmentProgram->attachToProgramObject(programHandle);
                OGRE_CHECK_GL_ERROR(glLinkProgram(programHandle));
                OGRE_CHECK_GL_ERROR(glGetProgramiv(programHandle, GL_LINK_STATUS, &linkStatus));

                if(linkStatus)
                {
                    mFragmentProgram->setLinked(linkStatus);
                    mLinked |= FRAGMENT_PROGRAM_LINKED;
                }

                mTriedToLinkAndFailed = !linkStatus;

                GLSLES::logObjectInfo( getCombinedName() + String("GLSL fragment program result : "), programHandle );
            }
        }
        
        if(mLinked)
        {
            if(getVertexProgram() && getVertexProgram()->isLinked())
            {
                OGRE_CHECK_GL_ERROR(glUseProgramStagesEXT(mGLProgramPipelineHandle, GL_VERTEX_SHADER_BIT_EXT, getVertexProgram()->getGLProgramHandle()));
                _writeToCache(getVertexProgram()->getName(), getVertexProgram()->getGLProgramHandle());
            }
            if(mFragmentProgram && mFragmentProgram->isLinked())
            {
                OGRE_CHECK_GL_ERROR(glUseProgramStagesEXT(mGLProgramPipelineHandle, GL_FRAGMENT_SHADER_BIT_EXT, mFragmentProgram->getGLProgramHandle()));
                _writeToCache(mFragmentProgram->getName(), mFragmentProgram->getGLProgramHandle());
            }

            // Validate pipeline
            GLSLES::logObjectInfo( getCombinedName() + String("GLSL program pipeline result : "), mGLProgramPipelineHandle );
            if(getVertexProgram() && mFragmentProgram && Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_DEBUG))
            {
                glLabelObjectEXT(GL_PROGRAM_PIPELINE_OBJECT_EXT, mGLProgramPipelineHandle, 0,
                             (getVertexProgram()->getName() + "/" + mFragmentProgram->getName()).c_str());
            }
        }
#endif
    }
Ejemplo n.º 11
0
bool GLSLESProgram::compile(const bool checkErrors)
{
    if (mCompiled == 1)
    {
        return true;
    }
    // Only create a shader object if glsl es is supported
    if (isSupported())
    {
        // Create shader object
        GLenum shaderType = 0x0000;
        if (mType == GPT_VERTEX_PROGRAM)
        {
            shaderType = GL_VERTEX_SHADER;
        }
        else if (mType == GPT_FRAGMENT_PROGRAM)
        {
            shaderType = GL_FRAGMENT_SHADER;
        }
        OGRE_CHECK_GL_ERROR(mGLShaderHandle = glCreateShader(shaderType));

#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
        if(getGLES2SupportRef()->checkExtension("GL_EXT_debug_label"))
        {
            OGRE_IF_IOS_VERSION_IS_GREATER_THAN(5.0)
            glLabelObjectEXT(GL_SHADER_OBJECT_EXT, mGLShaderHandle, 0, mName.c_str());
        }
#endif

        if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS))
        {
            OGRE_CHECK_GL_ERROR(mGLProgramHandle = glCreateProgram());
#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
            if(getGLES2SupportRef()->checkExtension("GL_EXT_debug_label"))
            {
                OGRE_IF_IOS_VERSION_IS_GREATER_THAN(5.0)
                glLabelObjectEXT(GL_PROGRAM_OBJECT_EXT, mGLProgramHandle, 0, mName.c_str());
            }
#endif
        }
    }

    // Add preprocessor extras and main source
    if (!mSource.empty())
    {
        // Fix up the source in case someone forgot to redeclare gl_Position
        if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS) &&
                mType == GPT_VERTEX_PROGRAM)
        {
            size_t versionPos = mSource.find("#version");
            int shaderVersion = StringConverter::parseInt(mSource.substr(versionPos+9, 3));

            // Check that it's missing and that this shader has a main function, ie. not a child shader.
            if(mSource.find("out highp vec4 gl_Position") == String::npos)
            {
                if(shaderVersion >= 300)
                    mSource.insert(versionPos+16, "out highp vec4 gl_Position;\nout highp float gl_PointSize;\n");
            }
            if(mSource.find("#extension GL_EXT_separate_shader_objects : require") == String::npos)
            {
                if(shaderVersion >= 300)
                    mSource.insert(versionPos+16, "#extension GL_EXT_separate_shader_objects : require\n");
            }
        }

#if !OGRE_NO_GLES2_GLSL_OPTIMISER
        const char *source = (getOptimiserEnabled() && getIsOptimised()) ? mOptimisedSource.c_str() : mSource.c_str();
#else
        const char *source = mSource.c_str();
#endif

        OGRE_CHECK_GL_ERROR(glShaderSource(mGLShaderHandle, 1, &source, NULL));
    }

    if (checkErrors)
        logObjectInfo("GLSL ES compiling: " + mName, mGLShaderHandle);

    OGRE_CHECK_GL_ERROR(glCompileShader(mGLShaderHandle));

    // Check for compile errors
    OGRE_CHECK_GL_ERROR(glGetShaderiv(mGLShaderHandle, GL_COMPILE_STATUS, &mCompiled));
    if(!mCompiled && checkErrors)
    {
        String message = logObjectInfo("GLSL ES compile log: " + mName, mGLShaderHandle);
        checkAndFixInvalidDefaultPrecisionError(message);
    }

    // Log a message that the shader compiled successfully.
    if (mCompiled && checkErrors)
        logObjectInfo("GLSL ES compiled: " + mName, mGLShaderHandle);

    if(!mCompiled)
    {
        OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
                    ((mType == GPT_VERTEX_PROGRAM) ? "Vertex Program " : "Fragment Program ") + mName +
                    " failed to compile. See compile log above for details.",
                    "GLSLESProgram::compile");
    }

    return (mCompiled == 1);
}
Ejemplo n.º 12
0
    bool GLES2FrameBufferObject::bind(bool recreateIfNeeded)
    {
        GLRenderSystemCommon* rs = static_cast<GLRenderSystemCommon*>(Root::getSingleton().getRenderSystem());
        GLContext* currentContext = rs->_getCurrentContext();
        if(mContext && mContext != currentContext) // FBO is unusable with current context, destroy it
        {
            if(mFB != 0)
                rs->_destroyFbo(mContext, mFB);
            if(mMultisampleFB != 0)
                rs->_destroyFbo(mContext, mMultisampleFB);
            
            mContext = 0;
            mFB = 0;
            mMultisampleFB = 0;
        }

        if(!mContext && recreateIfNeeded) // create FBO lazy or recreate after destruction
        {
            mContext = currentContext;
            
            // Generate framebuffer object
            OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &mFB));
#ifdef DEBUG
            if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_DEBUG))
            {
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
                OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mFB)); // to avoid GL_INVALID_OPERATION in glLabelObjectEXT(GL_FRAMEBUFFER,...) on iOS
#endif
                OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_FRAMEBUFFER, mFB, 0, ("FBO ##" + StringConverter::toString(mFB)).c_str()));
            }
#endif
            
            // Will we need a second FBO to do multisampling?
            if (mNumSamples)
            {
                OGRE_CHECK_GL_ERROR(glGenFramebuffers(1, &mMultisampleFB));
#ifdef DEBUG
                if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_DEBUG))
                {
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
                    OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mMultisampleFB)); // to avoid GL_INVALID_OPERATION in glLabelObjectEXT(GL_FRAMEBUFFER,...) on iOS
#endif
                    OGRE_CHECK_GL_ERROR(glLabelObjectEXT(GL_FRAMEBUFFER, mMultisampleFB, 0, ("MSAA FBO ##" + StringConverter::toString(mMultisampleFB)).c_str()));
                }
#endif
            }
            else
            {
                mMultisampleFB = 0;
            }
            
            // Re-initialise
            if(mColour[0].buffer)
                initialise();
        }

        if(mContext)
            OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, mMultisampleFB ? mMultisampleFB : mFB));

        return mContext != 0;
    }
Ejemplo n.º 13
0
	bool GLSLESProgram::compile(const bool checkErrors)
	{
		if (mCompiled == 1)
		{
			return true;
		}
		// Only create a shader object if glsl es is supported
		if (isSupported())
		{
            GL_CHECK_ERROR

			// Create shader object
			GLenum shaderType = 0x0000;
			if (mType == GPT_VERTEX_PROGRAM)
			{
				shaderType = GL_VERTEX_SHADER;
			}
            else if (mType == GPT_FRAGMENT_PROGRAM)
            {
				shaderType = GL_FRAGMENT_SHADER;
			}
			mGLShaderHandle = glCreateShader(shaderType);
            GL_CHECK_ERROR

#if GL_EXT_debug_label && OGRE_PLATFORM != OGRE_PLATFORM_NACL
            glLabelObjectEXT(GL_SHADER_OBJECT_EXT, mGLShaderHandle, 0, mName.c_str());
#endif

            if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS))
            {
                mGLProgramHandle = glCreateProgram();
                GL_CHECK_ERROR
#if GL_EXT_debug_label && OGRE_PLATFORM != OGRE_PLATFORM_NACL
                glLabelObjectEXT(GL_PROGRAM_OBJECT_EXT, mGLProgramHandle, 0, mName.c_str());
#endif
            }
		}

		// Add preprocessor extras and main source
		if (!mSource.empty())
		{
			const char *source = mSource.c_str();
			glShaderSource(mGLShaderHandle, 1, &source, NULL);
			// Check for load errors
            GL_CHECK_ERROR
		}

        if (checkErrors)
            logObjectInfo("GLSL ES compiling: " + mName, mGLShaderHandle);

		glCompileShader(mGLShaderHandle);
        GL_CHECK_ERROR

		// Check for compile errors
		glGetShaderiv(mGLShaderHandle, GL_COMPILE_STATUS, &mCompiled);
        if(!mCompiled && checkErrors)
		{
            String message = logObjectInfo("GLSL ES compile log: " + mName, mGLShaderHandle);
			checkAndFixInvalidDefaultPrecisionError(message);
		}

		// Log a message that the shader compiled successfully.
        if (mCompiled && checkErrors)
            logObjectInfo("GLSL ES compiled: " + mName, mGLShaderHandle);

        if(!mCompiled)
            OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
                        ((mType == GPT_VERTEX_PROGRAM) ? "Vertex Program " : "Fragment Program ") + mName +
                        " failed to compile. See compile log above for details.",
                        "GLSLESProgram::compile");

		return (mCompiled == 1);
	}
void GLSLESProgramPipeline::compileAndLink()
{
#if GL_EXT_separate_shader_objects && OGRE_PLATFORM != OGRE_PLATFORM_NACL
    GLint linkStatus = 0;

    OGRE_CHECK_GL_ERROR(glGenProgramPipelinesEXT(1, &mGLProgramPipelineHandle));
    OGRE_CHECK_GL_ERROR(glBindProgramPipelineEXT(mGLProgramPipelineHandle));

    // Compile and attach Vertex Program
    if(mVertexProgram && !mVertexProgram->isLinked())
    {
        try
        {
            mVertexProgram->getGLSLProgram()->compile(true);
        }
        catch (Exception& e)
        {
            LogManager::getSingleton().stream() << e.getDescription();
            mTriedToLinkAndFailed = true;
            return;
        }
        GLuint programHandle = mVertexProgram->getGLSLProgram()->getGLProgramHandle();
        OGRE_CHECK_GL_ERROR(glProgramParameteriEXT(programHandle, GL_PROGRAM_SEPARABLE_EXT, GL_TRUE));
        mVertexProgram->getGLSLProgram()->attachToProgramObject(programHandle);
        OGRE_CHECK_GL_ERROR(glLinkProgram(programHandle));
        OGRE_CHECK_GL_ERROR(glGetProgramiv(programHandle, GL_LINK_STATUS, &linkStatus));

        if(linkStatus)
        {
            mVertexProgram->setLinked(linkStatus);
            mLinked |= VERTEX_PROGRAM_LINKED;
        }

        mTriedToLinkAndFailed = !linkStatus;

        logObjectInfo( getCombinedName() + String("GLSL vertex program result : "), programHandle );

        setSkeletalAnimationIncluded(mVertexProgram->isSkeletalAnimationIncluded());
    }

    // Compile and attach Fragment Program
    if(mFragmentProgram && !mFragmentProgram->isLinked())
    {
        try
        {
            mFragmentProgram->getGLSLProgram()->compile(true);
        }
        catch (Exception& e)
        {
            LogManager::getSingleton().stream() << e.getDescription();
            mTriedToLinkAndFailed = true;
            return;
        }

        GLuint programHandle = mFragmentProgram->getGLSLProgram()->getGLProgramHandle();
        OGRE_CHECK_GL_ERROR(glProgramParameteriEXT(programHandle, GL_PROGRAM_SEPARABLE_EXT, GL_TRUE));
        mFragmentProgram->getGLSLProgram()->attachToProgramObject(programHandle);
        OGRE_CHECK_GL_ERROR(glLinkProgram(programHandle));
        OGRE_CHECK_GL_ERROR(glGetProgramiv(programHandle, GL_LINK_STATUS, &linkStatus));

        if(linkStatus)
        {
            mFragmentProgram->setLinked(linkStatus);
            mLinked |= FRAGMENT_PROGRAM_LINKED;
        }

        mTriedToLinkAndFailed = !linkStatus;

        logObjectInfo( getCombinedName() + String("GLSL fragment program result : "), programHandle );
    }

    if(mLinked)
    {
        if(mVertexProgram && mVertexProgram->isLinked())
        {
            OGRE_CHECK_GL_ERROR(glUseProgramStagesEXT(mGLProgramPipelineHandle, GL_VERTEX_SHADER_BIT_EXT, mVertexProgram->getGLSLProgram()->getGLProgramHandle()));
        }
        if(mFragmentProgram && mFragmentProgram->isLinked())
        {
            OGRE_CHECK_GL_ERROR(glUseProgramStagesEXT(mGLProgramPipelineHandle, GL_FRAGMENT_SHADER_BIT_EXT, mFragmentProgram->getGLSLProgram()->getGLProgramHandle()));
        }

        // Validate pipeline
        logObjectInfo( getCombinedName() + String("GLSL program pipeline result : "), mGLProgramPipelineHandle );
#if GL_EXT_debug_label && OGRE_PLATFORM != OGRE_PLATFORM_NACL
        if(mVertexProgram && mFragmentProgram)
            OGRE_IF_IOS_VERSION_IS_GREATER_THAN(5.0)
            glLabelObjectEXT(GL_PROGRAM_PIPELINE_OBJECT_EXT, mGLProgramPipelineHandle, 0,
                             (mVertexProgram->getName() + "/" + mFragmentProgram->getName()).c_str());
#endif
    }
#endif
}
Ejemplo n.º 15
0
void EnvironmentEs::objectLabel( GLenum identifier, GLuint name, GLsizei length, const char *label )
{
#if defined( CINDER_COCOA_TOUCH )
	glLabelObjectEXT( identifier, name, length, label );
#endif
}
Ejemplo n.º 16
0
Program::Program(const std::string& vs, const std::string& fs, const std::string& debug_name)
	: _debug_name(debug_name)
{
	VLOG_SCOPE_F(1, "Compiling GLSL %s", debug_name.c_str());

	CHECK_FOR_GL_ERROR;

	GLuint vs_id = load_shader(GL_VERTEX_SHADER,   vs.c_str(), debug_name.c_str());
	GLuint fs_id = load_shader(GL_FRAGMENT_SHADER, fs.c_str(), debug_name.c_str());

	_program = glCreateProgram();

#if TARGET_OS_IPHONE
	// For debugger:
	glLabelObjectEXT(GL_PROGRAM_OBJECT_EXT, _program, 0, debug_name.c_str());
#endif

	glAttachShader(_program, vs_id);
	glAttachShader(_program, fs_id);

	//GLuint color_number = 0;
	//glBindFragDataLocation(_program, color_number, "out_frag_color");

	link_program(_program, debug_name.c_str());

	/* too early to validate: uniforms haven't been bound yet.
	   Using two samplers of different type (sampler2D and sampler_cube)
	   will break the validation.
	 */
	//validate();

	CHECK_FOR_GL_ERROR;

	//debug_print();

#if 0
	LOG_F(INFO, "Shader: %s", debug_name.c_str());
	LOG_F(INFO, "-------------------------------------");
	LOG_F(INFO, "%s", vs.c_str());
	LOG_F(INFO, "-------------------------------------");
	LOG_F(INFO, "%s", fs.c_str());
	LOG_F(INFO, "-------------------------------------");
#endif

	GLint num_attribs;
	glGetProgramiv(_program, GL_ACTIVE_ATTRIBUTES, &num_attribs);

	for (int i=0; i<num_attribs; ++i) {
		GLint size;
		GLenum type;
		GLchar name[1024];
		glGetActiveAttrib(_program, i, sizeof(name), NULL, &size, &type, name);
		int location = glGetAttribLocation(_program, name);
		CHECK_NE_F(location, -1, "Attribute '%s' not found in shader '%s'", name, _debug_name.c_str());
		VLOG_F(1, "Attribute %d: %10s, %d x %s, location: %d", i, name, size, type_to_string(type), location);
		_attributes.emplace_back(Attribute{name, size, type, location});
	}

	GLint num_uniforms;
	glGetProgramiv(_program, GL_ACTIVE_UNIFORMS, &num_uniforms);

	for (int i=0; i<num_uniforms; ++i) {
		GLint size;
		GLenum type;
		GLchar name[1024];
		glGetActiveUniform(_program, i, sizeof(name), NULL, &size, &type, name);
		int location = glGetUniformLocation(_program, name);
		CHECK_NE_F(location, -1, "Uniform '%s' not found in shader '%s'", name, _debug_name.c_str());
		VLOG_F(1, "Uniform %d: %10s, %d x %s, location: %d", i, name, size, type_to_string(type), location);
		_uniforms.emplace_back(Uniform{name, size, type, location});
	}
}