mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Feat] (ProgramState): Implement more Global-GL-State functions.
- These functions were implemented: - glBlendFunc - glBlendFuncSeparate - glClear - glClearColor - glClearDepth - glColorMask - glDepthFunc - glDepthMask - glDisable - glEnable - glViewport
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
|
||||
#include "CommonState.h"
|
||||
|
||||
CommonState::CommonState() {
|
||||
pixelStoreParams[GL_PACK_ALIGNMENT] = 4;
|
||||
pixelStoreParams[GL_UNPACK_ALIGNMENT] = 4;
|
||||
}
|
||||
|
||||
GLenum CommonState::SetPixelStoreInt(GLenum pname, GLint param) {
|
||||
if (MG_Constants::PixelStore::VALID_PARAM_NAMES.find(pname) == MG_Constants::PixelStore::VALID_PARAM_NAMES.end()) {
|
||||
return GL_INVALID_ENUM;
|
||||
@@ -54,3 +59,99 @@ GLint CommonState::QueryPixelStoreInt(GLenum pname) {
|
||||
auto defaultIt = MG_Constants::PixelStore::DEFAULT_VALUES_MAP.find(pname);
|
||||
return (defaultIt != MG_Constants::PixelStore::DEFAULT_VALUES_MAP.end()) ? defaultIt->second : 0;
|
||||
}
|
||||
|
||||
GLenum CommonState::Enable(GLenum cap) {
|
||||
if (MG_Constants::CommonState::VALID_CAPS.find(cap) == MG_Constants::CommonState::VALID_CAPS.end()) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
capabilities[cap] = true;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::Disable(GLenum cap) {
|
||||
if (MG_Constants::CommonState::VALID_CAPS.find(cap) == MG_Constants::CommonState::VALID_CAPS.end()) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
capabilities[cap] = false;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::BlendFunc(GLenum sfactor, GLenum dfactor) {
|
||||
if (MG_Constants::Blend::VALID_FACTORS.find(sfactor) == MG_Constants::Blend::VALID_FACTORS.end() ||
|
||||
MG_Constants::Blend::VALID_FACTORS.find(dfactor) == MG_Constants::Blend::VALID_FACTORS.end()) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
|
||||
blendSrcRGB = blendSrcAlpha = sfactor;
|
||||
blendDstRGB = blendDstAlpha = dfactor;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
|
||||
GLenum srcAlpha, GLenum dstAlpha) {
|
||||
if (MG_Constants::Blend::VALID_FACTORS.find(srcRGB) == MG_Constants::Blend::VALID_FACTORS.end() ||
|
||||
MG_Constants::Blend::VALID_FACTORS.find(dstRGB) == MG_Constants::Blend::VALID_FACTORS.end() ||
|
||||
MG_Constants::Blend::VALID_FACTORS.find(srcAlpha) == MG_Constants::Blend::VALID_FACTORS.end() ||
|
||||
MG_Constants::Blend::VALID_FACTORS.find(dstAlpha) == MG_Constants::Blend::VALID_FACTORS.end()) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
blendSrcRGB = srcRGB;
|
||||
blendDstRGB = dstRGB;
|
||||
blendSrcAlpha = srcAlpha;
|
||||
blendDstAlpha = dstAlpha;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::Clear(GLbitfield mask) {
|
||||
const GLbitfield validBits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
|
||||
if ((mask & ~validBits) != 0) {
|
||||
return GL_INVALID_VALUE;
|
||||
}
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
|
||||
clearColor[0] = red;
|
||||
clearColor[1] = green;
|
||||
clearColor[2] = blue;
|
||||
clearColor[3] = alpha;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::ClearDepth(GLfloat depth) {
|
||||
clearDepth = depth;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
|
||||
colorMask[0] = red;
|
||||
colorMask[1] = green;
|
||||
colorMask[2] = blue;
|
||||
colorMask[3] = alpha;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::DepthFunc(GLenum func) {
|
||||
if (MG_Constants::Depth::VALID_FUNCS.find(func) == MG_Constants::Depth::VALID_FUNCS.end()) {
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
depthFunc = func;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::DepthMask(GLboolean flag) {
|
||||
depthMask = flag;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
|
||||
GLenum CommonState::Viewport(GLint x, GLint y, GLsizei width, GLsizei height) {
|
||||
if (width < 0 || height < 0) {
|
||||
return GL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
viewport[0] = x;
|
||||
viewport[1] = y;
|
||||
viewport[2] = width;
|
||||
viewport[3] = height;
|
||||
return GL_NO_ERROR;
|
||||
}
|
||||
@@ -10,11 +10,51 @@
|
||||
|
||||
class CommonState {
|
||||
private:
|
||||
// Pixel storage parameters
|
||||
std::unordered_map<GLenum, GLint> pixelStoreParams;
|
||||
|
||||
// Blend state
|
||||
GLenum blendSrcRGB = GL_ONE;
|
||||
GLenum blendDstRGB = GL_ZERO;
|
||||
GLenum blendSrcAlpha = GL_ONE;
|
||||
GLenum blendDstAlpha = GL_ZERO;
|
||||
|
||||
// Clear state
|
||||
GLfloat clearColor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
GLfloat clearDepth = 1.0f;
|
||||
|
||||
// Color mask
|
||||
GLboolean colorMask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE};
|
||||
|
||||
// Depth state
|
||||
GLenum depthFunc = GL_LESS;
|
||||
GLboolean depthMask = GL_TRUE;
|
||||
|
||||
// Viewport
|
||||
GLint viewport[4] = {0, 0, 0, 0};
|
||||
|
||||
// Capability enables
|
||||
std::unordered_map<GLenum, bool> capabilities;
|
||||
|
||||
public:
|
||||
CommonState();
|
||||
|
||||
// Return: the validity of the operation, according to OpenGL 3 standard
|
||||
GLenum SetPixelStoreInt(GLenum pname, GLint param);
|
||||
|
||||
GLenum Enable(GLenum cap);
|
||||
GLenum Disable(GLenum cap);
|
||||
GLenum BlendFunc(GLenum sfactor, GLenum dfactor);
|
||||
GLenum BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
|
||||
GLenum srcAlpha, GLenum dstAlpha);
|
||||
GLenum Clear(GLbitfield mask);
|
||||
GLenum ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
GLenum ClearDepth(GLfloat depth);
|
||||
GLenum ColorMask(GLboolean red, GLboolean green,
|
||||
GLboolean blue, GLboolean alpha);
|
||||
GLenum DepthFunc(GLenum func);
|
||||
GLenum DepthMask(GLboolean flag);
|
||||
GLenum Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
|
||||
GLint QueryPixelStoreInt(GLenum pname);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user