{"id":4389,"date":"2018-08-04T09:55:23","date_gmt":"2018-08-04T01:55:23","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=4389"},"modified":"2018-10-14T21:27:55","modified_gmt":"2018-10-14T13:27:55","slug":"android_game_batcher","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/android_game_batcher\/","title":{"rendered":"Android\u904a\u6232\u4e4b\u7cbe\u9748\u6279\u8655\u7406"},"content":{"rendered":"<figure id=\"attachment_4390\" aria-describedby=\"caption-attachment-4390\" style=\"width: 1200px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Batcher.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4390\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Batcher.jpg\" alt=\"\" width=\"1200\" height=\"800\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Batcher.jpg 1200w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Batcher-300x200.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Batcher-768x512.jpg 768w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Batcher-1024x683.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><figcaption id=\"caption-attachment-4390\" class=\"wp-caption-text\">Android\u904a\u6232\u4e4b\u7cbe\u9748\u6279\u8655\u7406<\/figcaption><\/figure>\n<p>OpenGL ES\u76e1\u53ef\u80fd\u6bcf\u6b21\u6e32\u67d3\u591a\u500b\u7cbe\u9748.\u4ee5\u63d0\u9ad8\u6e32\u67d3\u6027\u80fd.\u70ba\u6b64\u9700\u8981\u77e5\u9053\u7cbe\u9748\u300e\u4f4d\u7f6e\u300f\u300e\u5c3a\u5bf8\u300f\u300e\u7d0b\u7406\u5340\u57df\u300f.\u300e\u6279\u8655\u7406\u300f\u5c07\u591a\u500b\u6e32\u67d3\u5408\u62fc\u5728\u4e00\u8d77.\u9019\u5c0dGPU\u6709\u5229.\u6279\u8655\u7406\u8a2d\u7acb\u6d6e\u9ede\u6578\u300e\u7de9\u5b58\u300f\u4fdd\u5b58\u9802\u9ede.\u8a72\u7de9\u5b58\u5340\u521d\u6b64\u6642\u9700\u6e05\u7a7a.\u5b9a\u7fa9\u300e\u6279\u8655\u7406\u300f\u7d50\u69cbBATCHER.<\/p>\n<p>public class BATCHER {<\/p>\n<p>\u6210\u54e1Buffer\u70ba\u6d6e\u9ede\u578b\u6578\u7d44\u7528\u65bc\u5b58\u5132\u9802\u9ede.<\/p>\n<p>private static float[] buffer;<\/p>\n<p>\u6210\u54e1indices\u70ba\u77ed\u6574\u5f62\u7d22\u5f15.\u4ee5\u4e09\u89d2\u5f62\u6392\u5217\u7528\u65bc\u5132\u5b58\u9802\u9ede.<\/p>\n<p>public static short[] indices ;<\/p>\n<p>\u9802\u9ede\u5217\u8868\u7528\u65bc\u6279\u8655\u7406\u6e32\u67d3<\/p>\n<p>private static <a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">VERTICES<\/a> vertices;<\/p>\n<p>\u7de9\u5b58\u5beb\u5165\u7d22\u5f15\u521d\u6b64\u70ba\u96f6<\/p>\n<p>private static int index = 0;<\/p>\n<p>\u7cbe\u96f6\u6578\u91cf\u521d\u6b64\u70ba\u96f6<\/p>\n<p>public static int num = 0;<\/p>\n<p>\u521d\u6b21\u6279\u8655\u7406.max\u7cbe\u9748\u70ba\u6700\u5927\u91cf.<\/p>\n<p>public static void Init(int max){<\/p>\n<p>\u5206\u914d2D\u7cbe\u9748\u9802\u9ede\u7de9\u5b58,\u6bcf\u500b\u7cbe\u9748\u67094\u9802\u9ede,\u6bcf\u9802\u9ede\u89814\u500b\u6d6e\u9ede\u6578(\u7a7a\u9593\u5750\u6a19x,y\u5169\u500b,\u7d0b\u7406\u5750\u6a19u,v\u5169\u500b)<\/p>\n<p>buffer = new float[max<em>4<\/em>4];<\/p>\n<p>\u5206\u914d\u9802\u9ede\u7de9\u5b58.\u300e\u9802\u9ede\u300f\u300e\u7d0b\u7406\u5ea7\u6a19\u300f\u300e\u7d22\u5f15\u300f<\/p>\n<p>vertices = new <a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">VERTICES<\/a>(max * 4, max*6, false,true);<\/p>\n<p>\u5206\u914d\u7d22\u5f15\u6bcf\u500b\u7cbe\u97486\u500b\u7d22\u5f15<\/p>\n<p>indices = new short[max*6];<\/p>\n<p>int len = indices.length;\/\/ \u7d22\u5f15\u6578\u7d44\u9577\u5ea6<\/p>\n<p>index = 0;\/\/ \u7de9\u5b58\u5beb\u5165\u7d22\u5f15<\/p>\n<p>num = 0;\/\/\u00a0 \u7cbe\u96f6\u6578\u91cf<\/p>\n<p>\u751f\u6210\u9802\u9ede\u7d22\u5f15<\/p>\n<p>for (int i=0,j=0; i &lt; len; i += 6, j += 4) {<\/p>\n<p>indices[i + 0] = (short)(j + 0);<\/p>\n<p>indices[i + 1] = (short)(j + 1);<\/p>\n<p>indices[i + 2] = (short)(j + 2);<\/p>\n<p>indices[i + 3] = (short)(j + 2);<\/p>\n<p>indices[i + 4] = (short)(j + 3);<\/p>\n<p>indices[i + 5] = (short)(j + 0);<\/p>\n<p>}<\/p>\n<p>\u8a2d\u7f6e\u9802\u9ede\u7d22\u5f15<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">vertices.SetIndices<\/a>(indices, 0, indices.length);<\/p>\n<p>}<\/p>\n<p>\u6e96\u5099\u9032\u884c\u6279\u8655\u7406\u6e32\u67d3.\u9996\u5148\u7d81\u5b9a\u7d0b\u7406.\u4e26\u5c07\u300e\u7cbe\u96f6\u6578\u91cf\u300f\u300e\u7de9\u5b58\u7d22\u5f15\u300f\u7f6e\u96f6<\/p>\n<p>public static void Begin(<a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_texture_mapping\/\">TEXTURE<\/a> texture){<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_texture_mapping\/\">texture.Bind()<\/a>;\/\/ \u7d81\u5b9a\u7d0b\u7406<\/p>\n<p>num = 0;\/\/\u00a0 \u7cbe\u96f6\u6578\u91cf<\/p>\n<p>index = 0;\/\/ \u7de9\u5b58\u5beb\u5165\u7d22\u5f15<\/p>\n<p>}<\/p>\n<p>\u7d50\u675f\u6279\u8655\u7406\u6e32\u67d3.\u5c07\u9802\u9ede\u63d0\u4ea4\u7d66OpenGL\u6578\u7d44\u4e26\u89f8\u767c.\u7d81\u5b9a\u9802\u9ede\u6578\u64da\u5f8c\u9032\u5f62\u4e09\u89d2\u5f62\u6e32\u67d3.\u7136\u5f8c\u53d6\u6d88\u6578\u64da\u7d81\u5b9a.\u6bcf\u6b21\u8abf\u7528\u7e6a\u756b\u6642.\u5411\u7de9\u5b58\u5340\u4e2d\u6dfb\u52a04\u500b\u9802\u9ede\u53c3\u6578\u70ba\u300e\u4f4d\u7f6e\u300f\u300e\u984f\u8272\u300f\u300e\u7d22\u5f15\u300f\u300e\u7d0b\u7406\u5340\u57df\u300f<\/p>\n<p>public void boolean End(){<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">vertices.SetVertices<\/a>(buffer,0,index);<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">vertices.Bind()<\/a>;<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">vertices.Draw<\/a>(GL10.GL_TRIANGLES, 0, num * 6);<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_vertices\/\">vertices.Unbind()<\/a>;<\/p>\n<p>}<\/p>\n<p>\u6279\u8655\u7406\u7e6a\u756b\u8a08\u7b97\u7cbe\u9748\u4e2d\u5fc3\u300e\u4f4d\u7f6e\u300f\u53ca\u300e\u5bec\u548c\u9ad8\u300f.\u548c\u300e\u7d0b\u7406\u5340\u57df\u300f.\u751f\u6210\u7cbe\u9748\u300e\u5de6\u4e0b\u89d2\u300f\u8207\u300e\u53f3\u4e0a\u89d2\u300f\u300e\u7a7a\u9593\u5ea7\u6a19\u300f\u8207\u300e\u7d0b\u7406\u5ea7\u6a19\u300f<\/p>\n<p>public static void Draw(float x,float y,float width,float height,REGION region){<\/p>\n<p>float halfWidth = width\/2.0f;\/\/ \u5bec\u5ea6\u4e00\u534a<\/p>\n<p>float halfHeight = height\/2.0f;\/\/\u9ad8\u5ea6\u4e00\u534a<\/p>\n<p>float x1 = x &#8211; halfWidth;<\/p>\n<p>float y1 = y &#8211; halfHeight;<\/p>\n<p>float x2 = x + halfWidth;<\/p>\n<p>float y2 = y + halfHeight;<\/p>\n<p>buffer[index++] = x1;<\/p>\n<p>buffer[index++] = y1;<\/p>\n<p>buffer[index++] = region.u1;<\/p>\n<p>buffer[index++] = region.v2;<\/p>\n<p>buffer[index++] = x2;<\/p>\n<p>buffer[index++] = y1;<\/p>\n<p>buffer[index++] = region.u2;<\/p>\n<p>buffer[index++] = region.v2;<\/p>\n<p>buffer[index++] = x2;<\/p>\n<p>buffer[index++] = y2;<\/p>\n<p>buffer[index++] = region.u2;<\/p>\n<p>buffer[index++] = region.v1;<\/p>\n<p>buffer[index++] = x1;<\/p>\n<p>buffer[index++] = y2;<\/p>\n<p>buffer[index++] = region.u1;<\/p>\n<p>buffer[index++] = region.v1;<\/p>\n<p>++num;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5728\u8abf\u7528\u6642\u9996\u5148\u6e05\u7406\u7de9\u5b58\u4e26\u5b58\u5165\u7d0b\u7406.\u4f46\u53ea\u80fd\u5c0d\u4f7f\u7528\u540c\u4e00\u7d0b\u7406\u7cbe\u9748\u9032\u884c\u6279\u8655\u7406.\u6700\u5f8c\u7d50\u675f\u6e32\u67d3.\u5982\u4e0b:<\/p>\n<p>BATCHER.Begin(Texture);<\/p>\n<p>BATCHER.Draw(X,Y,WIDTH,HEIGHT,Region);<\/p>\n<p>BATCHER.End();<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenGL ES\u76e1\u53ef\u80fd\u6bcf\u6b21\u6e32\u67d3\u591a\u500b\u7cbe\u9748.\u4ee5\u63d0\u9ad8\u6e32\u67d3\u6027\u80fd.\u70ba\u6b64\u9700\u8981\u77e5\u9053\u7cbe\u9748\u300e\u4f4d\u7f6e\u300f\u300e\u5c3a\u5bf8\u300f\u300e\u7d0b\u7406\u5340\u57df\u300f.\u300e\u6279\u8655 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_batcher\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Android\u904a\u6232\u4e4b\u7cbe\u9748\u6279\u8655\u7406<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,62],"tags":[2,50],"class_list":["post-4389","post","type-post","status-publish","format-standard","hentry","category-android","category-opengl","tag-android","tag-opengl","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=4389"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4389\/revisions"}],"predecessor-version":[{"id":4391,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4389\/revisions\/4391"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=4389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=4389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=4389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}