/*
* Copyright (C) 2011 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.
*/
#ifndef __GL_UTILS_H__
#define __GL_UTILS_H__

#include <cutils/log.h>

#include <stdio.h>
#include <stdlib.h>

#ifdef GL_API
    #undef GL_API
#endif
#define GL_API

#ifdef GL_APIENTRY
    #undef GL_APIENTRY
#endif

#ifdef GL_APIENTRYP
    #undef GL_APIENTRYP
#endif
#define GL_APIENTRYP

#ifndef ANDROID
#define GL_APIENTRY
#endif

#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    INDIRECT_COMMAND_DRAWARRAYS = 0,
    INDIRECT_COMMAND_DRAWELEMENTS = 1,
} IndirectCommandType;

    bool isSamplerType(GLenum type);
    bool isIntegerType(GLenum type);
    bool isUnsignedIntType(GLenum type);
    bool isBoolType(GLenum type);
    uint32_t getColumnsOfType(GLenum type);
    uint32_t getRowsOfType(GLenum type);
    uint32_t getAttributeCountOfType(GLenum type);
    size_t glSizeof(GLenum type);
    size_t glUtilsParamSize(GLenum param);
    void   glUtilsPackPointerData(unsigned char *dst, unsigned char *str,
                           int size, GLenum type, unsigned int stride,
                           unsigned int datalen);
    void glUtilsWritePackPointerData(void* stream, unsigned char *src,
                                    int size, GLenum type, unsigned int stride,
                                    unsigned int datalen);
    int glUtilsPixelBitSize(GLenum format, GLenum type);
    void   glUtilsPackStrings(char *ptr, char **strings, GLint *length, GLsizei count);
    int glUtilsCalcShaderSourceLen(char **strings, GLint *length, GLsizei count);
    GLenum glUtilsColorAttachmentName(int i);
    int glUtilsColorAttachmentIndex(GLenum attachment);

    GLuint glUtilsIndirectStructSize(IndirectCommandType cmdType);

    bool colorRenderableFormat(GLint internalformat, GLenum texturetype, int majorVersion, int minorVersion, bool hasColorBufferFloatExtension, bool hasColorBufferHalfFloatExtension);

    bool depthRenderableFormat(GLint internalformat);
    bool stencilRenderableFormat(GLint internalformat);

#ifdef __cplusplus
}
#endif

namespace GLUtils {

    template <class T> void minmax(const T *indices, int count, int *min, int *max) {
        *min = -1;
        *max = -1;
        const T *ptr = indices;
        for (int i = 0; i < count; i++) {
            if (*min == -1 || *ptr < *min) *min = *ptr;
            if (*max == -1 || *ptr > *max) *max = *ptr;
            ptr++;
        }
    }

    template <class T> void minmaxExcept
        (const T *indices, int count, int *min, int *max,
         bool shouldExclude, T whatExclude) {

        if (!shouldExclude) return minmax(indices, count, min, max);

        *min = -1;
        *max = -1;
        const T *ptr = indices;
        for (int i = 0; i < count; i++) {
            if (*ptr != whatExclude) {
                if (*min == -1 || *ptr < *min) *min = *ptr;
                if (*max == -1 || *ptr > *max) *max = *ptr;
            }
            ptr++;
        }
    }

    template <class T> void shiftIndices(T *indices, int count,  int offset) {
        T *ptr = indices;
        for (int i = 0; i < count; i++) {
            *ptr += offset;
            ptr++;
        }
    }


    template <class T> void shiftIndices(const T *src, T *dst, int count, int offset)
    {
        for (int i = 0; i < count; i++) {
            *dst = *src + offset;
            dst++;
            src++;
        }
    }

    template <class T> void shiftIndicesExcept
        (T *indices, int count, int offset,
         bool shouldExclude, T whatExclude) {

        if (!shouldExclude) return shiftIndices(indices, count, offset);

        T *ptr = indices;
        for (int i = 0; i < count; i++) {
            if (*ptr != whatExclude) {
                *ptr += offset;
            }
            ptr++;
        }
    }

    template <class T> void shiftIndicesExcept
        (const T *src, T *dst, int count, int offset,
         bool shouldExclude, T whatExclude) {

        if (!shouldExclude) return shiftIndices(src, dst, count, offset);

        for (int i = 0; i < count; i++) {
            if (*src == whatExclude) {
                *dst = *src;
            } else {
                *dst = *src + offset;
            }
            dst++;
            src++;
        }
    }

    template<class T> T primitiveRestartIndex() {
        return -1;
    }

} // namespace GLUtils
#endif
