void XAudio2Player::Start() { // Get a couple of blocks ahead RenderBuffer(); RenderBuffer(); sourceVoice->Start(); }
RenderTargetPtr MultiRenderTarget::CreateTexture(const TargetParam& tp) { if (tp.useAsTexture) { RenderTexture* rt = NEX_NEW(RenderTexture()); rt->Create(TextureBase::TEXTURE_2D, tp.format, dimensions.width, dimensions.height, 1); return Assign(rt); } else { RenderBuffer* rt = NEX_NEW(RenderBuffer()); rt->Create(tp.format, dimensions.width, dimensions.height); return Assign(rt); } }
bool GL3FrameBufferProvider::attach_object(GLenum opengl_attachment, const Texture &texture, int level, int zoffset, GLuint texture_target) { int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment); // Check for object replacement bool is_replaced_object = false; if (!attached_renderbuffers[internal_attachment_offset].is_null()) { is_replaced_object = true; attached_renderbuffers[internal_attachment_offset] = RenderBuffer(); } if (!attached_textures[internal_attachment_offset].is_null()) { is_replaced_object = true; attached_textures[internal_attachment_offset] = Texture2D(); } // Store the texture attached_textures[internal_attachment_offset] = texture; // Bind the renderbuffer GL3TextureProvider *gl_texture_provider = dynamic_cast<GL3TextureProvider*>(texture.get_provider()); if (!gl_texture_provider) throw Exception("Invalid texture"); GLuint texture_type = gl_texture_provider->get_texture_type(); GLuint texture_handle = gl_texture_provider->get_handle(); GLenum target = GL_DRAW_FRAMEBUFFER; if (bind_target == framebuffer_read) target = GL_READ_FRAMEBUFFER; if (!texture_target) texture_target = texture_type; if (texture_type == GL_TEXTURE_1D) { glFramebufferTexture1D(target, opengl_attachment, texture_target, texture_handle, level); } else if (texture_type == GL_TEXTURE_2D) { glFramebufferTexture2D(target, opengl_attachment, texture_target, texture_handle, level); } else if (texture_type == GL_TEXTURE_3D) { glFramebufferTexture3D(target, opengl_attachment, texture_target, texture_handle, level, zoffset); } else if (texture_type == GL_TEXTURE_2D_ARRAY || texture_type == GL_TEXTURE_1D_ARRAY) { glFramebufferTextureLayer(target, opengl_attachment, texture_handle, level, zoffset); } return is_replaced_object; }
void CVisualizerScope::Draw() { #ifdef _DEBUG static int _peak = 0; static int _min = 0; static int _max = 0; #endif const int TIME_SCALING = 7; static int LastPos = 0; static int Accum = 0; for (unsigned int i = 0; i < m_iSampleCount; ++i) { #ifdef _DEBUG if (_min > m_pSamples[i]) _min = m_pSamples[i]; if (_max < m_pSamples[i]) _max = m_pSamples[i]; if (abs(m_pSamples[i]) > _peak) _peak = abs(m_pSamples[i]); #endif int Pos = m_iWindowBufPtr++ / TIME_SCALING; Accum += m_pSamples[i]; if (Pos != LastPos) { m_pWindowBuf[LastPos] = Accum / TIME_SCALING; Accum = 0; } LastPos = Pos; if (Pos == m_iWidth) { m_iWindowBufPtr = 0; LastPos = 0; RenderBuffer(); } } #ifdef _DEBUG _peak = _max - _min; m_iPeak = _peak; _peak = 0; _min = 0; _max = 0; #endif }
void CVisualizerScope::Draw() { #ifdef _DEBUG int min_ = 0; // // // int max_ = 0; #endif const int TIME_SCALING = 7; static int LastPos = 0; static int Accum = 0; for (auto sample : m_pSamples) { // // // #ifdef _DEBUG if (min_ > sample) min_ = sample; if (max_ < sample) max_ = sample; #endif int Pos = m_iWindowBufPtr++ / TIME_SCALING; Accum += sample; if (Pos != LastPos) { m_pWindowBuf[LastPos] = Accum / TIME_SCALING; Accum = 0; } LastPos = Pos; if (Pos == m_iWidth) { m_iWindowBufPtr = 0; LastPos = 0; RenderBuffer(); } } #ifdef _DEBUG m_iPeak = max_ - min_; // // // #endif }
void GL3FrameBufferProvider::on_dispose() { if (handle) { OpenGL::set_active(gc_provider); glDeleteFramebuffers(1, &handle); handle = 0; } // Detach all textures and renderbuffers for (int cnt = 0; cnt < num_attachment_offsets; cnt++) { if (!attached_textures[cnt].is_null()) attached_textures[cnt] = Texture2D(); if (!attached_renderbuffers[cnt].is_null()) attached_renderbuffers[cnt] = RenderBuffer(); } gc_provider->remove_disposable(this); }
void GL3FrameBufferProvider::detach_object(GLenum opengl_attachment) { int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment); GLenum target = GL_DRAW_FRAMEBUFFER; if (bind_target == framebuffer_read) target = GL_READ_FRAMEBUFFER; if (!attached_renderbuffers[internal_attachment_offset].is_null()) { glFramebufferRenderbuffer(target, opengl_attachment, GL_RENDERBUFFER, 0); attached_renderbuffers[internal_attachment_offset] = RenderBuffer(); } if (!attached_textures[internal_attachment_offset].is_null()) { GL3TextureProvider *gl_texture_provider = dynamic_cast<GL3TextureProvider*>(attached_textures[internal_attachment_offset].get_provider()); GLuint texture_type = gl_texture_provider->get_texture_type(); if (texture_type == GL_TEXTURE_1D) { glFramebufferTexture1D(target, opengl_attachment, texture_type, 0, 0); } else if (texture_type == GL_TEXTURE_2D) { glFramebufferTexture2D(target, opengl_attachment, texture_type, 0, 0); } else if (texture_type == GL_TEXTURE_3D) { glFramebufferTexture3D(target, opengl_attachment, texture_type, 0, 0, 0); } else if (texture_type == GL_TEXTURE_2D_ARRAY || texture_type == GL_TEXTURE_1D_ARRAY) { glFramebufferTextureLayer(target, opengl_attachment, 0, 0, 0); } attached_textures[internal_attachment_offset] = Texture(); } }
bool GL3FrameBufferProvider::attach_object(GLenum opengl_attachment, const RenderBuffer &render_buffer) { int internal_attachment_offset = decode_internal_attachment_offset(opengl_attachment); // Check for object replacement bool is_replaced_object = false; if (!attached_renderbuffers[internal_attachment_offset].is_null()) { is_replaced_object = true; attached_renderbuffers[internal_attachment_offset] = RenderBuffer(); } if (!attached_textures[internal_attachment_offset].is_null()) { is_replaced_object = true; attached_textures[internal_attachment_offset] = Texture2D(); } // Store the renderbuffer attached_renderbuffers[internal_attachment_offset] = render_buffer; // Bind the renderbuffer GL3RenderBufferProvider *gl_render_buffer = static_cast<GL3RenderBufferProvider *>(render_buffer.get_provider()); if (!gl_render_buffer) throw Exception("Invalid render buffer"); FrameBufferStateTracker tracker_draw(bind_target, handle, gc_provider); GLenum target = GL_DRAW_FRAMEBUFFER; if (bind_target == framebuffer_read) target = GL_READ_FRAMEBUFFER; GLuint render_buffer_handle = gl_render_buffer->get_handle(); glFramebufferRenderbuffer(target, opengl_attachment, GL_RENDERBUFFER, render_buffer_handle); return is_replaced_object; }
void ModelClass::Render(ID3D11DeviceContext* devCon) { RenderBuffer(devCon); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wndClass = { 0 }; wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.hInstance = hInstance; wndClass.hIcon = NULL; wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = WINDOW_NAME; wndClass.lpszClassName = WINDOW_NAME; if (!RegisterClassEx(&wndClass)) { MessageBox(NULL, "This program requires Windows NT!", WINDOW_NAME, MB_ICONERROR); return 0; } HWND hwnd = CreateWindow( WINDOW_NAME, //window class name WINDOW_NAME, //window caption WS_OVERLAPPEDWINDOW, //window style CW_USEDEFAULT, //initial x position CW_USEDEFAULT, //initial y position WINDOW_SIZE_X, //initial x size WINDOW_SIZE_Y, //initial y size NULL, //parent window handle NULL, //window menu handle hInstance, //program instance handle NULL); //creation parameters if (!hwnd) { MessageBox(NULL, "Failed to create window!", WINDOW_NAME, MB_ICONERROR); return 0; } ShowWindow(hwnd, nCmdShow); PIXELCOLOR* buffer = new PIXELCOLOR[WINDOW_SIZE_X * WINDOW_SIZE_Y]; for (int i = 0; i < WINDOW_SIZE_X * WINDOW_SIZE_Y; ++i) { buffer[i].r = 255; buffer[i].g = 0; if (i % 10 == 0) buffer[i].b = 0; else buffer[i].b = 255; } MSG msg = { 0 }; while (msg.message != WM_QUIT) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { HDC hdc; hdc = GetDC(hwnd); auto timeStart = GetTickCount(); RenderBuffer(hdc, buffer, WINDOW_SIZE_X, WINDOW_SIZE_Y); auto timeEnd = GetTickCount(); auto dtime = 1000 / (timeEnd - timeStart + 1); char a[30]; int len = sprintf_s(a, "%d", dtime); TextOut(hdc, 0, 0, a, len); ReleaseDC(hwnd, hdc); } } delete[] buffer; return msg.wParam; }
void AxisModelClass::Render( ID3D11DeviceContext* deviceContext ) { RenderBuffer( deviceContext ); }
void STDMETHODCALLTYPE XAudio2Player::OnBufferStart(void* pBufferContext) { RenderBuffer(); }