Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1a39d67 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Added most of the support needed for GLES 2.x

parent a3d66a83
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
#ifndef __gl2platform_h_
#define __gl2platform_h_

/* $Revision: 7173 $ on $Date:: 2009-01-09 11:18:21 -0800 #$ */

/*
 * This document is licensed under the SGI Free Software B License Version
 * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
 */

/* Platform-specific types and definitions for OpenGL ES 2.X  gl2.h
 * Last modified on 2008/12/19
 *
 * Adopters may modify khrplatform.h and this file to suit their platform.
 * You are encouraged to submit all modifications to the Khronos group so that
 * they can be included in future versions of this file.  Please submit changes
 * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
 * by filing a bug against product "OpenGL-ES" component "Registry".
 */

#include <KHR/khrplatform.h>

#ifndef GL_APICALL
#define GL_APICALL  KHRONOS_APICALL
#endif

#define GL_APIENTRY KHRONOS_APIENTRY

#endif /* __gl2platform_h_ */
+34 −5
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)

#
###############################################################################
# Build META EGL library
#

@@ -30,8 +30,8 @@ include $(BUILD_SHARED_LIBRARY)



#
# Build the wrapper OpenGL ES library
###############################################################################
# Build the wrapper OpenGL ES 1.x library
#

include $(CLEAR_VARS)
@@ -57,3 +57,32 @@ LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
LOCAL_CFLAGS += -fvisibility=hidden

include $(BUILD_SHARED_LIBRARY)


###############################################################################
# Build the wrapper OpenGL ES 2.x library
#

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= 		\
	GLES2/gl2.cpp.arm 	\
#

LOCAL_SHARED_LIBRARIES += libcutils libEGL
LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libGLESv2

# needed on sim build because of weird logging issues
ifeq ($(TARGET_SIMULATOR),true)
else
    LOCAL_SHARED_LIBRARIES += libdl
    # we need to access the Bionic private header <bionic_tls.h>
    LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../bionic/libc/private
endif

LOCAL_CFLAGS += -DLOG_TAG=\"libGLESv2\"
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
LOCAL_CFLAGS += -fvisibility=hidden

