本文整理匯總了C++中GLCheck函數的典型用法代碼示例。如果您正苦於以下問題:C++ GLCheck函數的具體用法?C++ GLCheck怎麽用?C++ GLCheck使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GLCheck函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: GLCheck
void RenderableObject::CompileBuffers()
{
Logger::Log() << "[INFO] Generate " << m_buffers.size() + 1
<< " buffers ... \n";
m_is_compiled = true;
m_indices_buffers = new unsigned int[m_buffers.size() + 1];
GLCheck(glGenBuffers( m_buffers.size()+1, m_indices_buffers ));
Logger::Log() << " * indice id : " << m_indices_buffers[0] << "\n";
// Add index buffer
Logger::Log() << " * load indices buffers ... " << m_indices_buffers[0]
<< "\n";
GLCheck(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indices_buffers[0]));
GLCheck(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)*m_indices_size, m_indices, GL_STATIC_DRAW));
// Add all others buffers
int i = 1;
for (BufferMap::iterator it = m_buffers.begin(); it != m_buffers.end();
it++)
{
Logger::Log() << " * load other buffers ... " << m_indices_buffers[i]
<< "\n";
GLCheck(glBindBuffer(GL_ARRAY_BUFFER, m_indices_buffers[i]));
GLCheck(glBufferData(GL_ARRAY_BUFFER, sizeof(float)*it->second.size, it->second.buffer, GL_STATIC_DRAW));
i++;
}
}
示例2: Assert
void RenderableObject::Draw()
{
Assert(m_is_compiled);
// pas de shader
if (!CShaderManager::Instance().activedShader())
{
Logger::Log()
<< "[Warning] No actived shader. Nothings to render ... \n";
}
// Material activation
for (MaterialMap::iterator it = m_material_map.begin();
it != m_material_map.end(); it++)
{
if (!CShaderManager::Instance().currentShader()->IsMaterialAvailable(it->first))
continue;
CShaderManager::Instance().currentShader()->SetMaterialValue(it->first,it->second);
}
// Textures activation
for (TexturesMap::iterator it = m_textures_map.begin();
it != m_textures_map.end(); it++)
{
if (!CShaderManager::Instance().currentShader()->IsTextureAvailable(
it->first))
continue;
it->second->activateMultiTex(it->first);
}
// Buffer activation
int i = 1;
for (BufferMap::iterator it = m_buffers.begin(); it != m_buffers.end(); it++)
{
if (!CShaderManager::Instance().currentShader()->IsAttributAvailable(it->first))
continue;
GLCheck(glBindBuffer(GL_ARRAY_BUFFER, m_indices_buffers[i]));
glEnableVertexAttribArray(it->first);
GLCheck(glVertexAttribPointer(it->first, it->second.dimension, GL_FLOAT, GL_FALSE, 0, 0));
i++;
}
// Drawing
CShaderManager::Instance().currentShader()->OnDraw();
GLCheck(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indices_buffers[0]));
GLCheck(glDrawElements(m_DrawMode, m_indices_size, GL_UNSIGNED_INT, 0));
// Buffer desactivation
for (BufferMap::iterator it = m_buffers.begin(); it != m_buffers.end();
it++)
{
if (!CShaderManager::Instance().currentShader()->IsAttributAvailable(
it->first))
continue;
glDisableVertexAttribArray(it->first);
}
// Textures desactivations
for (TexturesMap::reverse_iterator it = m_textures_map.rbegin();
it != m_textures_map.rend(); it++)
{
if (!CShaderManager::Instance().currentShader()->IsTextureAvailable(
it->first))
continue;
it->second->desactivateMultiTex(it->first);
}
}
示例3: glGetUniformLocation
////////////////////////////////////////////////////////////
/// Change la valeur d'un paramètre (scalaire ou vecteur) du shader
///
/// \param Name : Nom du paramètre
/// \param Value : Valeur du paramètre (quadruplet de flottants)
///
////////////////////////////////////////////////////////////
void GLShader::SetParameter(const std::string& Name, const size_t count_, const float* Value)
{
GLuint paramID = glGetUniformLocation(m_ProgramID, Name.c_str());
/*
glUniform1f (GLint location, GLfloat v0);
glUniform2f (GLint location, GLfloat v0, GLfloat v1);
glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
*/
switch (count_)
{
case 1:
GLCheck(glUniform1fv(paramID, 1, Value));
break;
case 2:
GLCheck(glUniform2fv(paramID, 1, Value));
break;
case 3:
GLCheck(glUniform3fv(paramID, 1, Value));
break;
case 4:
GLCheck(glUniform4fv(paramID, 1, Value));
break;
}
}
示例4: send_attribute
void send_attribute(ShaderAvailableAttributes attr,
const VertexData& data,
EnabledMethod exists_on_data_predicate,
OffsetMethod offset_func) {
int32_t loc = (int32_t) attr;
auto get_has_attribute = std::bind(exists_on_data_predicate, std::reference_wrapper<const VertexData>(data));
if(get_has_attribute()) {
auto get_offset = std::bind(offset_func, std::reference_wrapper<const VertexData>(data));
GLCheck(glEnableVertexAttribArray, loc);
GLCheck(glVertexAttribPointer,
loc,
SHADER_ATTRIBUTE_SIZES.find(attr)->second,
GL_FLOAT,
GL_FALSE,
data.stride(),
BUFFER_OFFSET(get_offset())
);
} else {
//L_WARN_ONCE(_u("Couldn't locate attribute on the mesh: {0}").format(attr));
}
}
示例5: GLCheck
////////////////////////////////////////////////////////////
/// Called when the window displays its content on screen
////////////////////////////////////////////////////////////
void RenderWindow::OnDisplay()
{
// Clear the frame buffer with the background color, for next frame
GLCheck(glClearColor(myBackgroundColor.r / 255.f,
myBackgroundColor.g / 255.f,
myBackgroundColor.b / 255.f,
myBackgroundColor.a / 255.f));
GLCheck(glClear(GL_COLOR_BUFFER_BIT));
}
示例6: Image
Image Texture::CopyToImage() const
{
// Easy case: empty texture
if (!myTexture)
return Image();
EnsureGlContext();
// Make sure that the current texture binding will be preserved
priv::TextureSaver save;
// Create an array of pixels
std::vector<Uint8> pixels(myWidth * myHeight * 4);
if ((myWidth == myTextureWidth) && (myHeight == myTextureHeight) && !myPixelsFlipped)
{
// Texture is not padded nor flipped, we can use a direct copy
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]));
}
else
{
// Texture is either padded or flipped, we have to use a slower algorithm
// All the pixels will first be copied to a temporary array
std::vector<Uint8> allPixels(myTextureWidth * myTextureHeight * 4);
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0]));
// Then we copy the useful pixels from the temporary array to the final one
const Uint8* src = &allPixels[0];
Uint8* dst = &pixels[0];
int srcPitch = myTextureWidth * 4;
int dstPitch = myWidth * 4;
// Handle the case where source pixels are flipped vertically
if (myPixelsFlipped)
{
src += srcPitch * (myHeight - 1);
srcPitch = -srcPitch;
}
for (unsigned int i = 0; i < myHeight; ++i)
{
std::memcpy(dst, src, dstPitch);
src += srcPitch;
dst += dstPitch;
}
}
// Create the image
Image image;
image.Create(myWidth, myHeight, &pixels[0]);
return image;
}
示例7: Update
bool Texture::LoadFromImage(const Image& image, const IntRect& area)
{
// Retrieve the image size
int width = static_cast<int>(image.GetWidth());
int height = static_cast<int>(image.GetHeight());
// Load the entire image if the source area is either empty or contains the whole image
if (area.Width == 0 || (area.Height == 0) ||
((area.Left <= 0) && (area.Top <= 0) && (area.Width >= width) && (area.Height >= height)))
{
// Load the entire image
if (Create(image.GetWidth(), image.GetHeight()))
{
Update(image);
return true;
}
else
{
return false;
}
}
else
{
// Load a sub-area of the image
// Adjust the rectangle to the size of the image
IntRect rectangle = area;
if (rectangle.Left < 0) rectangle.Left = 0;
if (rectangle.Top < 0) rectangle.Top = 0;
if (rectangle.Left + rectangle.Width > width) rectangle.Width = width - rectangle.Left;
if (rectangle.Top + rectangle.Height > height) rectangle.Height = height - rectangle.Top;
// Create the texture and upload the pixels
if (Create(rectangle.Width, rectangle.Height))
{
// Make sure that the current texture binding will be preserved
priv::TextureSaver save;
// Copy the pixels to the texture, row by row
const Uint8* pixels = image.GetPixelsPtr() + 4 * (rectangle.Left + (width * rectangle.Top));
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
for (int i = 0; i < rectangle.Height; ++i)
{
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, myWidth, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
pixels += 4 * width;
}
return true;
}
else
{
return false;
}
}
}
示例8: GLCheck
void Renderer::RestoreGLStates()
{
// Restore render states
GLCheck(glPopAttrib());
// Restore matrices
GLCheck(glMatrixMode(GL_PROJECTION));
GLCheck(glPopMatrix());
GLCheck(glMatrixMode(GL_MODELVIEW));
GLCheck(glPopMatrix());
}
示例9: GLCheck
void RenderImageImplDefault::UpdateTexture(unsigned int textureId)
{
GLint previous;
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous));
// Copy the rendered pixels to the image
GLCheck(glBindTexture(GL_TEXTURE_2D, textureId));
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
}
示例10: assert
void Texture::Update(const Window& window, unsigned int x, unsigned int y)
{
assert(x + window.GetWidth() <= myWidth);
assert(y + window.GetHeight() <= myHeight);
if (myTexture && window.SetActive(true))
{
// Copy pixels from the back-buffer to the texture
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.GetWidth(), window.GetHeight()));
myPixelsFlipped = true;
}
}
示例11: GLCheck
void HardwareGeometry::cleanUp
(
)
{
if( glIsBuffer(m_vbo) )
GLCheck(glDeleteBuffers(1, &m_vbo));
if( glIsBuffer(m_ibo) )
GLCheck(glDeleteBuffers(1, &m_ibo));
if( glIsVertexArray(m_vao) )
GLCheck(glDeleteVertexArrays(1, &m_vao));
}
示例12: GLCheck
void Shader::BindTextures() const
{
TextureTable::const_iterator it = myTextures.begin();
for (std::size_t i = 0; i < myTextures.size(); ++i)
{
GLint index = static_cast<GLsizei>(i + 1);
GLCheck(glUniform1iARB(it->first, index));
GLCheck(glActiveTextureARB(GL_TEXTURE0_ARB + index));
it->second->Bind();
it++;
}
// Make sure that the texture unit which is left active is the number 0
GLCheck(glActiveTextureARB(GL_TEXTURE0_ARB));
}
示例13: GLCheck
RenderImageImplFBO::~RenderImageImplFBO()
{
// Destroy the depth buffer
if (myDepthBuffer)
{
GLuint depthBuffer = static_cast<GLuint>(myDepthBuffer);
GLCheck(glDeleteFramebuffersEXT(1, &depthBuffer));
}
// Destroy the frame buffer
if (myFrameBuffer)
{
GLuint frameBuffer = static_cast<GLuint>(myFrameBuffer);
GLCheck(glDeleteFramebuffersEXT(1, &frameBuffer));
}
}
示例14: checkDimensionsArePowerOfTwo
void UploaderTexture2D::allocateTextureMemory
(
PixelFormat format,
const uvec2 &dimensions,
unsigned int levels
)
{
checkDimensionsArePowerOfTwo(dimensions);
// Use glTexStorage2D instead, it's the same but OpenGL 4.2!! Remplacer même l'exception
//GLCheck(glTexStorage2D(GL_TEXTURE_2D, levels, GLEnum::getInternalFormat(format), dimensions.x, dimensions.y));
if(levels < 1)
throw std::runtime_error("Levels < 1");
unsigned int width = dimensions.x;
unsigned int height = dimensions.y;
for (unsigned int i(0); i<levels; i++)
{
GLCheck( glTexImage2D(GL_TEXTURE_2D, i, GLEnum::getInternalFormat(format), width, height, 0, GLEnum::getExternalFormat(format), GLEnum::getType(format), NULL ));
width = std::max(1u, width/2);
height = std::max(1u, height/2);
}
}
示例15: GetWidth
////////////////////////////////////////////////////////////
/// Save the content of the window to an image
////////////////////////////////////////////////////////////
Image RenderWindow::Capture() const
{
// Get the window dimensions
const unsigned int Width = GetWidth();
const unsigned int Height = GetHeight();
// Set our window as the current target for rendering
if (SetActive())
{
// Get pixels from the backbuffer
std::vector<Uint8> Pixels(Width * Height * 4);
Uint8* PixelsPtr = &Pixels[0];
GLCheck(glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, PixelsPtr));
// Flip the pixels
unsigned int Pitch = Width * 4;
for (unsigned int y = 0; y < Height / 2; ++y)
std::swap_ranges(PixelsPtr + y * Pitch, PixelsPtr + (y + 1) * Pitch, PixelsPtr + (Height - y - 1) * Pitch);
// Create an image from the pixel buffer and return it
return Image(Width, Height, PixelsPtr);
}
else
{
return Image(Width, Height, Color::White);
}
}