Tôi đã được gán để tạo cổng Java nguồn mở của Objective C GPUImage Framework này để có thể sử dụng trong ứng dụng Android. Tôi sẽ tái tạo nó một cách chặt chẽ nhất có thể, với tất cả các tên biến, tên hàm, v.v. giống nhau. Tôi đang ở giai đoạn đầu và tôi đang cố gắng kết nối GPUImageOpenGLESContext.h và GPUImageOpenGLESContext.m (Xin lỗi, sẽ cung cấp liên kết, nhưng với tư cách là người dùng mới, tôi không thể thêm bất kỳ liên kết nào khác).Xác định giới hạn kích thước họa tiết tối đa/tối trong Android OpenGLES
Tôi đang gặp khó khăn với những phương pháp
+ (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;
}
Dường như trong Objective C, bạn có thể chỉ đơn giản là gọi những phương pháp nhưng trong Java bạn không thể. Tôi đã thực hiện một số tìm kiếm và thấy rằng hầu hết mọi người đã nói để sử dụng GLSurfaceView, nhưng điều đó sẽ yêu cầu một hoạt động, đúng không? Tôi đã rất vui mừng khi tôi tìm thấy điều này Get Maximum OpenGL ES 2.0 Texture Size Limit on Android, nhưng phản ứng cho rằng mã sẽ không hoạt động.
Vì vậy, câu hỏi của tôi là, làm cách nào để có được kết cấu tối thiểu và tối đa trong một lớp không phải là hoạt động? Sử dụng GLSurfaceView?
Tôi cũng đánh giá cao bất kỳ đề xuất nào về cách thực hiện điều này. Tôi chưa bao giờ chuyển bất cứ thứ gì từ Objective C sang Java, vì vậy mọi lời khuyên sẽ được đánh giá cao!
Nếu nó sẽ là hữu ích, đây là mã hiện tại của tôi:
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();
}
}
Khi bạn hoàn tất, hãy đảm bảo rằng bạn cho người này biết về điều đó: http://stackoverflow.com/questions/11405207/gpuimage-port-for-android –
Bạn đã thử GLES20.glGetIntegerv (GLES20.GL_MAX_TEXTURE_SIZE, kích thước, 0); ? – cleuton