我被指派为这个Objective C GPUImage 框架创建一个开源 Java 端口,以便它可以在 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,但这需要一个活动,对吗?当我发现这个Get Maximum OpenGL ES 2.0 Texture Size Limit on 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();
}
}