Webgl's getAttribLocation oddly returns -1 - Stack Overflow
文章推薦指數: 80 %
How are layout qualifiers better than getAttribLocation in ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore Webgl'sgetAttribLocationoddlyreturns-1 AskQuestion Asked 10years,5monthsago Modified 10years,5monthsago Viewed 5ktimes 16 4 Ihavemanagedtoisolatetheprobleminthiscode: vargl; _main_web=function(){ gl=document.getElementById("canvas").getContext("experimental-webgl"); gl=WebGLDebugUtils.makeDebugContext(gl, function(err,funcName,args){ throw(WebGLDebugUtils.glEnumToString(err)+"wascausedbycallto"+funcName); } ); vert_shader=gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(vert_shader,"attributevec4vertex;attributevec2uv;voidmain(void){gl_Position=vertex;}\n"); gl.compileShader(vert_shader); if(!gl.getShaderParameter(vert_shader,gl.COMPILE_STATUS)){ throw0; } frag_shader=gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(frag_shader,"voidmain(void){gl_FragColor=vec4(1.0,1.0,1.0,1.0);}\n"); gl.compileShader(frag_shader); if(!gl.getShaderParameter(frag_shader,gl.COMPILE_STATUS)){ throw1; } program=gl.createProgram(); gl.attachShader(program,vert_shader); gl.attachShader(program,frag_shader); gl.linkProgram(program); if(!gl.getProgramParameter(program,gl.LINK_STATUS)){ throw2; } vertexLocation=gl.getAttribLocation(program,"vertex"); textureLocation=gl.getAttribLocation(program,"uv"); } vertexLocationisalright,itis0.ButtextureLocationis-1,whatamImissing? webgl Share Follow askedJan25,2012at18:39 AndréPuelAndréPuel 8,28388goldbadges4848silverbadges8282bronzebadges Addacomment | 1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 48 You'retryingtogetthelocationforanattributethatyoudeclarebutneveruse.Yourvertexshadercodeis(expandedforclarity): attributevec4vertex; attributevec2uv; voidmain(void){ gl_Position=vertex; } Duringthecompilationofyourshader"uv"willbeidentifiedasanunusedparameterandbestrippedout.Evenifyouassignittoavaryinginthisshaderbutdon'teveruseitinthefragmentshader,itmaystillbestrippedoutbecauseit'sbeenidentifiedasnotcontributingtothefinalfragment. Share Follow answeredJan25,2012at21:19 TojiToji 33.1k2121goldbadges103103silverbadges114114bronzebadges 1 1 Thispointhere:"Evenifyouassignittoavaryinginthisshaderbutdon'teveruseitinthefragmentshader,itmaystillbestrippedout"iswhathelpedmeintheend.Iknewthatunusedattributeswouldbestrippedaway,butIdidn'tknowthatitcouldcarryoverbetweenthevertexandfragmentshaders.Thanks! – aclave1 Nov17,2015at17:37 Addacomment | YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedwebgloraskyourownquestion. TheOverflowBlog HowStackOverflowislevelingupitsunittestinggame Developersvsthedifficultybomb(Ep.459) FeaturedonMeta Testingnewtrafficmanagementtool Duplicatedvotesarebeingcleanedup Trending:Anewanswersortingoption Updatedbuttonstylingforvotearrows:currentlyinA/Btesting Linked 3 dart:web_gl:getAttributeLocationreturns-1 Related 3 WebGL:glslattributesissue,getProgramParameterreturnswrongnumberofattributes 2 Trackballcontrolsbehavingoddly 0 c3dlgetPosition()returnsafloat32array,whatdoesitrepresent? 1 readPixelsfunctionreturnsnotmodifiedtexture 1 UsingclientWidth/clientHeightJavascriptwithwebglreturnsproblems 0 whygl.CURRENT_PROGRAMreturnsalwaysthesameshader? 1 webglgetUniformLocationreturns0 0 WebGLreadPixelsreturnsflippedyaxis HotNetworkQuestions WhatmightImakeaplayerrolliftheyaskaphysical,self-awarenessquestion? IsthereanATMbeforetheVOAdeskatBatamCenterharbor? HowdoInotatealternatingquicklybetweentwonotesanoctaveawayfromeachother? Arebriftersmeanttospin/slideonimpact,bythechoiceofalowattachment-bolttorque? Whatisthedifferencebetween\dotsmand\cdots? Ifnuclearweaponswereneverexistedorinvented,whatcouldreplaceit Bookaboutanoutcastgirlwhoteachesagroupofkidstofly Anequationwithinfinitenestedsquareroots Howcanyoumaptheprobabilityof2d6ontoastandardpokerdeck? Quantumsupercomputersinorbit? "if"statementsyntaxdifferencesbetweenCandC++ CRAZYEIGHTSpuzzle Cgenericdynamicarray(usingpreprocessor) Howtowriteanumberbymakingawhitespacebetweentwonumbers? ErverseHteIfrstWtoElttersfoAechOwrd Doesawatercloset(toiletstall)requireanelectricaloutlet? WhydoesIsCoinBase()checkifthereisexactlyoneinput? Problemmodellingasimpleshapeandthenapplyingsubdivisionsurfacemodifier Arethereanyclass-changingprefixesinEnglish? CanaU.S.statebringactionbeforetheSupremeCourtagainstanotherstateforequalrightsofitsowncitizenswhentheyvisittheotherstate? Whatisthemeaningof"reflecting"inthiscontext? HowdoIknowwhichweaponstokeepinBorderlands2? SecrecyinMathematics DoesanycomputerresemblethemodeltaughtinUKsecondaryeducation? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1WebGLRenderingContext.getAttribLocation() - Web APIs | MDN
The WebGLRenderingContext.getAttribLocation() method of the WebGL API returns the location of an ...
- 2WebGLRenderingContext.getAttribLocation - Javascript
getAttribLocation( program, name ) const buffer = gl.createBuffer() gl.bindBuffer( gl.ARRAY_BUFFE...
- 3WebGLRenderingContext.getAttribLocation() - Web APIs
The WebGLRenderingContext.getAttribLocation() method of the WebGL API returns the location of an ...
- 4使用attribute 變數
getAttribLocation(prog, 'position'); const gl_size = gl.getAttribLocation(prog, "size");. 由於頂點著色器...
- 5GL.GetAttribLocation Method (OpenTK.Graphics.ES20)
GetAttribLocation(UInt32, String). Important. This API is not CLS-compliant. C# 複製.