Jump to content

Unlock context


benny!
 Share

Recommended Posts

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 null

So, is there a way to unlock/free a canvas context in order to re-initialize it again?

 

Best,

benny!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...