久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Android/Java 上安全使用 glMapBufferRange()

Safe usage of glMapBufferRange() on Android/Java(在 Android/Java 上安全使用 glMapBufferRange())
本文介紹了在 Android/Java 上安全使用 glMapBufferRange()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 Android 上使用來自 OpenGL-ES 3.0 的 glMapBufferRange() 的工作代碼如下所示:

I have working code using glMapBufferRange() from OpenGL-ES 3.0 on Android that looks like this:

  glBindBuffer(GL_ARRAY_BUFFER, myVertexBufferName);
  glBufferData(GL_ARRAY_BUFFER, myVertexBufferSize, null, GL_STATIC_DRAW);
  ByteBuffer mappedBuffer = (ByteBuffer)glMapBufferRange(
    GL_ARRAY_BUFFER,
    0, myVertexBufferSize,
    GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

  // [fill buffer...]

  glUnmapBuffer(GL_ARRAY_BUFFER);

我的問題是關于在第三行將 glMapBufferRange() 的結果向下轉換為 ByteBuffer.glMapBufferRange() 是 聲明返回一個Buffer:

My question is about downcasting the result of glMapBufferRange() to ByteBuffer on the third line. glMapBufferRange() is declared to return a Buffer:

public static Buffer glMapBufferRange (int target, int offset, int length, int access)

在我的測試平臺上,該函數返回 ByteBuffer 的子類,因此該轉換可以工作,但對支持 OpenGL-ES 3+ 的所有平臺或 Android 版本做出此假設似乎并不安全.雖然看起來很合理,但我還沒有找到任何保證它的文檔,如果它得到保證,似乎該函數應該被聲明為返回 ByteBuffer.

On my test platform the function returns a subclass of ByteBuffer so the cast works, but making this assumption for all platforms or Android versions supporting OpenGL-ES 3+ doesn't seem very safe. Although it seems reasonable, I haven't found any documentation that guarantees it, and if it were guaranteed it seems like the function should be declared as returning ByteBuffer.

使用 glMapBufferRange() 返回的 Buffer 的正確方法是什么(最好有文檔支持)?

What is the correct way (preferably supported by documentation) of using the Buffer returned by glMapBufferRange()?

推薦答案

正如您已經發現的那樣,缺少文檔.但仍然有一個相當確鑿的參考資料:OpenGL Java 綁定的實現是公共 Android 源代碼的一部分.

As you already found, the documentation is lacking. But there is still a fairly conclusive reference: The implementation of the OpenGL Java bindings is part of the public Android source code.

如果您查看 glMapBufferRange() 的 JNI 包裝器的實現,它位于文件 glMapBufferRange.cpp,可以看到調用NewDirectByteBuffer()函數分配了緩沖區.基于此,假設緩沖區確實是一個 ByteBuffer 似乎是安全的.

If you look at the implementation of the JNI wrapper for glMapBufferRange(), which is in the file glMapBufferRange.cpp, you can see that the buffer is allocated by calling a function named NewDirectByteBuffer(). Based on this, it seems safe to assume that the buffer is indeed a ByteBuffer.

雖然供應商可以更改 Android 代碼,但似乎任何人都不太可能更改 Java 綁定的行為(可能修復錯誤除外).如果您擔心在以后的 Android 版本中實現可能會發生變化,您當然可以使用標準的 Java 類型檢查:

While vendors can change the Android code, it seems very unlikely that anybody would change the behavior of the Java bindings (except maybe to fix bugs). If you are concerned that the implementation could change in later Android versions, you can certainly use a standard Java type check:

Buffer buf = glMapBufferRange(...);
ByteBuffer byteBuf = null;
if (buf instanceof ByteBuffer) {
    byteBuf = (ByteBuffer)buf;
}

或者您可以使用更精細的反射,首先在返回的緩沖區上調用 getClass().下一個問題當然是如果返回的緩沖區不是 ByteBuffer 該怎么辦.它真的是唯一對我有意義的類型.

Or you could use more elaborate reflection, starting with calling getClass() on the returned buffer. The next question is of course what you do if the returned buffer is not a ByteBuffer. It's really the only type that makes sense to me.

這篇關于在 Android/Java 上安全使用 glMapBufferRange()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 九九精品视频在线观看 | 久久精品国产77777蜜臀 | 中文字幕的 | 三级视频在线观看 | 日韩三级一区 | 交换多p群乱高h文 | 三上悠亚激情av一区二区三区 | 中文在线字幕免费观看 | 黄色片视频在线观看 | 国产欧美日本 | www国产在线观看 | av影片在线观看 | 免费观看a级片 | 在线免费av网站 | 久久精品导航 | 色综合一区二区 | 亚洲精品无 | av在线免费网站 | 亚洲大片在线观看 | 蜜桃色一区二区三区 | 国产做爰免费观看视频 | 亚洲成人精品在线 | 天天视频黄 | 夜夜夜夜操 | 亚洲午夜18毛片在线看 | 九九热精品在线 | 日韩精品视频免费 | 婷婷av在线 | 日本香蕉视频 | 精品一区二区在线视频 | 国产91在线视频 | 国产精品一区一区三区 | 欧美一区二区三区在线观看视频 | av毛片在线看 | 四虎在线免费观看视频 | 在线国产小视频 | 久久精品一区二区三区四区五区 | 一区二区三区四区在线视频 | 啪啪网站免费 | 亚洲天堂免费 | 精品久久一区二区 |