benny! Posted October 1, 2013 Share Posted October 1, 2013 Hi, I have a general question. Refer to the following dummy code:var cvs, ctx;cvs = document.getElementById( "single_canvas" );ctx = cvs.getContext( "2d" );// Do some 2d drawing here.// ...// Never want to use 2d context from now on// Want to re-use canvas element but with 3d contentctx = cvs.getContext( "webgl" );// ctx is nullSo, is there a way to unlock/free a canvas context in order to re-initialize it again? Best,benny! Quote Link to comment Share on other sites More sharing options...
Chris Posted October 1, 2013 Share Posted October 1, 2013 Well, why don't you just destroy the canvas element and create a new one.I don't really know whats going on under the hood, but I can imagine that when you call getContext() the first time, the whole canvas element is prepared for either 2d or webgl rendering and hooked against the hardware as best as possible.They might as well change everything beneath the canvas tag you "see" there. So imho it will be AT LEAST as heavy for the browser to remove all context code and initialize a new context. Dumping the whole canvas element with everything related and initializing a new one + a new context from scratch won't make a big performance difference. You should pick that approach. Quote Link to comment Share on other sites More sharing options...
benny! Posted October 2, 2013 Author Share Posted October 2, 2013 Hey Chris, thanks for your answer. Actually thats what I am currently doing right now (using two separate canvas). I was just wondering if there is a general way - or at least some explanation about it. For me, it would feel natural to somehow release/destroy/unbind the context. Hmmmm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.