久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产福利视频 | 久久久久久av | 国产免费一区二区三区网站免费 | 中文字幕日韩欧美一区二区三区 | 国产性生活一级片 | 免费精品久久久久久中文字幕 | 午夜成人在线视频 | 亚洲精品免费看 | 国产成人精品久久久 | 亚洲国产一区二区视频 | 亚洲成人久久久 | 久久噜噜噜精品国产亚洲综合 | 日韩在线 | 欧美日一区二区 | 91tv在线观看 | 亚洲精品亚洲人成人网 | 亚洲欧美精品久久 | 欧美一级特黄aaa大片在线观看 | 欧美一级在线免费观看 | 亚洲精美视频 | 成人特区| 99re在线视频免费观看 | 久久99视频精品 | 这里只有精品99re | www.日韩| 一区二区久久电影 | 久久网站免费视频 | 久久久久久久一区二区三区 | 日韩精品在线看 | av一级久久 | 欧美一区二区三区高清视频 | 日一区二区三区 | 黄色大片免费看 | 麻豆国产一区二区三区四区 | 一区二区在线 | 久久的色| 国产一区二区三区久久久久久久久 | 欧美视频成人 | 欧美国产在线一区 | 日韩电影中文字幕在线观看 | 国产精品一区久久久 |