Kotlin(标签:kotlin)packagecom。codelearning。vulkaninfoimportandroid。Manifestimportandroid。content。ClipDataimportandroid。content。ClipboardManagerimportandroid。content。Contextimportandroid。content。pm。PackageManagerimportandroid。content。res。AssetManagerimportandroidx。appcompat。app。AppCompatActivityimportandroid。os。Bundleimportandroid。os。Environmentimportandroid。util。Logimportcom。codelearning。vulkaninfo。databinding。ActivityMainBindingimportjava。io。IOExceptionimportjava。io。RandomAccessFileimportjava。nio。charset。StandardCharsetsprivateexternalfundoVulkanWork(assetMgr:AssetManager,logBuffer:ByteArray):IntclassMainActivity:AppCompatActivity(){privatelateinitvarbinding:ActivityMainBindingprivatevarmisVulkanAvailabletrueoverridefunonCreate(savedInstanceState:Bundle?){super。onCreate(savedInstanceState)bindingActivityMainBinding。inflate(layoutInflater)setContentView(binding。root)Exampleofacalltoanativemethodbinding。sampleText。textstringFromJNI()if(binding。sampleText。text。contains(Failed,true)){misVulkanAvailablefalse}binding。runVulkanButton。setOnClickListener{if(!misVulkanAvailable)returnsetOnClickListenervallogBufferByteArray(1010241024)valdataLendoVulkanWork(assets,logBuffer)vallogStrString(logBuffer,0,dataLen,StandardCharsets。UTF8)valclipboardgetSystemService(Context。CLIPBOARDSERVICE)asClipboardManagervalclipDataClipData。newPlainText(vulkaninfo,logStr)clipboard。setPrimaryClip(clipData)binding。sampleText。textresources。getString(R。string。contentsarecopied)if(checkSelfPermission(Manifest。permission。WRITEEXTERNALSTORAGE)!PackageManager。PERMISSIONGRANTED){requestPermissions(arrayOf(Manifest。permission。WRITEEXTERNALSTORAGE),101)}valfileEnvironment。getExternalStoragePublicDirectory(Environment。DIRECTORYDOCUMENTS)?:returnsetOnClickListenertry{valfilePathfile。absolutePathvulkaninfo。logLog。i(null,Thefilepathtobesaved:filePath)valfileAccessRandomAccessFile(filePath,rw)fileAccess。write(logBuffer,0,dataLen)fileAccess。close()}catch(e:IOException){Log。i(null,Filewriteerror:{e。localizedMessage})}binding。sampleText。textresources。getString(R。string。fileissaved)}}Anativemethodthatisimplementedbythevulkaninfonativelibrary,whichispackagedwiththisapplication。externalfunstringFromJNI():Stringcompanionobject{Usedtoloadthevulkaninfolibraryonapplicationstartup。init{System。loadLibrary(vulkaninfo)}}}Lua(标签:lua)printHello,Lua!functiontestfunc()localnum0returnfunction()numnum1returnnumendendMakefile(标签:makefile)all:main。omodule。ogccmain。omodule。ootargetbinmain。o:main。cmodule。hgccI。cmain。cmodule。o:module。cmodule。hgccI。cmodule。cclean:rmrf。ormtargetbinMetalShadingLanguage(标签:metal)控制点结构体structControlPoint{float2position〔〔attribute(0)〕〕;float4color〔〔attribute(1)〕〕;};Patch结构体structPatchIn{patchcontrolpointControlPointcontrolpoints;};顶点着色器输出到片段着色器的结构体structFunctionOutIn{float4position〔〔position〕〕;half4color〔〔flat〕〕;};三角形细分曲面后处理顶点着色器〔〔patch(triangle,3)〕〕vertexstructFunctionOutIntrianglevertex(structPatchInpatchIn〔〔stagein〕〕,float3patchcoord〔〔positioninpatch〕〕){floatupatchcoord。x;floatvpatchcoord。y;floatwpatchcoord。z;将当前控制点坐标(u,v,w)通过线性插值转换为笛卡尔坐标(x,y)floatxupatchIn。controlpoints〔0〕。position。xvpatchIn。controlpoints〔1〕。position。xwpatchIn。controlpoints〔2〕。position。x;floatyupatchIn。controlpoints〔0〕。position。yvpatchIn。controlpoints〔1〕。position。ywpatchIn。controlpoints〔2〕。position。y;顶点输出structFunctionOutInvertexOut;vertexOut。positionfloat4(x,y,0。0,1。0);vertexOut。colorhalf4(u,v,w,1。0);returnvertexOut;}四边形细分曲面后处理顶点着色器〔〔patch(quad,4)〕〕vertexstructFunctionOutInquadvertex(structPatchInpatchIn〔〔stagein〕〕,float2patchcoord〔〔positioninpatch〕〕){从tessellator处理之后所获得的规格化之后的控制点坐标uv坐标的原点(即(0,0)的位置)是在原patch的左下顶点floatupatchcoord。x;floatvpatchcoord。y;以下通过线性插值的算法将规格化后的控制点坐标再转换为相对于输入顶点的坐标float2lowermiddlemix(patchIn。controlpoints〔0〕。position。xy,patchIn。controlpoints〔1〕。position。xy,u);float2uppermiddlemix(patchIn。controlpoints〔2〕。position。xy,patchIn。controlpoints〔3〕。position。xy,1u);顶点输出structFunctionOutInvertexOut;vertexOut。positionfloat4(mix(lowermiddle,uppermiddle,v),0。0f,1。0f);vertexOut。colorhalf4(u,v,1。0fv,1。0h);靠左下的所有顶点使用原patch左下顶点的颜色if(u0。5fv0。5f){vertexOut。colorhalf4(patchIn。controlpoints〔0〕。color);}靠右下的所有顶点使用原patch右下顶点的颜色elseif(u0。5fv0。5f){vertexOut。colorhalf4(patchIn。controlpoints〔1〕。color);}靠右上的所有顶点使用原patch右上顶点的颜色elseif(u0。5fv0。5f){vertexOut。colorhalf4(patchIn。controlpoints〔2〕。color);}靠左上的所有顶点使用原patch左上顶点的颜色elseif(u0。5fv0。5f){vertexOut。colorhalf4(patchIn。controlpoints〔3〕。color);}returnvertexOut;}NASM(标签:nasm);这是一个汇编文件;YASM的注释风格使用分号形式globalMyASMTestsection。textMyASMTest:subedi,esimoveax,ediretObjectiveC(标签:objectivec)importFoundation;intmain(void){autoreleasepool{NSLog(Hello,thisisamodernObjectiveC2。0program!);unicharcu加;NSLog(Thecharacteris:C,c);}}OpenCL(标签:opencl)kernelvoidsolvesum(globalunsignedbuffer〔512〕,globalunsigneddest〔512〕){localvolatileintflag0;sizetgidgetglobalid(0);constuint4value(uint4)(1,2,3,4);if(0gidgid32){while(flag0);vstore4(value,gid,buffer);writememfence(CLKGLOBALMEMFENCE);flag0;}elseif(32gidgid64){flag1;while(flag1);unsignedretbuffer〔12732gid〕;dest〔gid32〕ret;}}PHP(标签:php)lt;?phpecho(HelloPHP!);?Python(标签:python)hello10ifhello10:print(ThisisaPythonprogram)lam1lambdax,y:xylam2lambdalam:lam(20,10)2lam3lambdax,y:x(lambdaa:xa)(hello)ylam4lambdax:lambday:yxprint(lam1(100,hello))print(lam2(lam1))print(lam3(4,5))print(lam4(2)(8))Rust(标签:rust)fnmain(){println!(ThisisaRustprogram!);letaHelloA!;letbHelloB!;println!({}{},a,b);}Scheme(标签:scheme)(definex2);Value:x(x10);Value:12(definey(32));Value:y(y0。5x);Value:4。(y0。1);Value:1。6Swift(标签:swift)classViewController:NSViewController{overridefuncviewDidLoad(){super。viewDidLoad()由于myMethod方法被重载,因此这里对funcRef显式指定类型来指明指向不带任何参数的myMethod方法letfuncRef:()Voidself。myMethodfuncRef()或者可以这么写:直接显式地在方法名后添加上类型letfuncRef2self。myMethodas()VoidfuncRef2()这里使用方法签名myMethod(a:)来指明metohdRef指向myMethod(aa:Int)方法,而methodRef的类型被推导为:(a:Int)VoidvarmethodRefself。myMethod(a:)methodRef(a:100)methodRefself。myMethod(:)methodRef(a:200)这里即便有一个a:标签也无所谓,调用的仍然是myMethod(:)方法各位请注意,这里的mref的类型为:(:Int)Void注意,其形参不含外部标签varmrefself。myMethod(:)mref(10)这里又指向了myMethod(a:Int)方法mrefself。myMethod(a:)mref(20)仅管这里没有标签,但调用时仍然调用的是myMethod(a:Int)方法上述是隐式地做类型推导,而下面我们可以用显式的类型指定显式指明ref是一个带有含外部标签b的形参的方法引用letref:(b:Int)Voidself。myMethod(a:)ref(b:30)以下是对应的selector的描述varsel:Selectorselector(self。myMethod(a:))selselector(self。myMethod(:))对于不带参数的方法,被用作selector时,必须在后面显式地加上函数类型selselector(self。myMethodas()Void)}funcmyMethod(){print(Mymethod!)}funcmyMethod(aa:Int){print(Method2value(a))}funcmyMethod(a:Int){print(Method3value(a))}overridevarrepresentedObject:AnyObject?{didSet{Updatetheview,ifalreadyloaded。}}} 以上编程语言的代码语法高亮都支持得不错,后续可以考虑直接在头条上发博文了