//----------------------------------------------------------------------------// OpenGLWGLPBTextureTarget::OpenGLWGLPBTextureTarget(OpenGLRendererBase& owner) : OpenGLTextureTarget(owner), d_pixfmt(0), d_pbuffer(0), d_context(0), d_hdc(0), d_prevContext(0), d_prevDC(0) { if (!WGLEW_ARB_pbuffer) CEGUI_THROW(RendererException("WGL_ARB_pbuffer extension is needed to " "use OpenGLWGLPBTextureTarget!")); HDC hdc = wglGetCurrentDC(); uint fmtcnt; wglChoosePixelFormatARB(hdc, pbAttrs, 0, 1, &d_pixfmt, &fmtcnt); if (!fmtcnt) CEGUI_THROW(RendererException( "pbuff creation failure, no suitable pixel formats.")); initialiseTexture(); // set default size (and cause initialisation of the pbuffer) declareRenderSize(Sizef(DEFAULT_SIZE, DEFAULT_SIZE)); }
//----------------------------------------------------------------------------// void NullTexture::loadFromFile(const String& filename, const String& resourceGroup) { // get and check existence of CEGUI::System object System* sys = System::getSingletonPtr(); if (!sys) CEGUI_THROW(RendererException( "CEGUI::System object has not been created!")); // load file to memory via resource provider RawDataContainer texFile; sys->getResourceProvider()->loadRawDataContainer(filename, texFile, resourceGroup); Texture* res = sys->getImageCodec().load(texFile, this); // unload file data buffer sys->getResourceProvider()->unloadRawDataContainer(texFile); // throw exception if data was load loaded to texture. if (!res) CEGUI_THROW(RendererException( sys->getImageCodec().getIdentifierString() + " failed to load image '" + filename + "'.")); }
//----------------------------------------------------------------------------// GLint OpenGLTexture::internalFormat() const { if (OpenGLInfo::getSingleton().isSizedInternalFormatSupported()) { const char* err = "Invalid or unsupported OpenGL pixel format."; switch (d_format) { case GL_RGBA: switch (d_subpixelFormat) { case GL_UNSIGNED_BYTE: return GL_RGBA8; case GL_UNSIGNED_SHORT_4_4_4_4: return GL_RGBA4; default: throw RendererException(err); } case GL_RGB: switch (d_subpixelFormat) { case GL_UNSIGNED_BYTE: return GL_RGB8; case GL_UNSIGNED_SHORT_5_6_5: return GL_RGB565; default: throw RendererException(err); } default: throw RendererException(err); } } else return d_format; }
//----------------------------------------------------------------------------// void OpenGLTexture::loadFromFile(const String& filename, const String& resourceGroup) { // Note from PDT: // There is somewhat tight coupling here between OpenGLTexture and the // ImageCodec classes - we have intimate knowledge of how they are // implemented and that knowledge is relied upon in an unhealthy way; this // should be addressed at some stage. // load file to memory via resource provider RawDataContainer texFile; System::getSingleton().getResourceProvider()-> loadRawDataContainer(filename, texFile, resourceGroup); // get and check existence of CEGUI::System (needed to access ImageCodec) System* sys = System::getSingletonPtr(); if (!sys) CEGUI_THROW(RendererException("OpenGLTexture::loadFromFile - " "CEGUI::System object has not been created: " "unable to access ImageCodec.")); Texture* res = sys->getImageCodec().load(texFile, this); // unload file data buffer System::getSingleton().getResourceProvider()-> unloadRawDataContainer(texFile); if (!res) // It's an error CEGUI_THROW(RendererException("OpenGLTexture::loadFromFile - " + sys->getImageCodec().getIdentifierString() + " failed to load image '" + filename + "'.")); }
//----------------------------------------------------------------------------// void DirectFBTexture::loadFromMemory(const void* buffer, const Sizef& buffer_size, PixelFormat pixel_format) { if (!isPixelFormatSupported(pixel_format)) CEGUI_THROW(InvalidRequestException( "Data was supplied in an unsupported pixel format.")); cleanupDirectFBTexture(); DFBSurfaceDescription desc; desc.flags = static_cast<DFBSurfaceDescriptionFlags> (DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); desc.width = buffer_size.d_width; desc.height = buffer_size.d_height; desc.pixelformat = DSPF_ARGB; if (d_directfb.CreateSurface(&d_directfb, &desc, &d_texture)) CEGUI_THROW(RendererException("Failed to create surface.")); char* dest; int pitch; if(d_texture->Lock(d_texture, DSLF_WRITE, reinterpret_cast<void**>(&dest), &pitch)) { d_texture->Release(d_texture); d_texture = 0; CEGUI_THROW(RendererException("Directfb::Lock failed.")); } // Copy data in. const size_t pix_sz = (pixel_format == PF_RGB) ? 3 : 4; const char* src = static_cast<const char*>(buffer); for (int i = 0; i < buffer_size.d_height; ++i) { for (int j = 0; j < buffer_size.d_width; ++j) { dest[j * 4 + 0] = src[j * pix_sz + 2]; dest[j * 4 + 1] = src[j * pix_sz + 1]; dest[j * 4 + 2] = src[j * pix_sz + 0]; dest[j * 4 + 3] = (pix_sz == 3) ? 0xFF : src[j * pix_sz + 3]; } dest += pitch; src += static_cast<size_t>(buffer_size.d_width) * pix_sz; } d_texture->Unlock(d_texture); // update size and scaling info int rw, rh; d_texture->GetSize(d_texture, &rw, &rh); d_size.d_width = static_cast<float>(rw); d_size.d_height = static_cast<float>(rh); d_dataSize = buffer_size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLApplePBTextureTarget::declareRenderSize(const Size& sz) { // exit if current size is enough if ((d_area.getWidth() >= sz.d_width) && (d_area.getHeight() >= sz.d_height)) return; setArea(Rect(d_area.getPosition(), d_owner.getAdjustedTextureSize(sz))); // dump any previous pbuffer if (d_pbuffer) { CGLDestroyPBuffer(d_pbuffer); d_pbuffer = 0; } CGLError err; if (err = CGLCreatePBuffer(d_area.getWidth(), d_area.getHeight(), GL_TEXTURE_2D, GL_RGBA, 0, &d_pbuffer)) { CEGUI_THROW(RendererException( "OpenGLApplePBTextureTarget::declareRenderSize " "- CGLCreatePBuffer failed: " + String(CGLErrorString(err)))); } if (err = CGLSetPBuffer(d_context, d_pbuffer, 0, 0, d_screen)) CEGUI_THROW(RendererException( "OpenGLApplePBTextureTarget::declareRenderSize " "- CGLSetPBuffer failed: " + String(CGLErrorString(err)))); clear(); // make d_texture use the pbuffer as it's data source // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); glBindTexture(GL_TEXTURE_2D, d_texture); err = CGLTexImagePBuffer(CGLGetCurrentContext(), d_pbuffer, GL_FRONT); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); if (err) CEGUI_THROW(RendererException( "OpenGLApplePBTextureTarget::declareRenderSize " "- CGLTexImagePBuffer failed: " + String(CGLErrorString(err)))); // ensure CEGUI::Texture is wrapping real GL texture and has correct size d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize()); }
//----------------------------------------------------------------------------// void OpenGLWGLPBTextureTarget::initialisePBuffer() { int creation_attrs[] = { WGL_PBUFFER_LARGEST_ARB, true, 0 }; releasePBuffer(); HDC hdc = wglGetCurrentDC(); d_pbuffer = wglCreatePbufferARB(hdc, d_pixfmt, static_cast<int>(d_area.getWidth()), static_cast<int>(d_area.getHeight()), creation_attrs); if (!d_pbuffer) CEGUI_THROW(RendererException( "OpenGLWGLPBTextureTarget::initialisePBuffer - " "pbuffer creation failure, wglCreatePbufferARB() call failed.")); d_hdc = wglGetPbufferDCARB(d_pbuffer); if (!d_hdc) CEGUI_THROW(RendererException( "OpenGLWGLPBTextureTarget::initialisePBuffer - " "pbuffer creation failure, wglGetPbufferDCARB() call failed.")); d_context= wglCreateContext(d_hdc); if (!d_hdc) CEGUI_THROW(RendererException( "OpenGLWGLPBTextureTarget::initialisePBuffer - " "pbuffer creation failure, wglCreateContext() call failed.")); if(!wglShareLists(wglGetCurrentContext(), d_context)) CEGUI_THROW(RendererException( "OpenGLWGLPBTextureTarget::initialisePBuffer - " "pbuffer creation failure, wglShareLists() call failed.")); // extract the actual size of the created bufer int actual_width, actual_height; wglQueryPbufferARB(d_pbuffer, WGL_PBUFFER_WIDTH_ARB, &actual_width); wglQueryPbufferARB(d_pbuffer, WGL_PBUFFER_HEIGHT_ARB, &actual_height); d_area.setSize(Size(static_cast<float>(actual_width), static_cast<float>(actual_height))); // ensure CEGUI::Texture is wrapping real GL texture and has correct size d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize()); }
//----------------------------------------------------------------------------// void OpenGLGLXPBTextureTarget::initialisePBuffer() { int creation_attrs[] = { GLX_PBUFFER_WIDTH, d_area.getWidth(), GLX_PBUFFER_HEIGHT, d_area.getHeight(), GLX_LARGEST_PBUFFER, True, GLX_PRESERVED_CONTENTS, True, None }; // release any existing pbuffer if (d_pbuffer) glXDestroyPbuffer(d_dpy, d_pbuffer); d_pbuffer = glXCreatePbuffer(d_dpy, d_fbconfig, creation_attrs); if (!d_pbuffer) throw RendererException("OpenGLGLXPBTextureTarget::initialisePBuffer - " "pbuffer creation error: glXCreatePbuffer() failed"); // get the real size of the buffer that was created GLuint actual_width, actual_height; glXQueryDrawable(d_dpy, d_pbuffer, GLX_WIDTH, &actual_width); glXQueryDrawable(d_dpy, d_pbuffer, GLX_HEIGHT, &actual_height); d_area.setSize(Size(actual_width, actual_height)); // ensure CEGUI::Texture is wrapping real GL texture and has correct size d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize()); }
//----------------------------------------------------------------------------// void OpenGLTexture::setTextureSize(const Size& sz) { const Size size(d_owner.getAdjustedTextureSize(sz)); // make sure size is within boundaries GLfloat maxSize; glGetFloatv(GL_MAX_TEXTURE_SIZE, &maxSize); if ((size.d_width > maxSize) || (size.d_height > maxSize)) CEGUI_THROW(RendererException( "OpenGLTexture::setTextureSize: size too big")); // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // set texture to required size glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, static_cast<GLsizei>(size.d_width), static_cast<GLsizei>(size.d_height), 0, GL_RGBA , GL_UNSIGNED_BYTE, 0); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); d_dataSize = d_size = size; updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void Direct3D9Texture::loadFromMemory(const void* buffer, const Sizef& buffer_size, PixelFormat pixel_format) { if (!isPixelFormatSupported(pixel_format)) CEGUI_THROW(InvalidRequestException( "Data was supplied in an unsupported pixel format.")); const D3DFORMAT pixfmt = toD3DPixelFormat(pixel_format); createDirect3D9Texture(buffer_size, pixfmt); LPDIRECT3DSURFACE9 surface = getTextureSurface(); const PixelBuffer pixel_buffer(buffer, buffer_size, pixel_format); const RECT src_rect = { 0, 0, static_cast<LONG>(buffer_size.d_width), static_cast<LONG>(buffer_size.d_height) }; HRESULT hr = D3DXLoadSurfaceFromMemory( surface, 0, 0, pixel_buffer.getPixelDataPtr(), pixfmt == D3DFMT_X8R8G8B8 ? D3DFMT_R8G8B8 : pixfmt, pixel_buffer.getPitch(), 0, &src_rect, D3DX_FILTER_NONE, 0); surface->Release(); if (FAILED(hr)) CEGUI_THROW(RendererException( "D3DXLoadSurfaceFromMemory failed.")); }
//----------------------------------------------------------------------------// Direct3D11Texture::Direct3D11Texture(IDevice11& device, const Size& sz) : d_device(device), d_texture(0), d_resourceView(0), d_size(0, 0), d_dataSize(0, 0), d_texelScaling(0, 0) { D3D11_TEXTURE2D_DESC tex_desc; ZeroMemory(&tex_desc, sizeof(tex_desc)); tex_desc.Width = static_cast<UINT>(sz.d_width); tex_desc.Height = static_cast<UINT>(sz.d_height); tex_desc.ArraySize = 1; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; tex_desc.Usage = D3D11_USAGE_DEFAULT; tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; tex_desc.CPUAccessFlags = 0; tex_desc.MiscFlags = 0; tex_desc.MipLevels = 1; if (FAILED(d_device.d_device->CreateTexture2D(&tex_desc, 0, &d_texture))) CEGUI_THROW(RendererException( "Direct3D11Texture: Failed to create texture with specified size.")); initialiseShaderResourceView(); d_dataSize = sz; updateTextureSize(); updateCachedScaleValues(); }
void OgreGeometryBuffer::setVertexBuffer(size_t count) const { // We first check if some other buffer has already allocated a suited buffer // for us Ogre::HardwareVertexBufferSharedPtr already_created = d_owner.getVertexBuffer(count); if (!already_created.isNull()) { d_hwBuffer = already_created; } else { // Create the a new vertex buffer d_hwBuffer = Ogre::HardwareBufferManager::getSingleton(). createVertexBuffer(getVertexAttributeElementCount()*sizeof(float), count, Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false); } if (d_hwBuffer.isNull()) { throw RendererException("Failed to create Ogre vertex buffer, " "probably because the vertex layout is invalid."); } // bind the vertex buffer for rendering d_renderOp.vertexData->vertexBufferBinding->setBinding(0, d_hwBuffer); }
//----------------------------------------------------------------------------// void OpenGLESTexture::setTextureSize_impl(const Sizef& sz) { const Sizef size(d_owner.getAdjustedTextureSize(sz)); if (!d_isCompressed) { // make sure size is within boundaries GLfloat maxSize = static_cast<GLfloat>(d_owner.getMaxTextureSize()); if ((size.d_width > maxSize) || (size.d_height > maxSize)) CEGUI_THROW(RendererException("size too big")); // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // set texture to required size glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(size.d_width), static_cast<GLsizei>(size.d_height), 0, d_format , d_subpixelFormat, 0); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); } d_size = size; }
/************************************************************************* Direct3D support method that must be called after a Reset call on the Direct3DDevice. *************************************************************************/ void DirectX9Renderer::postD3DReset(void) { // Recreate a vertex buffer if (FAILED(d_device->CreateVertexBuffer((VERTEXBUFFER_CAPACITY * sizeof(QuadVertex)), D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, VERTEX_FVF, D3DPOOL_DEFAULT, &d_buffer, 0))) { throw RendererException("DirectX9Renderer::postD3DReset - Failed to " "create the VertexBuffer for use by the " "DirectX9Renderer object."); } // perform post-reset operations on all textures std::list<DirectX9Texture*>::iterator ctex = d_texturelist.begin(); std::list<DirectX9Texture*>::iterator endtex = d_texturelist.end(); for (; ctex != endtex; ++ctex) { (*ctex)->postD3DReset(); } // update display size setDisplaySize(getViewportSize()); // Now we've come back, we MUST ensure a full redraw is done since the // textures in the stored quads will have been invalidated. System::getSingleton().signalRedraw(); }
//----------------------------------------------------------------------------// void OpenGLTexture::loadFromFile(const String& filename, const String& resourceGroup) { // Note from PDT: // There is somewhat tight coupling here between OpenGLTexture and the // ImageCodec classes - we have intimate knowledge of how they are // implemented and that knowledge is relied upon in an unhealthy way; this // should be addressed at some stage. // load file to memory via resource provider RawDataContainer texFile; CEGUI::System& system = System::getSingleton(); system.getResourceProvider()-> loadRawDataContainer(filename, texFile, resourceGroup); Texture* res = system.getImageCodec().load(texFile, this); // unload file data buffer System::getSingleton().getResourceProvider()-> unloadRawDataContainer(texFile); if (!res) // It's an error throw RendererException( system.getImageCodec().getIdentifierString() + " failed to load image '" + filename + "'."); }
//----------------------------------------------------------------------------// void Direct3D11Texture::loadFromMemory(const void* buffer, const Size& buffer_size, PixelFormat pixel_format) { cleanupDirect3D11Texture(); const void* img_src = buffer; if (pixel_format == PF_RGB) { const char* src = static_cast<const char*>(buffer); char* dest = new char[buffer_size.d_width * buffer_size.d_height * 4]; for (int i = 0; i < buffer_size.d_width * buffer_size.d_height; ++i) { dest[i * 4 + 0] = src[i * 3 + 0]; dest[i * 4 + 1] = src[i * 3 + 1]; dest[i * 4 + 2] = src[i * 3 + 2]; dest[i * 4 + 3] = 0xFF; } img_src = dest; } D3D11_TEXTURE2D_DESC tex_desc; ZeroMemory(&tex_desc, sizeof(tex_desc)); tex_desc.Width = static_cast<UINT>(buffer_size.d_width); tex_desc.Height = static_cast<UINT>(buffer_size.d_height); tex_desc.ArraySize = 1; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; tex_desc.Usage = D3D11_USAGE_DEFAULT; tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; tex_desc.CPUAccessFlags = 0; tex_desc.MiscFlags = 0; tex_desc.MipLevels = 1; D3D11_SUBRESOURCE_DATA data; ZeroMemory(&data, sizeof(D3D11_SUBRESOURCE_DATA)); data.pSysMem = img_src; data.SysMemPitch = 4 * tex_desc.Width; HRESULT hr = d_device.d_device->CreateTexture2D(&tex_desc, &data, &d_texture); if (pixel_format == PF_RGB) delete[] img_src; if (FAILED(hr)) CEGUI_THROW(RendererException( "Direct3D11Texture::loadFromMemory: Failed to " "create texture from memory buffer.")); initialiseShaderResourceView(); d_dataSize = buffer_size; updateTextureSize(); updateCachedScaleValues(); }
//----------------------------------------------------------------------------// void OpenGLGLXPBTextureTarget::createContext() { d_context = glXCreateNewContext(d_dpy, d_fbconfig, GLX_RGBA_TYPE, glXGetCurrentContext(), true); if (!d_context) throw RendererException("OpenGLGLXPBTextureTarget::createContext - " "Failed to create GLX context for pbuffer."); }
//----------------------------------------------------------------------------// void OpenGL1Texture::initInternalPixelFormatFields(const PixelFormat fmt) { d_isCompressed = false; switch(fmt) { case PF_RGBA: d_format = GL_RGBA; d_subpixelFormat = GL_UNSIGNED_BYTE; break; case PF_RGB: d_format = GL_RGB; d_subpixelFormat = GL_UNSIGNED_BYTE; break; case PF_RGB_565: d_format = GL_RGB; d_subpixelFormat = GL_UNSIGNED_SHORT_5_6_5; break; case PF_RGBA_4444: d_format = GL_RGBA; d_subpixelFormat = GL_UNSIGNED_SHORT_4_4_4_4; break; case PF_RGB_DXT1: d_format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; d_subpixelFormat = GL_UNSIGNED_BYTE; // not used. d_isCompressed = true; break; case PF_RGBA_DXT1: d_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; d_subpixelFormat = GL_UNSIGNED_BYTE; // not used. d_isCompressed = true; break; case PF_RGBA_DXT3: d_format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; d_subpixelFormat = GL_UNSIGNED_BYTE; // not used. d_isCompressed = true; break; case PF_RGBA_DXT5: d_format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; d_subpixelFormat = GL_UNSIGNED_BYTE; // not used. d_isCompressed = true; break; default: throw RendererException( "invalid or unsupported CEGUI::PixelFormat."); } }
//----------------------------------------------------------------------------// IDirect3DSurface9* Direct3D9Texture::getTextureSurface() const { LPDIRECT3DSURFACE9 surface; HRESULT hr = d_texture->GetSurfaceLevel(0, &surface); if (FAILED(hr)) CEGUI_THROW(RendererException( "IDirect3DTexture9::GetSurfaceLevel failed.")); return surface; }
//----------------------------------------------------------------------------// Size Direct3D9Renderer::getViewportSize() { D3DVIEWPORT9 vp; if (FAILED(d_device->GetViewport(&vp))) throw RendererException("Direct3D9Renderer::getViewportSize - Unable " "to access required view port information from " "Direct3DDevice9."); else return Size(static_cast<float>(vp.Width), static_cast<float>(vp.Height)); }
//----------------------------------------------------------------------------// void OpenGLGLXPBTextureTarget::selectFBConfig() { int cfgcnt; GLXFBConfig* glxcfgs; glxcfgs = glXChooseFBConfig(d_dpy, DefaultScreen(d_dpy), pbAttrs, &cfgcnt); if (!glxcfgs) CEGUI_THROW(RendererException( "pbuffer creation failure, can't get suitable configuration.")); d_fbconfig = glxcfgs[0]; }
//----------------------------------------------------------------------------// void Direct3D11GeometryBuffer::allocateVertexBuffer(const size_t count) const { D3D11_BUFFER_DESC buffer_desc; buffer_desc.Usage = D3D11_USAGE_DYNAMIC; buffer_desc.ByteWidth = count * sizeof(D3DVertex); buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; buffer_desc.MiscFlags = 0; if (FAILED(d_device.d_device->CreateBuffer(&buffer_desc, 0, &d_vertexBuffer))) CEGUI_THROW(RendererException("failed to allocate vertex buffer.")); d_bufferSize = count; }
// See method declaration for details. void DrawPrimitivesTaskList::GenerateDrawPrimitivesTasks(const utility::RenderPrimitiveList& render_primitives, TexHandleToTexContext& textures) { for(auto i = render_primitives.cbegin(); i != render_primitives.cend(); ++i) { switch((*i)->GetType()) { case utility::RenderPrimitive::TEXTURED_QUAD: GenerateDrawPrimitivesTask(*static_cast<const utility::TexturedQuad* const>(*i), textures); break; default: throw RendererException("avl::view::d3d::DrawPrimitivesTaskList::GenerateDrawPrimitivesTasks() -- Unable to render unsupported RenderPrimitive type."); } } }
//----------------------------------------------------------------------------// void GLES2Texture::setTextureSize_impl(const Sizef& sz) { const Sizef size(d_owner.getAdjustedTextureSize(sz)); d_size = size; // make sure size is within boundaries GLfloat maxSize; glGetFloatv(GL_MAX_TEXTURE_SIZE, &maxSize); char tBuff[250]; Logger::getSingleton().logEvent( tBuff ); if((size.d_width > maxSize) || (size.d_height > maxSize)) CEGUI_THROW(RendererException("size too big")); // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); Logger::getSingleton().logEvent( tBuff ); // set texture to required size glBindTexture(GL_TEXTURE_2D, d_ogltexture); Logger::getSingleton().logEvent( tBuff ); if(d_isCompressed) { const GLsizei image_size = getCompressedTextureSize(size); glCompressedTexImage2D(GL_TEXTURE_2D, 0, d_format, static_cast<GLsizei>(size.d_width), static_cast<GLsizei>(size.d_height), 0, image_size, 0); } else { #ifndef CEGUI_GLES3_SUPPORT glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, #endif static_cast<GLsizei>(size.d_width), static_cast<GLsizei>(size.d_height), 0, GL_RGBA , GL_UNSIGNED_BYTE, 0); } // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); }
//----------------------------------------------------------------------------// Sizef Direct3D10Renderer::getViewportSize() { D3D10_VIEWPORT vp; UINT vp_count = 1; d_device->RSGetViewports(&vp_count, &vp); if (vp_count != 1) CEGUI_THROW(RendererException( "Unable to access required view port information from " "IDirect3DDevice10.")); else return Sizef(static_cast<float>(vp.Width), static_cast<float>(vp.Height)); }
//----------------------------------------------------------------------------// void OpenGLES2Shader::outputProgramLog(GLuint program) { char logBuffer[LOG_BUFFER_SIZE]; GLsizei length; logBuffer[0] = '\0'; glGetProgramInfoLog(program, LOG_BUFFER_SIZE, &length, logBuffer); if (length > 0) { std::stringstream sstream; sstream << "OpenGLES2Shader linking has failed.\n" << logBuffer; CEGUI_THROW(RendererException(sstream.str().c_str())); } };
//----------------------------------------------------------------------------// void OpenGLES2Shader::outputShaderLog(GLuint shader) { char logBuffer[LOG_BUFFER_SIZE]; GLsizei length; logBuffer[0] = '\0'; glGetShaderInfoLog(shader, LOG_BUFFER_SIZE, &length, logBuffer); if (length > 0) { std::stringstream ss; ss << "OpenGLES2Shader compilation has failed.\n" << logBuffer; CEGUI_THROW(RendererException(ss.str().c_str())); } };
//----------------------------------------------------------------------------// Direct3D9ViewportTarget::Direct3D9ViewportTarget(Direct3D9Renderer& owner) : Direct3D9RenderTarget<>(owner) { // initialise renderer size D3DVIEWPORT9 vp; if (FAILED(d_owner.getDevice()->GetViewport(&vp))) CEGUI_THROW(RendererException("Unable to access " "required view port information from Direct3DDevice9.")); Rectf area( Vector2f(static_cast<float>(vp.X), static_cast<float>(vp.Y)), Sizef(static_cast<float>(vp.Width), static_cast<float>(vp.Height)) ); setArea(area); }
//----------------------------------------------------------------------------// Direct3D10ViewportTarget::Direct3D10ViewportTarget(Direct3D10Renderer& owner) : Direct3D10RenderTarget(owner) { // initialise renderer size D3D10_VIEWPORT vp; UINT vp_count = 1; d_device.RSGetViewports(&vp_count, &vp); if (vp_count != 1) throw RendererException("Direct3D10RenderTarget: Unable to access " "required view port information from ID3D10Device."); Rect area( Point(static_cast<float>(vp.TopLeftX), static_cast<float>(vp.TopLeftY)), Size(static_cast<float>(vp.Width), static_cast<float>(vp.Height)) ); setArea(area); }
void RenderArea::activateGLContext() { DB(cerr << "RenderArea::activateGLContext()" << endl); if (_myContextRefCount++ == 0) { GdkGLContext *glcontext = gtk_widget_get_gl_context (GTK_WIDGET(gobj())); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (GTK_WIDGET(gobj())); gdk_gl_drawable_gl_begin (gldrawable, glcontext); // init glew unsigned int myGlewError = glewInit(); if (GLEW_OK != myGlewError) { throw RendererException(std::string("Glew Initialization Error: ") + std::string(reinterpret_cast<const char*>(glewGetErrorString(myGlewError))), PLUS_FILE_LINE); } GLResourceManager::get().initCaps(); } }