include $(BUILD_SHARED_LIBRARY)
+67 −47
Original line number Diff line number Diff line
@@ -153,8 +153,14 @@ static void gl_unimplemented() {
#define EGL_ENTRY(_r, _api, ...) #_api,

static char const * const gl_names[] = {
    #include "gl_entries.in"
    #include "glext_entries.in"
    #include "GLES_CM/gl_entries.in"
    #include "GLES_CM/glext_entries.in"
    NULL
};

static char const * const gl2_names[] = {
    #include "GLES2/gl2_entries.in"
    #include "GLES2/gl2ext_entries.in"
    NULL
};

@@ -275,51 +281,16 @@ EGLContext getContext() {

/*****************************************************************************/

static __attribute__((noinline))
void *load_driver(const char* driver, gl_hooks_t* hooks)
{
    //LOGD("%s", driver);
    char scrap[256];
    void* dso = dlopen(driver, RTLD_NOW | RTLD_LOCAL);
    LOGE_IF(!dso,
            "couldn't load <%s> library (%s)",
            driver, dlerror());

    if (dso) {
        // first find the symbol for eglGetProcAddress
        
typedef __eglMustCastToProperFunctionPointerType (*getProcAddressType)(
        const char*);

        getProcAddressType getProcAddress = 
            (getProcAddressType)dlsym(dso, "eglGetProcAddress");
        
        LOGE_IF(!getProcAddress, 
                "can't find eglGetProcAddress() in %s", driver);        
        
        __eglMustCastToProperFunctionPointerType* curr;
        char const * const * api;

        gl_hooks_t::egl_t* egl = &hooks->egl;
        curr = (__eglMustCastToProperFunctionPointerType*)egl;
        api = egl_names;
        while (*api) {
            char const * name = *api;
            __eglMustCastToProperFunctionPointerType f = 
                (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
            if (f == NULL) {
                // couldn't find the entry-point, use eglGetProcAddress()
                f = getProcAddress(name);
                if (f == NULL) {
                    f = (__eglMustCastToProperFunctionPointerType)0;
                }
            }
            *curr++ = f;
            api++;
        }
        gl_hooks_t::gl_t* gl = &hooks->gl;
        curr = (__eglMustCastToProperFunctionPointerType*)gl;
        api = gl_names;
static __attribute__((noinline))
void init_api(void* dso, 
        char const * const * api, 
        __eglMustCastToProperFunctionPointerType* curr, 
        getProcAddressType getProcAddress) 
{
    char scrap[256];
    while (*api) {
        char const * name = *api;
        __eglMustCastToProperFunctionPointerType f = 
@@ -357,6 +328,55 @@ void *load_driver(const char* driver, gl_hooks_t* hooks)
        api++;
    }
}

static __attribute__((noinline))
void *load_driver(const char* driver, gl_hooks_t* hooks)
{
    //LOGD("%s", driver);
    void* dso = dlopen(driver, RTLD_NOW | RTLD_LOCAL);
    LOGE_IF(!dso,
            "couldn't load <%s> library (%s)",
            driver, dlerror());

    if (dso) {
        // first find the symbol for eglGetProcAddress
        
        typedef __eglMustCastToProperFunctionPointerType (*getProcAddressType)(
                const char*);
        
        getProcAddressType getProcAddress = 
            (getProcAddressType)dlsym(dso, "eglGetProcAddress");
        
        LOGE_IF(!getProcAddress, 
                "can't find eglGetProcAddress() in %s", driver);        

        gl_hooks_t::egl_t* egl = &hooks->egl;
        __eglMustCastToProperFunctionPointerType* curr =
                (__eglMustCastToProperFunctionPointerType*)egl;
        char const * const * api = egl_names;
        while (*api) {
            char const * name = *api;
            __eglMustCastToProperFunctionPointerType f = 
                (__eglMustCastToProperFunctionPointerType)dlsym(dso, name);
            if (f == NULL) {
                // couldn't find the entry-point, use eglGetProcAddress()
                f = getProcAddress(name);
                if (f == NULL) {
                    f = (__eglMustCastToProperFunctionPointerType)0;
                }
            }
            *curr++ = f;
            api++;
        }
        
        init_api(dso, gl_names,  
                (__eglMustCastToProperFunctionPointerType*)&hooks->gl, 
                getProcAddress);
        
        init_api(dso, gl2_names, 
                (__eglMustCastToProperFunctionPointerType*)&hooks->gl2, 
                getProcAddress);
    }
    return dso;
}

+111 −0
Original line number Diff line number Diff line
/* 
 ** Copyright 2007, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License"); 
 ** you may not use this file except in compliance with the License. 
 ** You may obtain a copy of the License at 
 **
 **     http://www.apache.org/licenses/LICENSE-2.0 
 **
 ** Unless required by applicable law or agreed to in writing, software 
 ** distributed under the License is distributed on an "AS IS" BASIS, 
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 ** See the License for the specific language governing permissions and 
 ** limitations under the License.
 */

#include <ctype.h>
#include <string.h>
#include <errno.h>

#include <sys/ioctl.h>

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#include <cutils/log.h>
#include <cutils/properties.h>

#include "hooks.h"
#include "egl_impl.h"

using namespace android;

// ----------------------------------------------------------------------------
// Actual GL entry-points
// ----------------------------------------------------------------------------

#undef API_ENTRY
#undef CALL_GL_API
#undef CALL_GL_API_RETURN

#if USE_FAST_TLS_KEY

    #define API_ENTRY(_api) __attribute__((naked)) _api

    #define CALL_GL_API(_api, ...)                              \
         asm volatile(                                          \
            "mov   r12, #0xFFFF0FFF   \n"                       \
            "ldr   r12, [r12, #-15]   \n"                       \
            "ldr   r12, [r12, %[tls]] \n"                       \
            "cmp   r12, #0            \n"                       \
            "ldrne pc,  [r12, %[api]] \n"                       \
            "bx    lr                 \n"                       \
            :                                                   \
            : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
              [api] "J"(__builtin_offsetof(gl_hooks_t, gl2._api))    \
            :                                                   \
            );
    
    #define CALL_GL_API_RETURN(_api, ...) \
        CALL_GL_API(_api, __VA_ARGS__) \
        return 0; // placate gcc's warnings. never reached.

#else

    #define API_ENTRY(_api) _api

    #define CALL_GL_API(_api, ...)                                       \
        gl_hooks_t::gl2_t const * const _c = &getGlThreadSpecific()->gl2; \
        _c->_api(__VA_ARGS__)
    
    #define CALL_GL_API_RETURN(_api, ...)                                \
        gl_hooks_t::gl2_t const * const _c = &getGlThreadSpecific()->gl2; \
        return _c->_api(__VA_ARGS__)

#endif


extern "C" {
#include "gl2_api.in"
#include "gl2ext_api.in"
}

#undef API_ENTRY
#undef CALL_GL_API
#undef CALL_GL_API_RETURN


/*
 * These GL calls are special because they need to EGL to retrieve some
 * informations before they can execute.
 */

extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);


void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
{
    GLeglImageOES implImage = 
        (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
    __glEGLImageTargetTexture2DOES(target, implImage);
}

void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
{
    GLeglImageOES implImage = 
        (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
    __glEGLImageTargetRenderbufferStorageOES(target, image);
}
Loading