axmol/cocos/renderer/backend/opengl/UtilsGL.h

170 lines
7.0 KiB
C
Raw Normal View History

2019-07-04 17:47:24 +08:00
/****************************************************************************
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
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.
****************************************************************************/
#pragma once
#include "base/ccMacros.h"
#include "platform/CCGL.h"
#include "renderer/backend/Types.h"
CC_BACKEND_BEGIN
2019-07-16 10:01:23 +08:00
/**
* @addtogroup _opengl
* @{
*/
2019-07-17 09:26:15 +08:00
2020-09-11 00:10:44 +08:00
class TextureBackend;
2019-07-17 09:26:15 +08:00
/**
* Convert backend enum class to corresponding opengl defined value.
*/
2020-09-11 00:10:44 +08:00
struct UtilsGL
{
2019-07-17 09:26:15 +08:00
/**
* Convert attribute enum classs type to GLenum type. i.e. convert VertexFormat::FLOAT4 to GL_FLOAT.
* @param vertexFormat Specifies the attribute data type to convert.
* @return Attribute type.
*/
static GLenum toGLAttributeType(VertexFormat vertexFormat);
/**
* Convert attribute component count to GLsizei. i.e. convert VertexFormat::FLOAT4 to 4.
* @param vertexFormat Specifies the attribute type.
* @return Attribute component counts.
*/
static GLsizei getGLAttributeSize(VertexFormat vertexFormat);
2019-07-17 09:26:15 +08:00
/**
* Get opengl data type size in bytes. i.e. GL_FLOAT_VEC4 data type size is sizeof(GLfloat) * 4.
* @param size Specifies the data type.
* @return Data type size in bytes.
*/
static GLsizei getGLDataTypeSize(GLenum size);
2019-07-17 09:26:15 +08:00
/**
* Convert magnification filter to GLint. i.e. convert SamplerFilter::LINEAR to GL_LINEAR.
* @param magFilter Specifies the magnification filter to convert.
* @return Magnification filter.
*/
static GLint toGLMagFilter(SamplerFilter magFilter);
2019-07-17 09:26:15 +08:00
/**
* Convert minifying filter to GLint. i.e. convert SamplerFilter::LINEAR to GL_LINEAR.
* If mipmaps is enabled and texture width and height are not power of two, then if minFilter is SamplerFilter::LINEAR, GL_LINEAR is returned, otherwise return GL_NEAREST.
* @param minFilter Specifies minifying filter.
* @param hasMipmaps Specifies whether mipmap is enabled.
* @param isPow2 Specifies if texture width and height are power of two.
* @return Minifying filter
*/
static GLint toGLMinFilter(SamplerFilter minFilter, bool hasMipmaps, bool isPow2);
2019-07-17 09:26:15 +08:00
/**
* Convert wrap parameter for texture coordinate to GLint. i.e. convert SamplerAddressMode::REPEAT to GL_REPEAT.
* If texture width and height are not power of 2, then GL_CLAMP_TO_EDGE is returned.
* @param addressMode Specifies wrapping mode.
* @param isPow2 Specifies if texture width and height are power of two.
* @return Wrap mode.
*/
static GLint toGLAddressMode(SamplerAddressMode addressMode, bool isPow2);
2019-07-17 09:26:15 +08:00
/**
* Get textrue parameters from texture pixle format.
* @param in textureFormat Specifies texture pixel format.
* @param out internalFormat Specifies the internal format of the texture.
* @param out format Specifies the format of the texel data.
* @param out type Specifies the data type of the texel data.
* @param out isCompressed Specifies if the texel data is compressed.
*/
static void toGLTypes(PixelFormat textureFormat, GLint &internalFormat, GLuint &format, GLenum &type, bool &isCompressed);
2019-07-17 09:26:15 +08:00
/**
* Convert compare function to GLenum. i.e. convert CompareFunction::NEVER to GL_NEVER.
* @param compareFunction Specifies the compare function to convert.
* @return Compare function.
*/
static GLenum toGLComareFunction(CompareFunction compareFunction);
2019-07-17 09:26:15 +08:00
/**
* Convert stencil operation to GLenum. i.e. convert StencilOperation::KEEP to GL_KEEP.
* @param stencilOperation Specifies stencil operation.
* @return Stencil operation.
*/
static GLenum toGLStencilOperation(StencilOperation stencilOperation);
2019-07-17 09:26:15 +08:00
/**
* Convert blend operation to GLenum. i.e. convert BlendOperation::ADD to GL_FUNC_ADD.
* @param blendOperation Specifies blend function to convert.
* @return Blend operation.
*/
static GLenum toGLBlendOperation(BlendOperation blendOperation);
2019-07-17 09:26:15 +08:00
/**
* Convert blend factor to GLenum. i.e. convert BlendFactor::ZERO to GL_ZERO.
* @param blendFactor Specifies the blend factor to convert.
* @return Blend factor.
*/
static GLenum toGLBlendFactor(BlendFactor blendFactor);
2019-07-17 09:26:15 +08:00
/**
* Convert winding value to GLenum. i.e. convert Winding::CLOCK_WISE to GL_CW.
* @param winding Specifies the winding value to convert.
* @return Winding mode.
*/
static GLenum toGLFrontFace(Winding winding);
2019-07-17 09:26:15 +08:00
/**
* Convert primitive type to GLenum. i.e. convert PrimitiveType::TRIANGLE to GL_TRIANGLES.
* @param primitiveType Specifies the kind of primitives to convert.
* @return Primitive type.
*/
static GLenum toGLPrimitiveType(PrimitiveType primitiveType);
2019-07-17 09:26:15 +08:00
/**
* Convert index type to GLenum. i.e. convert IndexFormat::U_INT to GL_UNSIGNED_INT.
* @param indexType Specifies the index type to convert.
* @return Index type.
*/
static GLenum toGLIndexType(IndexFormat indexType);
2019-07-17 09:26:15 +08:00
/**
* Convert cull mode to GLenum. i.e. convert CullMode::BACK to GL_BACK.
* @param mode Specifies the cull mode to convert.
* @return Cull mode.
*/
static GLenum toGLCullMode(CullMode mode);
2020-09-11 00:10:44 +08:00
/**
* Read a block of pixels from the given texture
* @param texture Specifies the texture to get the image.
* @param origX,origY Specify the window coordinates of the first pixel that is read from the given texture. This location is the lower left corner of a rectangular block of pixels.
* @param rectWidth,rectHeight Specify the dimensions of the pixel rectangle. rectWidth and rectHeight of one correspond to a single pixel.
* @param outbuffer, the output buffer for fill texels data
* @remark: !!!this function only can call after endFrame, then it's could be works well.
*/
static void readPixels(TextureBackend* texture, std::size_t origX, std::size_t origY, std::size_t rectWidth, std::size_t rectHeight, PixelBufferDescriptor& outbuffer);
};
2019-07-16 10:01:23 +08:00
//end of _opengl group
/// @}
2020-09-11 00:14:03 +08:00
CC_BACKEND_END