Определение максимального/минимального предела размера текстуры в Android OpenGLES

Мне было поручено создать порт Java с открытым исходным кодом Objective C GPUImage Framework , чтобы его можно было использовать в приложении для Android. Я должен воссоздать его как можно точнее, со всеми именами переменных, именами функций и т.д. Я на начальном этапе и пытаюсь портировать GPUImageOpenGLESContext.h и GPUImageOpenGLESContext.m (Извините, хотел бы дать ссылки, но как новый пользователь я не могу больше добавлять ссылки ).

У меня проблемы с этими методами

+ (GLint)maximumTextureSizeForThisDevice;
{
    GLint maxTextureSize; 
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
    return maxTextureSize;
}

+ (GLint)maximumTextureUnitsForThisDevice;
{
    GLint maxTextureUnits; 
    glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
    return maxTextureUnits;
}

Похоже, что в Objective C вы можете просто вызывать эти методы, а в Java — нет. Я провел некоторый поиск и обнаружил, что большинство людей говорят использовать GLSurfaceView, но для этого потребуется действие, верно? Я был очень взволнован, когда нашел это Получить максимальный размер текстуры OpenGL ES 2.0 на Android , но в ответе утверждается, что код не будет работать.

Итак, мой вопрос,как я могу получить минимальную и максимальную текстуру в классе, который не является активностью? Используете GLSurfaceView?

Я также был бы признателен за любые предложения о том, как портировать это. Я никогда ничего не портировал с Objective C на Java, поэтому буду признателен за любой совет!

Если это будет полезно, вот мой текущий код:

public class GPUImageOpenGLESContext 
{
    private static GPUImageOpenGLESContext instance = null;

    EGLContext context;

    protected GPUImageOpenGLESContext()
    {
        // This is a protected empty method
        // that exists only to prevent
        // this singleton object from
        // multiple instantiation

        return;
    }

    public enum GPUImageRotationMode { 
            kGPUImageNoRotation, kGPUImageRotateLeft, kGPUImageRotateRight, kGPUImageFlipVertical,
            kGPUImageFlipHorizontal, kGPUImageRotateRightFlipVertical, kGPUImageRotate180
    }

    public GPUImageRotationMode GPUImageRotationSwapsWidthAndHeight(GPUImageRotationMode rotation)
    {
        // TODO: Implement GPUImageRotationSwapsWidthAndHeight macro as method
        //rotation = ((rotation) == kGPUImageRotateLeft || (rotation) == kGPUImageRotateRight || (rotation) == kGPUImageRotateRightFlipVertical)
        return rotation;
    }

    public static GPUImageOpenGLESContext sharedImageProcessingOpenGLESContext()
    {
        if (instance == null)
        {
            instance = new GPUImageOpenGLESContext();
        }
        return instance;
    }

    public static void useImageProcessingContext()
    {
         EGLContext imageProcessingContext = GPUImageOpenGLESContext.sharedImageProcessingOpenGLESContext().context;
         if (EGLContext.getEGL() != imageProcessingContext)
         {
             // In Objective C, this call would be here:
             // [EAGLContext setCurrentContext:imageProcessingContext]

             // Cannot figure out how to handle this.  For now, throws an exception.
             throw new RuntimeException("useImageProcessingContext not equal to EGLContext");
         }

         return;
    }

    public static int maximumTextureSizeForThisDevice()
    {
        int[] maxTextureSize = new int[1];

        // TODO: See if you can use gl. without an activity
        //GL10 gl = new GL10();
        //EGL gl = EGLContext.getEGL();

        //gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);

        return maxTextureSize[0];
    }

    public static int maximumTextureUnitsForThisDevice()
    {
        // TODO: Implement maximumTextureUnitsForThisDevice();
        return -1;
    }

    public static CGSize sizeThatFitsWithinATextureForSize(CGSize inputSize)
    {
        int maxTextureSize = maximumTextureSizeForThisDevice();

        if ((inputSize.width < maxTextureSize) && (inputSize.height < maxTextureSize))
        {
            return inputSize;
        }

        CGSize adjustedSize = new CGSize();
        if (inputSize.width > inputSize.height)
        {
            adjustedSize.width = (float)maxTextureSize;
            adjustedSize.height = ((float)maxTextureSize / inputSize.width) * inputSize.height;
        }
        else
        {
            adjustedSize.height = (float)maxTextureSize;
            adjustedSize.width = ((float)maxTextureSize / inputSize.height) * inputSize.width;
        }

        return adjustedSize;
    }

    public EGLContext getContext()
    {
        if (context == null)
        {
            // TODO: Implement getContext()
        }
    }

    public interface GPUImageInput
    {
        public void newFrameReadyAtTime(Time frameTime);
        public void setInputTextureAtIndex(int newInputTexture, int textureIndex);
        public int nextAvailableTextureIndex();
        public void setInputSizeAtIndex(CGSize newSize, int textureIndex);
        public void setInputRotationAtIndex(GPUImageRotationMode newInputRotation, int textureIndex);
        public CGSize maximumOutputSize();
        public void endProcessing();
        public boolean shouldIgnoreUpdatesToThisTarget();
    }
}

6
задан Community 23 May 2017 в 12:00
поделиться