本文整理汇总了C++中MakeContextCurrent函数的典型用法代码示例。如果您正苦于以下问题:C++ MakeContextCurrent函数的具体用法?C++ MakeContextCurrent怎么用?C++ MakeContextCurrent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeContextCurrent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeContextCurrent
void
WebGL2Context::UniformMatrix2x3fv_base(WebGLUniformLocation* loc, bool transpose,
size_t arrayLength, const GLfloat* data)
{
GLuint rawLoc;
GLsizei numElementsToUpload;
if (!ValidateUniformMatrixArraySetter(loc, 2, 3, LOCAL_GL_FLOAT, arrayLength,
transpose, "uniformMatrix2x3fv",
&rawLoc, &numElementsToUpload))
{
return;
}
MakeContextCurrent();
gl->fUniformMatrix2x3fv(rawLoc, numElementsToUpload, transpose, data);
}
示例2: GetBufferSlotByTarget
void
WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage)
{
if (IsContextLost())
return;
if (!ValidateBufferTarget(target, "bufferData"))
return;
WebGLRefPtr<WebGLBuffer>& bufferSlot = GetBufferSlotByTarget(target);
if (size < 0)
return ErrorInvalidValue("bufferData: negative size");
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
return;
// careful: WebGLsizeiptr is always 64-bit, but GLsizeiptr is like intptr_t.
if (!CheckedInt<GLsizeiptr>(size).isValid())
return ErrorOutOfMemory("bufferData: bad size");
WebGLBuffer* boundBuffer = bufferSlot.get();
if (!boundBuffer)
return ErrorInvalidOperation("bufferData: no buffer bound!");
UniquePtr<uint8_t> zeroBuffer((uint8_t*)calloc(size, 1));
if (!zeroBuffer)
return ErrorOutOfMemory("bufferData: out of memory");
MakeContextCurrent();
InvalidateBufferFetching();
GLenum error = CheckedBufferData(target, size, zeroBuffer.get(), usage);
if (error) {
GenerateWarning("bufferData generated error %s", ErrorName(error));
return;
}
boundBuffer->SetByteLength(size);
if (!boundBuffer->ElementArrayCacheBufferData(nullptr, size)) {
return ErrorOutOfMemory("bufferData: out of memory");
}
}
示例3: MakeContextCurrent
bool
WebGL2Context::IsSampler(WebGLSampler* sampler)
{
if (IsContextLost())
return false;
if (!sampler)
return false;
if (!ValidateObjectAllowDeleted("isSampler", sampler))
return false;
if (sampler->IsDeleted())
return false;
MakeContextCurrent();
return gl->fIsSampler(sampler->mGLName);
}
示例4: MakeContextCurrent
bool
WebGLContext::IsVertexArray(WebGLVertexArray* array)
{
if (IsContextLost())
return false;
if (!array)
return false;
if (!ValidateObjectAllowDeleted("isVertexArray", array))
return false;
if (array->IsDeleted())
return false;
MakeContextCurrent();
return array->IsVertexArray();
}
示例5: MOZ_ASSERT
void
WebGL2Context::ResumeTransformFeedback()
{
if (IsContextLost())
return;
WebGLTransformFeedback* tf = mBoundTransformFeedback;
MOZ_ASSERT(tf);
if (!tf)
return;
if (!tf->mIsActive || !tf->mIsPaused)
return ErrorInvalidOperation("resumeTransformFeedback: transform feedback is not active or is not paused");
MakeContextCurrent();
gl->fResumeTransformFeedback();
tf->mIsPaused = false;
}
示例6: switch
void
WebGLContext::BindTexture(GLenum rawTarget, WebGLTexture* newTex)
{
if (IsContextLost())
return;
if (!ValidateObjectAllowDeletedOrNull("bindTexture", newTex))
return;
// Need to check rawTarget first before comparing against newTex->Target() as
// newTex->Target() returns a TexTarget, which will assert on invalid value.
WebGLRefPtr<WebGLTexture>* currentTexPtr = nullptr;
switch (rawTarget) {
case LOCAL_GL_TEXTURE_2D:
currentTexPtr = &mBound2DTextures[mActiveTexture];
break;
case LOCAL_GL_TEXTURE_CUBE_MAP:
currentTexPtr = &mBoundCubeMapTextures[mActiveTexture];
break;
case LOCAL_GL_TEXTURE_3D:
if (!IsWebGL2())
return ErrorInvalidEnum("bindTexture: target TEXTURE_3D is only available in WebGL version 2.0 or newer");
currentTexPtr = &mBound3DTextures[mActiveTexture];
break;
default:
return ErrorInvalidEnumInfo("bindTexture: target", rawTarget);
}
const TexTarget texTarget(rawTarget);
MakeContextCurrent();
if (newTex && !newTex->BindTexture(texTarget))
return;
if (!newTex) {
gl->fBindTexture(texTarget.get(), 0);
}
*currentTexPtr = newTex;
}
示例7: LastColorAttachmentEnum
void
WebGL2Context::ReadBuffer(GLenum mode)
{
if (IsContextLost())
return;
const bool isColorAttachment = (mode >= LOCAL_GL_COLOR_ATTACHMENT0 &&
mode <= LastColorAttachmentEnum());
if (mode != LOCAL_GL_NONE && mode != LOCAL_GL_BACK && !isColorAttachment) {
ErrorInvalidEnum("readBuffer: `mode` must be one of NONE, BACK, or "
"COLOR_ATTACHMENTi. Was %s",
EnumName(mode));
return;
}
if (mBoundReadFramebuffer) {
if (mode != LOCAL_GL_NONE &&
!isColorAttachment)
{
ErrorInvalidOperation("readBuffer: If READ_FRAMEBUFFER is non-null, `mode` "
"must be COLOR_ATTACHMENTi or NONE. Was %s",
EnumName(mode));
return;
}
MakeContextCurrent();
mBoundReadFramebuffer->SetReadBufferMode(mode);
gl->fReadBuffer(mode);
return;
}
// Operating on the default framebuffer.
if (mode != LOCAL_GL_NONE &&
mode != LOCAL_GL_BACK)
{
ErrorInvalidOperation("readBuffer: If READ_FRAMEBUFFER is null, `mode`"
" must be BACK or NONE. Was %s",
EnumName(mode));
return;
}
gl->Screen()->SetReadBuffer(mode);
}
示例8: glfwCreateWindow
Window::Window(const int2 & dimensions, const char * title)
{
if(glfwInit() == GL_FALSE) throw std::runtime_error("glfwInit() failed.");
window = glfwCreateWindow(dimensions.x, dimensions.y, title, nullptr, nullptr);
if(window == nullptr) throw std::runtime_error("glfwCreateWindow(...) failed.");
glfwSetWindowUserPointer(window, this);
glfwSetKeyCallback(window, OnKey);
const uint32_t compressedFont[] = {
0,0x18,0,0,0x660000,0xc000018,0,0,0x36661800,0xc1c003e,0xc30,0x40000000,0x36663c00,0xc360063,0x1818,0x60000000,0x7f243c00,0x6364343,0x1866300c,0x30000000,0x36003c00,0x1c6303,0x183c300c,
0x18000000,0x36001800,0x6e303e,0x7eff300c,0xc007f00,0x36001800,0x3b1860,0x183c300c,0x6000000,0x7f000000,0x330c61,0x1866300c,0x3000018,0x36001800,0x336663,0x1818,0x1180018,0x36001800,
0x6e633e,0xc30,0x180018,0,0x18,0,0xc,0,0x18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3e3e183e,0x7f1c7f30,0x3e3e,0x3e060060,0x63631c63,0x63060338,0x18186363,0x630c0030,0x60601e73,0x6003033c,0x18186363,
0x63180018,0x6030187b,0x30030336,0x6363,0x30307e0c,0x3c18186f,0x183f3f33,0x7e3e,0x18600006,0x600c1867,0xc63607f,0x6063,0x1830000c,0x60061863,0xc636030,0x18186063,0x187e18,0x63631863,
0xc636330,0x18183063,0x180c0030,0x3e7f7e3e,0xc3e3e78,0xc001e3e,0x18060060,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3c3f083e,0x3c7f7f1f,0x67783c63,0x1c63630f,0x66661c63,0x66666636,
0x66301863,0x36677706,0x43663663,0x43464666,0x36301863,0x636f7f06,0x366637b,0x3161666,0x36301863,0x637f7f06,0x33e637b,0x31e1e66,0x1e30187f,0x637b6b06,0x3667f7b,0x7b161666,0x36301863,
0x63736306,0x4366633b,0x63064666,0x36331863,0x63636346,0x66666303,0x66066636,0x66331863,0x36636366,0x3c3f633e,0x5c0f7f1f,0x671e3c63,0x1c63637f,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000,0,0,0,
0x1c0000,0x3e3f3e3f,0x6363637e,0x3c7f6663,0x363c01,0x63666366,0x6363637e,0xc636663,0x633003,0x63666366,0x6363635a,0xc316636,0x3007,0x6666366,0x63636318,0xc18661c,0x300e,0x1c3e633e,
0x6b636318,0xc0c3c1c,0x301c,0x30366b06,0x6b636318,0xc06181c,0x3038,0x63667b06,0x7f366318,0xc431836,0x3070,0x63663e06,0x3e1c6318,0xc631863,0x3060,0x3e67300f,0x36083e3c,0x3c7f3c63,0x3c40,
0x7000,0,0,0,0,0,0,0xff000000,0,0,0,0,0xc,0,0,0,0xc,0,0,0,0x70018,0x1c0038,0x7601807,0x1c,0x60000,0x360030,0x6601806,0x18,0x60000,0x260030,0x6000006,0x18,0x3e1e1e00,0x6e063e3c,0x66701c36,
0x3e3b3718,0x63363000,0x330f6336,0x3660186e,0x63667f18,0x3663e00,0x33067f33,0x1e601866,0x63666b18,0x3663300,0x33060333,0x36601866,0x63666b18,0x63663300,0x3e066333,0x66601866,0x63666b18,
0x3e3e6e00,0x300f3e6e,0x67663c67,0x3e66633c,0,0x33000000,0x660000,0,0,0x1e000000,0x3c0000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x8,0x70000000,0x6e0e18,0,0xc,0x18000000,0x3b1818,0,0xc,0x18000000,
0x1818,0x3e3b6e3b,0x6366333f,0x187f6363,0x1818,0x636e3366,0x6366330c,0xe336336,0x7000,0xe663366,0x6b66330c,0x1818631c,0x1818,0x38063366,0x6b66330c,0x180c631c,0x1818,0x63063e3e,0x7f3c336c,
0x18667e36,0x1818,0x3e0f3006,0x36186e38,0x707f6063,0xe18,0x3006,0,0x3000,0,0x780f,0,0x1f00 };
uint8_t fontPixels[128*128] = {};
auto out = fontPixels;
for(auto num : compressedFont)
{
for(int i=0; i<32; ++i)
{
*out++ = num & (1 << i) ? 255 : 0;
}
}
MakeContextCurrent();
glGenTextures(1, &fontTexture);
glBindTexture(GL_TEXTURE_2D, fontTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, fontPixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBindTexture(GL_TEXTURE_2D, 0);
}
示例9: GetStateTrackingSlot
void
WebGLContext::Enable(GLenum cap)
{
if (IsContextLost())
return;
if (!ValidateCapabilityEnum(cap, "enable"))
return;
realGLboolean* trackingSlot = GetStateTrackingSlot(cap);
if (trackingSlot)
{
*trackingSlot = 1;
}
MakeContextCurrent();
gl->fEnable(cap);
}
示例10: GetQuerySlotByTarget
void
WebGL2Context::EndQuery(GLenum target)
{
if (IsContextLost())
return;
if (!ValidateQueryTarget(target, "endQuery"))
return;
WebGLRefPtr<WebGLQuery>& querySlot = GetQuerySlotByTarget(target);
WebGLQuery* activeQuery = querySlot.get();
if (!activeQuery || target != activeQuery->mType)
{
/* From GLES's EXT_occlusion_query_boolean:
* marks the end of the sequence of commands to be tracked for the
* query type given by <target>. The active query object for
* <target> is updated to indicate that query results are not
* available, and the active query object name for <target> is reset
* to zero. When the commands issued prior to EndQueryEXT have
* completed and a final query result is available, the query object
* active when EndQueryEXT is called is updated by the GL. The query
* object is updated to indicate that the query results are
* available and to contain the query result. If the active query
* object name for <target> is zero when EndQueryEXT is called, the
* error INVALID_OPERATION is generated.
*/
ErrorInvalidOperation("endQuery: There is no active query of type %s.",
GetQueryTargetEnumString(target));
return;
}
MakeContextCurrent();
if (target == LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN) {
gl->fEndQuery(LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
} else {
gl->fEndQuery(SimulateOcclusionQueryTarget(gl, target));
}
UpdateBoundQuery(target, nullptr);
NS_DispatchToCurrentThread(new WebGLQuery::AvailableRunnable(activeQuery));
}
示例11: MakeContextCurrent
void
WebGLContext::DisableVertexAttribArray(GLuint index)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "disableVertexAttribArray"))
return;
MakeContextCurrent();
InvalidateBufferFetching();
if (index || !gl->IsCompatibilityProfile()) {
gl->fDisableVertexAttribArray(index);
}
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->mAttribs[index].mEnabled = false;
}
示例12: MOZ_ASSERT
void
WebGLContext::VertexAttribDivisor(GLuint index, GLuint divisor)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttribDivisor"))
return;
MOZ_ASSERT(mBoundVertexArray);
WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
vd.mDivisor = divisor;
InvalidateBufferFetching();
MakeContextCurrent();
gl->fVertexAttribDivisor(index, divisor);
}
示例13: MakeContextCurrent
/* This doesn't belong here. It's part of state querying */
void
WebGL2Context::GetIndexedParameter(GLenum target, GLuint index,
dom::Nullable<dom::OwningWebGLBufferOrLongLong>& retval)
{
retval.SetNull();
if (IsContextLost())
return;
GLint64 data = 0;
MakeContextCurrent();
switch (target) {
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
if (index >= mGLMaxTransformFeedbackSeparateAttribs)
return ErrorInvalidValue("getIndexedParameter: index should be less than "
"MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS");
retval.SetValue().SetAsWebGLBuffer() =
mBoundTransformFeedbackBuffers[index].get();
return;
case LOCAL_GL_UNIFORM_BUFFER_BINDING:
if (index >= mGLMaxUniformBufferBindings)
return ErrorInvalidValue("getIndexedParameter: index should be than "
"MAX_UNIFORM_BUFFER_BINDINGS");
retval.SetValue().SetAsWebGLBuffer() = mBoundUniformBuffers[index].get();
return;
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
case LOCAL_GL_UNIFORM_BUFFER_START:
case LOCAL_GL_UNIFORM_BUFFER_SIZE:
gl->fGetInteger64i_v(target, index, &data);
retval.SetValue().SetAsLongLong() = data;
return;
}
ErrorInvalidEnumInfo("getIndexedParameter: target", target);
}
示例14: MakeContextCurrent
void
WebGLContext::Clear(GLbitfield mask)
{
const char funcName[] = "clear";
if (IsContextLost())
return;
MakeContextCurrent();
uint32_t m = mask & (LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);
if (mask != m)
return ErrorInvalidValue("%s: invalid mask bits", funcName);
if (mask == 0) {
GenerateWarning("Calling gl.clear(0) has no effect.");
} else if (mRasterizerDiscardEnabled) {
GenerateWarning("Calling gl.clear() with RASTERIZER_DISCARD enabled has no effects.");
}
if (mBoundDrawFramebuffer) {
if (!mBoundDrawFramebuffer->ValidateAndInitAttachments(funcName))
return;
gl->fClear(mask);
return;
} else {
ClearBackbufferIfNeeded();
}
// Ok, we're clearing the default framebuffer/screen.
{
ScopedMaskWorkaround autoMask(*this);
gl->fClear(mask);
}
Invalidate();
mShouldPresent = true;
}
示例15: MakeContextCurrent
void
WebGLContext::DrawElements(GLenum mode, GLsizei count, GLenum type,
WebGLintptr byteOffset)
{
const char funcName[] = "drawElements";
if (IsContextLost())
return;
if (!ValidateDrawModeEnum(mode, funcName))
return;
MakeContextCurrent();
bool error;
ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
if (error)
return;
GLuint upperBound = 0;
if (!DrawElements_check(count, type, byteOffset, 1, funcName, &upperBound))
return;
RunContextLossTimer();
{
ScopedMaskWorkaround autoMask(*this);
if (gl->IsSupported(gl::GLFeature::draw_range_elements)) {
gl->fDrawRangeElements(mode, 0, upperBound, count, type,
reinterpret_cast<GLvoid*>(byteOffset));
} else {
gl->fDrawElements(mode, count, type,
reinterpret_cast<GLvoid*>(byteOffset));
}
}
Draw_cleanup(funcName);
}