I have a question, how can I empty a buffer?
for example, I store a word in a buffer, the buffer size is 50
then I wanna keep this buffer, but I want it to be empty, how to erase everything in the buff?
Just store 0 over the whole size of the buffer.
Related
UMat frame,gray;
VideoCapture cap(0);
if(!cap.isOpened())
return -1;
for(i=0;i<10;i++)
{
cap >> frame;
Canny(frame, frame, 0, 50);
imshow("canny", frame);
}
return 0;
here my doubt is that if the loop is running for 10 times and in
line-11 I am applying the canny filter, but the src and dst are same(frame) so it will be inplace operation, so at each iteration what will happen in case of the memory
allocations and deallocation!!
will there will 9 memory locations with no header pointing to it,
or in every loop the memory occupied by frame matrix data will be
deallocated,
or in every loop i have to call release(), to manually deallocate the
matrix
when the canny filter is applied will the result data replace the old matrix data, or it will allocate a new set of memory for the result data and pointing to it, and if so what will happen to the old matrix data?
The following line:
UMat frame
does not allocate any significant image memory. It just creates a header on the stack with space for:
the number of rows,
and columns in the image,
the image type,
a reference count, and
a pointer that will eventually point to the image's pixels, but for the moment points to nothing.
On entry to the loop, the following line:
cap >> frame;
will allocate sufficient memory on the heap for the image's pixels, and initialise the dimensions, the reference count and make the data pointer point to the allocated chunk of image memory - obviously it will also fill the pixel-data from the video source.
When you call Canny with:
Canny(frame, frame, 0, 50);
it will see that the operation is in-place and re-use the same Mat that contains frame and over-write it. No allocation, nor releasing is necessary.
The second, and subsequent, times you go around the loop, the line:
cap >> frame;
will see that there is already sufficient space allocated and load the data from the video stream into the same Mat, thereby over-writing the results of the previous Canny().
When you return from the function at the end, the heap memory for the pixel data is released and the stack memory for the header is given up.
TLDR; There is nothing to worry about - memory allocation and releasing are taken care of for you!
void D3DApp::OnResize()
{
assert(md3dImmediateContext);
assert(md3dDevice);
assert(mSwapChain);
// Release the old views, as they hold references to the buffers we
// will be destroying. Also release the old depth/stencil buffer.
ReleaseCOM(mRenderTargetView);
ReleaseCOM(mDepthStencilView);
ReleaseCOM(mDepthStencilBuffer);
// Resize the swap chain and recreate the render target view.
HR(mSwapChain->ResizeBuffers(1, mClientWidth, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
ID3D11Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCOM(backBuffer);
I am having a bit of trouble understanding exactly what this code is actually doing. I think it is getting the current back buffer storing the buffer in memory and then rendering it to the screen again? What could be in the contents of the buffer that is gotten? I am very confused. My program is using an 800 x 600 pixel window.
As the function name point out, it just Reset the backbuffer and the rendertarget, and this function should be called whenever a render window is resized.
HR(mSwapChain->ResizeBuffers(1, mClientWidth, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
In an DirectX application, we always set the backbuffer size same as the window size, so when the window size changed, we should update the backbuffer size accordingly, otherwise your scene will be stretched.
ID3D11Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCOM(backBuffer);
The render target was based on the backbuffer which in turn should be updated.
Is it possible to create a VBO and reuse it between calls to glDrawElements in the same rendering cycle? (I tried and obtained weird results). The example below is missing bindings, etc.
Init code (executed only once) *:*
glGenBuffers(...)
glBufferData(...)
Render frame code (executed for each frame):
glMapBufferOES(...)
//... Update buffer from index 0 to X
glDrawElements(...)
//... Update buffer from index 0 to Y
glDrawElements(...)
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
You need to unmap your buffer before drawing with it. If you don't unmap, that's probably why you're seeing weird results with glDrawElements.
http://www.opengl.org/sdk/docs/man/xhtml/glMapBuffer.xml
After glDrawElements is called, you can remap your buffer and fill it in again.
You will probably get better performance by not reusing the buffer right away. Remapping right after the draw will probably block until the draw is completed.
I am trying to get the current pixel in an image by a "OnMouseMove event" Using Scanline.
something equivalent to this:
Label1.Caption := IntToStr(Image1.Picture.Bitmap.Canvas.Pixels[X,Y]);
Any ideas ?
ScanLine returns a pointer to a packed array of pixels that constitutes one line of a bitmap. Using this pointer you can access these pixels fast.
ScanLine can't help if you need only one pixel.
Still you can use ScanLine here; assuming bitmap pixel format pf32bit:
Label1.Caption:= IntToStr(PIntegerArray(Image1.Picture.Bitmap.ScanLine[Y])^[X]);
Scanlines are useful for quickly scanning the entire line, like in your other post. But if you want to get an arbitrary single pixel, the best way to do it is to use the code you've already got.
I am trying to cut a mesh in half or at least be able to delete faces from it in real-time.
How to go about doing this i wonder?
Lock the vertex buffers, memset the selected face or vertex to 0, does not work for me.
has anyone a solution or a tutorial on this i really want this feature in my program!
Cheers
Oh - that one is easy. There is no need to modify the mesh. D3D can already do this for you!
Set the clip-plane via IDirect3DDevice9::SetClipPlane, then enable the plane via the D3DRS_CLIPPLANEENABLE renderstate. You can even set multiple clip-planes at the same time if you want to..
Here is a link to the msdn-entry: http://doc.51windows.net/Directx9_SDK/?url=/directx9_sdk/graphics/reference/d3d/interfaces/idirect3ddevice9/setclipplane.htm
And if you do a google search on "D3D SetClipPlane" you will find lots of discussions and example codes how to use it.
If you need to dynamically delete triangles from a mesh the best/fastest way is to use indexed triangles. When you create the index buffer, use the 'D3DUSAGE_DYNAMIC' flag. When you want to delete triangles, lock it with the 'D3DLOCK_DISCARD' flag. Write the entire new list of indices into the buffer, leaving out the triangles you want to delete.
The index buffer will be much smaller than the vertex buffer, so re-uploading only indices won't be as much of a drag on the system as the vertex buffer would be. But if it would be a big problem for you to convert to indexed triangle lists, then doing these stame operations using the vertex buffer instead is probably your next best option.
You say that setting the vertex to 0 doesn't work. In what way doesn't it work?
If you set the position of all the verticies of a triangle to (0.0, 0.0, 0.0) then the resulting triangle will be of zero size and shouldn't be drawn. Just to be sure you could set it to an offscreen position instead of zero.