mirror of https://github.com/mosra/magnum.git
24 changed files with 1531 additions and 821 deletions
@ -0,0 +1,68 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 |
||||||
|
Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/DefaultFramebuffer.h" |
||||||
|
#include "Magnum/Framebuffer.h" |
||||||
|
#include "Magnum/Platform/Sdl2Application.h" |
||||||
|
|
||||||
|
using namespace Magnum; |
||||||
|
|
||||||
|
struct A: Platform::Sdl2Application { |
||||||
|
/* [DefaultFramebuffer-usage-viewport] */ |
||||||
|
void viewportEvent(const Vector2i& size) override { |
||||||
|
defaultFramebuffer.setViewport({{}, size}); |
||||||
|
|
||||||
|
// ...
|
||||||
|
} |
||||||
|
/* [DefaultFramebuffer-usage-viewport] */ |
||||||
|
|
||||||
|
/* [DefaultFramebuffer-usage-clear] */ |
||||||
|
void drawEvent() override { |
||||||
|
defaultFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); |
||||||
|
|
||||||
|
// ...
|
||||||
|
} |
||||||
|
/* [DefaultFramebuffer-usage-clear] */ |
||||||
|
}; |
||||||
|
|
||||||
|
struct B: Platform::Sdl2Application { |
||||||
|
|
||||||
|
Framebuffer framebuffer; |
||||||
|
|
||||||
|
/* [Framebuffer-usage-draw] */ |
||||||
|
void drawEvent() override { |
||||||
|
defaultFramebuffer.clear(FramebufferClear::Color); |
||||||
|
framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil); |
||||||
|
|
||||||
|
framebuffer.bind(); |
||||||
|
// ...
|
||||||
|
|
||||||
|
defaultFramebuffer.bind(); |
||||||
|
// ...
|
||||||
|
|
||||||
|
swapBuffers(); |
||||||
|
} |
||||||
|
/* [Framebuffer-usage-draw] */ |
||||||
|
}; |
||||||
@ -1,108 +0,0 @@ |
|||||||
#include "Magnum/AbstractShaderProgram.h" |
|
||||||
#include "Magnum/Buffer.h" |
|
||||||
#include "Magnum/Context.h" |
|
||||||
#include "Magnum/Extensions.h" |
|
||||||
#include "Magnum/Mesh.h" |
|
||||||
#include "Magnum/Texture.h" |
|
||||||
#include "Magnum/TextureFormat.h" |
|
||||||
|
|
||||||
using namespace Magnum; |
|
||||||
|
|
||||||
std::tuple<Mesh, Buffer, Buffer> importSomeMesh(); |
|
||||||
|
|
||||||
struct Foo { |
|
||||||
void setSomeBuffer(GLuint); |
|
||||||
GLuint someBuffer(); |
|
||||||
} externalLib; |
|
||||||
|
|
||||||
void foo(); |
|
||||||
void foo() { |
|
||||||
|
|
||||||
{ |
|
||||||
/* [nocreate] */ |
|
||||||
Mesh mesh{NoCreate}; |
|
||||||
Buffer vertices{NoCreate}, indices{NoCreate}; |
|
||||||
std::tie(mesh, vertices, indices) = importSomeMesh(); |
|
||||||
/* [nocreate] */ |
|
||||||
} |
|
||||||
|
|
||||||
{ |
|
||||||
char someData[1]; |
|
||||||
/* [transfer] */ |
|
||||||
/* Transferring the instance to external library */ |
|
||||||
{ |
|
||||||
Buffer buffer; |
|
||||||
buffer.setData(someData, BufferUsage::StaticDraw); |
|
||||||
GLuint id = buffer.release(); |
|
||||||
externalLib.setSomeBuffer(id); /* The library is responsible for deletion */ |
|
||||||
} |
|
||||||
|
|
||||||
/* Acquiring an instance from external library */ |
|
||||||
{ |
|
||||||
GLuint id = externalLib.someBuffer(); |
|
||||||
Buffer buffer = Buffer::wrap(id, ObjectFlag::DeleteOnDestruction); |
|
||||||
/* The buffer instance now handles deletion */ |
|
||||||
} |
|
||||||
/* [transfer] */ |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef MAGNUM_TARGET_GLES |
|
||||||
{ |
|
||||||
struct: AbstractShaderProgram {} someShader; |
|
||||||
/* [state] */ |
|
||||||
Buffer buffer; |
|
||||||
Mesh mesh; |
|
||||||
// ...
|
|
||||||
mesh.draw(someShader); |
|
||||||
|
|
||||||
{ |
|
||||||
/* Entering a section with 3rd-party OpenGL code -- clean up all state that
|
|
||||||
could cause accidental modifications of our objects from outside */ |
|
||||||
Context::current().resetState(Context::State::EnterExternal); |
|
||||||
|
|
||||||
/* Raw OpenGL calls */ |
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer.id()); |
|
||||||
glBufferStorage(GL_ARRAY_BUFFER, 32768, nullptr, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT); |
|
||||||
// ...
|
|
||||||
|
|
||||||
/* Exiting a section with 3rd-party OpenGL code -- reset our state tracker */ |
|
||||||
Context::current().resetState(Context::State::ExitExternal); |
|
||||||
} |
|
||||||
|
|
||||||
/* Use the buffer through Magnum again */ |
|
||||||
auto data = buffer.map(0, 32768, Buffer::MapFlag::Read|Buffer::MapFlag::Write); |
|
||||||
// ...
|
|
||||||
/* [state] */ |
|
||||||
static_cast<void>(data); |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#ifndef MAGNUM_TARGET_GLES |
|
||||||
{ |
|
||||||
/* [extensions] */ |
|
||||||
TextureFormat format; |
|
||||||
if(Context::current().isExtensionSupported<Extensions::GL::ARB::depth_buffer_float>()) |
|
||||||
format = TextureFormat::DepthComponent32F; |
|
||||||
else |
|
||||||
format = TextureFormat::DepthComponent24; |
|
||||||
/* [extensions] */ |
|
||||||
static_cast<void>(format); |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) |
|
||||||
{ |
|
||||||
/* [dsa] */ |
|
||||||
Texture2D texture; |
|
||||||
|
|
||||||
/* - on OpenGL 4.5+/ARB_direct_state_access this calls glTextureStorage2D()
|
|
||||||
- if EXT_direct_state_access is available, calls glTextureStorage2DEXT() |
|
||||||
- on OpenGL 4.2+/ARB_texture_storage and OpenGL ES 3.0+ calls glTexStorage2D() |
|
||||||
- on OpenGL ES 2.0 with EXT_texture_storage calls glTexStorage2DEXT() |
|
||||||
- otherwise emulated using a sequence of four glTexImage2D() calls */ |
|
||||||
texture.setStorage(4, TextureFormat::RGBA8, {256, 256}); |
|
||||||
/* [dsa] */ |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue